thrownewMeteor.Error(403,"visit can't be found.")unlessvisit?
patient = Patients.findOne
_id: visit.patientId
thrownewMeteor.Error(403,"patient can't be found.")unlesspatient?
thrownewMeteor.Error(433,"you are not allowed to upsert answers")unlessRoles.userIsInRole(@userId,['admin'])or(Roles.userIsInRole(@userId,'therapist')andpatient.therapistIdis@userId)
check(answer.questionId,String)
question = Questions.findOne
_id: answer.questionId
thrownewMeteor.Error(403,"question can't be found.")unlessquestion?
questionnaire = Questionnaires.findOne
_id: question.questionnaireId
thrownewMeteor.Error(403,"questionnaire can't be found.")unlessquestionnaire?
#TODO check if questionnaire is scheduled at visit
answerId = null
ifanswer._id?
a = Answers.findOne_.pickanswer,'visitId','questionId','_id'
thrownewMeteor.Error(403,"answer to update can't be found.")unlessanswer?