if question.type is 'table' or question.type is 'table_polar'
answered = answer? and answer.value.length is question.subquestions.length
#question.answered = answered
if !answered
quest.answered = false
if question.subquestions?
if answer?
quest.numAnswered += answer.value.length
if !question.optional
quest.numAnsweredRequired += answer.value.length
else if answered
quest.numAnswered += 1
if !question.optional
quest.numAnsweredRequired++
question
#quest.questions = questions
quest.numQuestions = numQuestions
quest.numQuestionsRequired = numQuestionsRequired
quest.answered = true if quest.numAnsweredRequired >= quest.numQuestionsRequired
quest
quests
@Visits = new Meteor.Collection("visits",
transform: (doc) ->
new Visit(doc)
)
Visits.before.insert BeforeInsertTimestampHook
Visits.before.update BeforeUpdateTimestampHook
schema =
'patientId':
type: String
'designVisitId':
type: String
'title':
type: String
'questionnaireIds':
type: [String]
defaultValue: []
'recordPhysicalData':
type: Boolean
defaultValue: false
'index':
type: Number
'daysOffsetFromPrevious':
type: Number
optional: true
'daysOffsetFromBaseline':
type: Number
optional: true
'date':
type: Number
optional: true
'updatedAt':
type: Number
optional: true
'createdAt':
type: Number
optional: true
Visits.attachSchema new SimpleSchema(schema)
Meteor.methods
"initVisit": (designVisitId, patientId) ->
check designVisitId, String
check patientId, String
patient = Patients.findOne patientId
throw new Meteor.Error(403, "patient can't be found.") unless patient?
throw new Meteor.Error(433, "you are not allowed to upsert answers") unless Roles.userIsInRole(@userId, ['admin']) or (Roles.userIsInRole(@userId, 'caseManager') and @userId in patient.caseManagerIds)
# use query from Patient
studyDesign = StudyDesigns.findOne
_id: $in: patient.studyDesignIds
'visits._id': designVisitId
throw new Meteor.Error(403, "studyDesign can't be found.") unless studyDesign?
daysOffsetFromPrevious: visitTemplate.daysOffsetFromPrevious if visitTemplate.daysOffsetFromPrevious?
daysOffsetFromBaseline: visitTemplate.daysOffsetFromBaseline if visitTemplate.daysOffsetFromBaseline?
_id = Visits.insert visit
_id
"changeVisitDate": (visitId, date) ->
check visitId, String
if date? #we allow null values
check date, Number
check isNaN(date), false
visit = Visits.findOne visitId
throw new Meteor.Error(403, "visit can't be found.") unless visit?
patient = Patients.findOne visit.patientId
throw new Meteor.Error(403, "patient can't be found.") unless patient?
throw new Meteor.Error(433, "you are not allowed change this visit") unless Roles.userIsInRole(@userId, ['admin']) or (Roles.userIsInRole(@userId, 'caseManager') and @userId in patient.caseManagerIds)