def setUp(self): super(QuestionnaireDaoTest, self).setUp(with_data=False) self.dao = QuestionnaireDao() self.questionnaire_history_dao = QuestionnaireHistoryDao() self.questionnaire_concept_dao = QuestionnaireConceptDao() self.questionnaire_question_dao = QuestionnaireQuestionDao() self.code_dao = CodeDao() self.CODE_1 = Code(codeId=1, system='a', value='b', display=u'c', topic=u'd', codeType=CodeType.MODULE, mapped=True) self.CODE_2 = Code(codeId=2, system='a', value='x', display=u'y', codeType=CodeType.MODULE, mapped=False) self.CODE_3 = Code(codeId=3, system='a', value='z', display=u'y', codeType=CodeType.MODULE, mapped=False) self.CODE_4 = Code(codeId=4, system='a', value='c', codeType=CodeType.QUESTION, mapped=True, parentId=1) self.CODE_5 = Code(codeId=5, system='a', value='d', codeType=CodeType.QUESTION, mapped=True, parentId=2) self.CODE_6 = Code(codeId=6, system='a', value='e', codeType=CodeType.QUESTION, mapped=True, parentId=2) self.CONCEPT_1 = QuestionnaireConcept(codeId=1) self.CONCEPT_2 = QuestionnaireConcept(codeId=2) self.QUESTION_1 = QuestionnaireQuestion(linkId='a', codeId=4, repeats=False) self.QUESTION_2 = QuestionnaireQuestion(linkId='d', codeId=5, repeats=True) self.insert_codes()
def insert_codes(self): self.code_dao.insert(self.CODE_1) self.code_dao.insert(self.CODE_2) self.code_dao.insert(self.CODE_3) self.code_dao.insert(self.CODE_4) self.code_dao.insert(self.CODE_5) self.code_dao.insert(self.CODE_6) self.code_dao.insert(self.MODULE_CODE_7) self.code_dao.insert(self.skip_code) self.consent_code_id = self.code_dao.insert(consent_code()).codeId self.first_name_code_id = self.code_dao.insert( first_name_code()).codeId self.last_name_code_id = self.code_dao.insert(last_name_code()).codeId self.email_code_id = self.code_dao.insert(email_code()).codeId self.login_phone_number_code_id = self.code_dao.insert( login_phone_number_code()).codeId self.FN_QUESTION = QuestionnaireQuestion( linkId='fn', codeId=self.first_name_code_id, repeats=False) self.LN_QUESTION = QuestionnaireQuestion(linkId='ln', codeId=self.last_name_code_id, repeats=False) self.EMAIL_QUESTION = QuestionnaireQuestion(linkId='email', codeId=self.email_code_id, repeats=False) self.LOGIN_PHONE_NUMBER_QUESTION = QuestionnaireQuestion( linkId='lpn', codeId=self.login_phone_number_code_id, repeats=False) self.first_name = self.fake.first_name() self.last_name = self.fake.last_name() self.email = self.fake.email() self.login_phone_number = self.fake.phone_number() self.FN_ANSWER = QuestionnaireResponseAnswer( questionnaireResponseAnswerId=3, questionnaireResponseId=1, questionId=3, valueString=self.first_name) self.LN_ANSWER = QuestionnaireResponseAnswer( questionnaireResponseAnswerId=4, questionnaireResponseId=1, questionId=4, valueString=self.last_name) self.EMAIL_ANSWER = QuestionnaireResponseAnswer( questionnaireResponseAnswerId=5, questionnaireResponseId=1, questionId=5, valueString=self.email) self.LOGIN_PHONE_NUMBER_ANSWER = QuestionnaireResponseAnswer( questionnaireResponseAnswerId=6, questionnaireResponseId=1, questionId=6, valueString=self.login_phone_number)
def _add_questions(cls, q, code_id_map, questions): for system, code, linkId, repeats in questions: q.questions.append( QuestionnaireQuestion(questionnaireId=q.questionnaireId, questionnaireVersion=q.version, linkId=linkId, codeId=code_id_map.get((system, code)), repeats=repeats if repeats else False))
def _make_history(self, questionnaire, concepts, questions): history = QuestionnaireHistory() history.fromdict(questionnaire.asdict(), allow_pk=True) for concept in concepts: new_concept = QuestionnaireConcept() new_concept.fromdict(concept.asdict()) new_concept.questionnaireId = questionnaire.questionnaireId new_concept.questionnaireVersion = questionnaire.version history.concepts.append(new_concept) for question in questions: new_question = QuestionnaireQuestion() new_question.fromdict(question.asdict()) new_question.questionnaireId = questionnaire.questionnaireId new_question.questionnaireVersion = questionnaire.version history.questions.append(new_question) return history
from unit_test_util import SqlTestBase, sort_lists from clock import FakeClock from werkzeug.exceptions import NotFound, PreconditionFailed from sqlalchemy.exc import IntegrityError EXPECTED_CONCEPT_1 = QuestionnaireConcept(questionnaireConceptId=1, questionnaireId=1, questionnaireVersion=1, codeId=1) EXPECTED_CONCEPT_2 = QuestionnaireConcept(questionnaireConceptId=2, questionnaireId=1, questionnaireVersion=1, codeId=2) EXPECTED_QUESTION_1 = QuestionnaireQuestion(questionnaireQuestionId=1, questionnaireId=1, questionnaireVersion=1, linkId='a', codeId=4, repeats=False) EXPECTED_QUESTION_2 = QuestionnaireQuestion(questionnaireQuestionId=2, questionnaireId=1, questionnaireVersion=1, linkId='d', codeId=5, repeats=True) TIME = datetime.datetime(2016, 1, 1) TIME_2 = datetime.datetime(2016, 1, 2) RESOURCE_1 = '{"x": "y"}' RESOURCE_1_WITH_ID = '{"x": "y", "version": "1", "id": "1"}' RESOURCE_2 = '{"x": "z", "version": "2"}' RESOURCE_2_WITH_ID = '{"x": "z", "version": "2", "id": "1"}'
def test_schema(self): session = self.database.make_session() hpo = HPO(hpoId=1, name='UNSET', displayName='No organization set', organizationType=OrganizationType.UNSET) code_book = CodeBook(codeBookId=1, created=datetime.datetime.now(), latest=True, name="pmi", system="http://foo/bar", version="v0.1.1") session.add(hpo) session.add(code_book) session.commit() organization = Organization(organizationId=1, externalId='org', displayName='Organization', hpoId=1) session.add(organization) session.commit() site = Site(siteId=1, siteName='site', googleGroup='*****@*****.**', mayolinkClientNumber=12345, organizationId=1) code1 = Code(codeId=1, codeBookId=1, system="a", value="b", shortValue="q", display=u"c", topic=u"d", codeType=CodeType.MODULE, mapped=True, created=datetime.datetime.now()) codeHistory1 = CodeHistory(codeId=1, codeBookId=1, system="a", value="b", shortValue="q", display=u"c", topic=u"d", codeType=CodeType.MODULE, mapped=True, created=datetime.datetime.now()) session.add(site) session.add(code1) session.add(codeHistory1) session.commit() code2 = Code(codeId=2, codeBookId=1, parentId=1, system="a", value="c", display=u"X", topic=u"d", codeType=CodeType.QUESTION, mapped=True, created=datetime.datetime.now()) codeHistory2 = CodeHistory(codeId=2, codeBookId=1, parentId=1, system="a", value="c", display=u"X", topic=u"d", codeType=CodeType.QUESTION, mapped=True, created=datetime.datetime.now()) session.add(code2) session.add(codeHistory2) session.commit() code3 = Code(codeId=3, codeBookId=1, parentId=2, system="a", value="d", display=u"Y", topic=u"d", codeType=CodeType.ANSWER, mapped=False, created=datetime.datetime.now()) codeHistory3 = CodeHistory(codeId=3, codeBookId=1, parentId=2, system="a", value="d", display=u"Y", topic=u"d", codeType=CodeType.ANSWER, mapped=False, created=datetime.datetime.now()) session.add(code3) session.add(codeHistory3) session.commit() session.commit() p = self._participant_with_defaults( participantId=1, version=1, biobankId=2, clientId='*****@*****.**', hpoId=hpo.hpoId, signUpTime=datetime.datetime.now(), lastModified=datetime.datetime.now()) ps = self._participant_summary_with_defaults( participantId=1, biobankId=2, lastModified=datetime.datetime.now(), hpoId=hpo.hpoId, firstName=self.fake.first_name(), middleName=self.fake.first_name(), lastName=self.fake.last_name(), email=self.fake.email(), zipCode='78751', dateOfBirth=datetime.date.today(), genderIdentityId=1, consentForStudyEnrollment=QuestionnaireStatus.SUBMITTED, consentForStudyEnrollmentTime=datetime.datetime.now(), numBaselineSamplesArrived=2) p.participantSummary = ps session.add(p) ph = self._participant_history_with_defaults( participantId=1, biobankId=2, clientId='*****@*****.**', hpoId=hpo.hpoId, signUpTime=datetime.datetime.now(), lastModified=datetime.datetime.now()) session.add(ph) session.commit() session.add( BiobankStoredSample(biobankStoredSampleId='WEB1234542', biobankId=p.biobankId, biobankOrderIdentifier='KIT', test='1UR10', confirmed=datetime.datetime.utcnow())) session.add( BiobankStoredSample( biobankStoredSampleId='WEB99999', # Sample ID must be unique. biobankId=p. biobankId, # Participant ID and test may be duplicated. biobankOrderIdentifier='KIT', test='1UR10', confirmed=datetime.datetime.utcnow())) pm = PhysicalMeasurements(physicalMeasurementsId=1, participantId=1, created=datetime.datetime.now(), resource='blah', final=False, logPosition=LogPosition()) pm2 = PhysicalMeasurements(physicalMeasurementsId=2, participantId=1, created=datetime.datetime.now(), resource='blah', final=True, amendedMeasurementsId=1, logPosition=LogPosition()) session.add(pm) session.add(pm2) session.commit() q1 = Measurement(measurementId=3, physicalMeasurementsId=pm.physicalMeasurementsId, codeSystem='codeSystem', codeValue='codeValue', measurementTime=datetime.datetime.now(), valueCodeSystem='valueCodeSystem', valueCodeValue='value3') session.add(q1) session.commit() m1 = Measurement(measurementId=1, physicalMeasurementsId=pm.physicalMeasurementsId, codeSystem='codeSystem', codeValue='codeValue', measurementTime=datetime.datetime.now(), bodySiteCodeSystem='bodySiteCodeSystem', bodySiteCodeValue='bodySiteCodeValue', valueString='a', valueDecimal=1.2, valueUnit='cm', valueCodeSystem='valueCodeSystem', valueCodeValue='value', valueDateTime=datetime.datetime.now(), qualifierId=q1.measurementId) session.add(m1) session.commit() m2 = Measurement(measurementId=2, physicalMeasurementsId=pm.physicalMeasurementsId, codeSystem='codeSystem', codeValue='codeValue', measurementTime=datetime.datetime.now(), valueCodeSystem='valueCodeSystem', valueCodeValue='value2', parentId=m1.measurementId, qualifierId=q1.measurementId) session.add(m2) session.commit() q = Questionnaire(questionnaireId=1, version=1, created=datetime.datetime.now(), lastModified=datetime.datetime.now(), resource='what?') qh = QuestionnaireHistory(questionnaireId=1, version=1, created=datetime.datetime.now(), lastModified=datetime.datetime.now(), resource='what?') qh.questions.append( QuestionnaireQuestion(questionnaireQuestionId=1, questionnaireId=1, questionnaireVersion=1, linkId="1.2.3", codeId=2, repeats=True)) qh.concepts.append( QuestionnaireConcept(questionnaireConceptId=1, questionnaireId=1, questionnaireVersion=1, codeId=1)) session.add(q) session.add(qh) session.commit() qr = QuestionnaireResponse(questionnaireResponseId=1, questionnaireId=1, questionnaireVersion=1, participantId=1, created=datetime.datetime.now(), resource='blah') qr.answers.append( QuestionnaireResponseAnswer(questionnaireResponseAnswerId=1, questionnaireResponseId=1, questionId=1, endTime=datetime.datetime.now(), valueSystem='a', valueCodeId=3, valueDecimal=123, valueString=self.fake.first_name(), valueDate=datetime.date.today())) session.add(qr) session.commit() mv = MetricsVersion(metricsVersionId=1, inProgress=False, complete=True, date=datetime.datetime.utcnow(), dataVersion=1) session.add(mv) session.commit() mb = MetricsBucket(metricsVersionId=1, date=datetime.date.today(), hpoId='PITT', metrics='blah') session.add(mb) session.commit()
def setUp(self): super(QuestionnaireResponseDaoTest, self).setUp() self.code_dao = CodeDao() self.participant_dao = ParticipantDao() self.questionnaire_dao = QuestionnaireDao() self.questionnaire_response_dao = QuestionnaireResponseDao() self.questionnaire_response_answer_dao = QuestionnaireResponseAnswerDao( ) self.participant_summary_dao = ParticipantSummaryDao() self.CODE_1 = Code(codeId=1, system=PPI_SYSTEM, value=GENDER_IDENTITY_QUESTION_CODE, display=u'c', topic=u'd', codeType=CodeType.QUESTION, mapped=True) self.CODE_2 = Code(codeId=2, system='a', value='x', display=u'y', codeType=CodeType.QUESTION, mapped=False) self.CODE_3 = Code(codeId=3, system='a', value='c', codeType=CodeType.ANSWER, mapped=True, parentId=1) self.CODE_4 = Code(codeId=4, system='a', value='d', codeType=CodeType.ANSWER, mapped=True, parentId=2) self.CODE_5 = Code(codeId=5, system='a', value='e', codeType=CodeType.ANSWER, mapped=False, parentId=1) self.CODE_6 = Code(codeId=6, system='a', value='f', codeType=CodeType.ANSWER, mapped=True, parentId=1) self.MODULE_CODE_7 = Code(codeId=7, system=PPI_SYSTEM, value=THE_BASICS_PPI_MODULE, codeType=CodeType.MODULE, mapped=True) self.CONCEPT_1 = QuestionnaireConcept(codeId=7) self.CODE_1_QUESTION_1 = QuestionnaireQuestion(linkId='a', codeId=1, repeats=False) self.CODE_2_QUESTION = QuestionnaireQuestion(linkId='d', codeId=2, repeats=True) # Same code as question 1 self.CODE_1_QUESTION_2 = QuestionnaireQuestion(linkId='x', codeId=1, repeats=False) self.skip_code = Code(codeId=8, system=PPI_SYSTEM, value=PMI_SKIP_CODE, mapped=True, codeType=CodeType.ANSWER) config.override_setting(config.CONSENT_PDF_BUCKET, [_FAKE_BUCKET])