def _create_sample_from_row(row, biobank_id_prefix):
    """Creates a new BiobankStoredSample object from a CSV row.

  Raises:
    DataError if the row is invalid.
  Returns:
    A new BiobankStoredSample, or None if the row should be skipped.
  """
    biobank_id_str = row[_Columns.EXTERNAL_PARTICIPANT_ID]
    if not biobank_id_str.startswith(biobank_id_prefix):
        # This is a biobank sample for another environment. Ignore it.
        return None
    if _Columns.BIOBANK_ORDER_IDENTIFIER not in row:
        return None
    biobank_id = from_client_biobank_id(biobank_id_str)
    sample = BiobankStoredSample(
        biobankStoredSampleId=row[_Columns.SAMPLE_ID],
        biobankId=biobank_id,
        biobankOrderIdentifier=row[_Columns.BIOBANK_ORDER_IDENTIFIER],
        test=row[_Columns.TEST_CODE])
    if row[_Columns.PARENT_ID]:
        # Skip child samples.
        return None
    sample.confirmed = _parse_timestamp(row, _Columns.CONFIRMED_DATE, sample)
    sample.created = _parse_timestamp(row, _Columns.CREATE_DATE, sample)
    return sample
 def add_sample(participant, test_code, sample_id, confirmed_time):
     sample_dao.insert(
         BiobankStoredSample(biobankStoredSampleId=sample_id,
                             biobankId=participant.biobankId,
                             biobankOrderIdentifier='KIT',
                             test=test_code,
                             confirmed=confirmed_time))
Example #3
0
    def test_dv_order_sample_update(self):
        """
    Test Biobank Direct Volunteer order
    """
        participant = self.participant_dao.insert(Participant())
        self.summary_dao.insert(self.participant_summary(participant))

        created_ts = datetime.datetime(2019, 03, 22, 18, 30, 45)
        confirmed_ts = datetime.datetime(2019, 03, 23, 12, 13, 00)

        bo = self._make_biobank_order(participantId=participant.participantId)
        BiobankOrderDao().insert(bo)

        boi = bo.identifiers[0]

        bss = BiobankStoredSample(biobankStoredSampleId=u'23523523',
                                  biobankId=participant.biobankId,
                                  test=u'1SAL2',
                                  created=created_ts,
                                  biobankOrderIdentifier=boi.value,
                                  confirmed=confirmed_ts)

        with self.participant_dao.session() as session:
            session.add(bss)

        ps = self.summary_dao.get(participant.participantId)
        self.assertIsNone(ps.sampleStatusDV1SAL2)
        self.assertIsNone(ps.sampleStatusDV1SAL2Time)

        self.summary_dao.update_from_biobank_stored_samples()
        ps = self.summary_dao.get(participant.participantId)
        self.assertEqual(ps.sampleStatus1SAL2, SampleStatus.RECEIVED)
        self.assertEqual(ps.sampleStatus1SAL2Time, confirmed_ts)
  def test_update_from_samples(self):
    # baseline_tests = ['BASELINE1', 'BASELINE2']
    baseline_tests = ["1PST8", "2PST8"]

    config.override_setting(config.BASELINE_SAMPLE_TEST_CODES, baseline_tests)
    self.dao.update_from_biobank_stored_samples()  # safe noop

    p_baseline_samples = self._insert(Participant(participantId=1, biobankId=11))
    p_mixed_samples = self._insert(Participant(participantId=2, biobankId=22))
    p_no_samples = self._insert(Participant(participantId=3, biobankId=33))
    p_unconfirmed = self._insert(Participant(participantId=4, biobankId=44))
    self.assertEquals(self.dao.get(p_baseline_samples.participantId).numBaselineSamplesArrived, 0)

    def get_p_baseline_last_modified():
      return self.dao.get(p_baseline_samples.participantId).lastModified
    p_baseline_last_modified1 = get_p_baseline_last_modified()

    sample_dao = BiobankStoredSampleDao()

    def add_sample(participant, test_code, sample_id):
      TIME = datetime.datetime(2018, 3, 2)
      sample_dao.insert(BiobankStoredSample(
          biobankStoredSampleId=sample_id, biobankId=participant.biobankId,
        biobankOrderIdentifier='KIT', test=test_code, confirmed=TIME))

    add_sample(p_baseline_samples, baseline_tests[0], '11111')
    add_sample(p_baseline_samples, baseline_tests[1], '22223')
    add_sample(p_mixed_samples, baseline_tests[0], '11112')
    add_sample(p_mixed_samples, 'NOT1', '44441')
    # add unconfirmed sample
    sample_dao.insert(BiobankStoredSample(biobankStoredSampleId=55555,
                                          biobankId=p_unconfirmed.biobankId,
                                          biobankOrderIdentifier='KIT', test=baseline_tests[1],
                                          confirmed=None))
    # sleep 1 sec to make lastModified different
    time.sleep(1)
    self.dao.update_from_biobank_stored_samples()

    p_baseline_last_modified2 = get_p_baseline_last_modified()
    self.assertNotEquals(p_baseline_last_modified2, p_baseline_last_modified1)

    self.assertEquals(self.dao.get(p_baseline_samples.participantId).numBaselineSamplesArrived, 2)
    self.assertEquals(self.dao.get(p_mixed_samples.participantId).numBaselineSamplesArrived, 1)
    self.assertEquals(self.dao.get(p_no_samples.participantId).numBaselineSamplesArrived, 0)
    self.assertEquals(self.dao.get(p_unconfirmed.participantId).numBaselineSamplesArrived, 0)

    M_baseline_samples = self._insert(Participant(participantId=9, biobankId=99))
    add_sample(M_baseline_samples, baseline_tests[0], '999')
    M_first_update = self.dao.get(M_baseline_samples.participantId)
    # sleep 1 sec to make lastModified different
    time.sleep(1)
    self.dao.update_from_biobank_stored_samples()
    add_sample(M_baseline_samples, baseline_tests[1], '9999')
    M_second_update = self.dao.get(M_baseline_samples.participantId)
    # sleep 1 sec to make lastModified different
    time.sleep(1)
    self.dao.update_from_biobank_stored_samples()

    self.assertNotEqual(M_first_update.lastModified, M_second_update.lastModified)
    self.assertEquals(get_p_baseline_last_modified(), p_baseline_last_modified2)
 def add_sample(test_code, sample_id):
     TIME = datetime.datetime(2018, 3, 2)
     sample_dao.insert(
         BiobankStoredSample(biobankStoredSampleId=sample_id,
                             biobankId=participant.biobankId,
                             biobankOrderIdentifier='KIT',
                             test=test_code,
                             confirmed=TIME))
Example #6
0
 def _insert_samples(self, participant, tests, sample_ids, confirmed_time,
                     created_time):
     for test_code, sample_id in zip(tests, sample_ids):
         self.sample_dao.insert(
             BiobankStoredSample(biobankStoredSampleId=sample_id,
                                 biobankId=participant.biobankId,
                                 test=test_code,
                                 confirmed=confirmed_time,
                                 created=created_time))
 def test_insert_and_read_sample(self):
     sample_id = 'WEB123456'
     test_code = '1U234'
     now = clock.CLOCK.now()
     created = self.dao.insert(
         BiobankStoredSample(biobankStoredSampleId=sample_id,
                             biobankId=self.participant.biobankId,
                             test=test_code,
                             confirmed=now))
     fetched = self.dao.get(sample_id)
     self.assertEquals(test_code, created.test)
     self.assertEquals(test_code, fetched.test)
Example #8
0
    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()
Example #9
0
  def _create_data(self):
    HPODao().insert(HPO(hpoId=PITT_HPO_ID + 1, name='AZ_TUCSON_2'))
    HPODao().insert(HPO(hpoId=PITT_HPO_ID + 4, name='TEST'))
    SqlTestBase.setup_codes(
        ANSWER_FIELD_TO_QUESTION_CODE.values() + [EHR_CONSENT_QUESTION_CODE],
        code_type=CodeType.QUESTION)
    SqlTestBase.setup_codes(
        FIELD_TO_QUESTIONNAIRE_MODULE_CODE.values(), code_type=CodeType.MODULE)

    # Import codes for white and female, but not male or black.
    SqlTestBase.setup_codes([
      RACE_WHITE_CODE, CONSENT_PERMISSION_YES_CODE, RACE_NONE_OF_THESE_CODE,
      PMI_PREFER_NOT_TO_ANSWER_CODE, CONSENT_PERMISSION_NO_CODE, 'female', 'PIIState_VA',
      PMI_SKIP_CODE
    ], code_type=CodeType.ANSWER)
    participant_dao = ParticipantDao()

    questionnaire_id = self.create_questionnaire('questionnaire3.json')
    questionnaire_id_2 = self.create_questionnaire('questionnaire4.json')
    questionnaire_id_3 = self.create_questionnaire('all_consents_questionnaire.json')

    pl_tucson = make_primary_provider_link_for_name('AZ_TUCSON')
    pl_test = make_primary_provider_link_for_name('TEST')
    pl_pitt = make_primary_provider_link_for_name('PITT')

    with FakeClock(TIME):
      participant = Participant(participantId=1, biobankId=2, providerLink=pl_tucson)
      participant_dao.insert(participant)
      self.send_consent('P1', email='*****@*****.**')

      # Participant 2 starts out unpaired; later gets paired automatically when their physical
      # measurements come in.
      participant2 = Participant(participantId=2, biobankId=3)
      participant_dao.insert(participant2)
      self.send_consent('P2', email='*****@*****.**')

      # Test HPO affiliation; this test participant is ignored.
      participant3 = Participant(participantId=3, biobankId=4, providerLink=pl_test)
      participant_dao.insert(participant3)
      self.send_consent('P3', email='*****@*****.**')

      # example.com e-mail; this test participant is ignored, too.
      participant4 = Participant(participantId=4, biobankId=5, providerLink=pl_pitt)
      participant_dao.insert(participant4)
      self.send_consent('P4', email='*****@*****.**')

      participant5 = Participant(participantId=5, biobankId=6, providerLink=pl_tucson)
      participant_dao.insert(participant5)
      self.send_consent('P5', email='*****@*****.**')

    with FakeClock(TIME_2):
      # FIXME: The test passes, but the following "update" doesn't actually make much sense.  The
      # providerlink is not changed but the HPO ID actually is (at this point in time
      # `participant.hpoId` evaluates to 4, which is the value given in `unit_test_util.AZ_HPO_ID`).
      # The original intent of the test is not clear.
      # This update to participant has no effect, as the HPO ID didn't change.
      participant = self._participant_with_defaults(
        participantId=1, version=1, biobankId=2,
        hpoId=3, # <<<< Had to add hpoId here, default is UNSET_HPO_ID
        providerLink=pl_tucson
      )
      participant_dao.update(participant)

      self.submit_questionnaire_response('P1', questionnaire_id,
                                         race_code=RACE_WHITE_CODE,
                                         gender_code='male',
                                         state=PMI_SKIP_CODE,
                                         date_of_birth=datetime.date(1980, 1, 2))

      self.submit_questionnaire_response('P2', questionnaire_id,
                                         race_code=RACE_NONE_OF_THESE_CODE,
                                         gender_code=None,
                                         state=None,
                                         date_of_birth=None)

      self.submit_questionnaire_response('P5', questionnaire_id,
                                         race_code=PMI_SKIP_CODE,
                                         gender_code=PMI_SKIP_CODE,
                                         state=None,
                                         date_of_birth=None)

    with FakeClock(TIME_3):
      # Re-pair the original participant
      participant.version = 2
      participant.providerLink = pl_pitt
      participant_dao.update(participant)
      self.send_post('Participant/P2/PhysicalMeasurements', load_measurement_json(2))
      self.send_post('Participant/P2/BiobankOrder', load_biobank_order_json(2))

      self.submit_questionnaire_response('P1', questionnaire_id,
                                         race_code='black',
                                         gender_code='female',
                                         state=None,
                                         date_of_birth=datetime.date(1980, 1, 3))

      self.submit_questionnaire_response('P2', questionnaire_id,
                                         race_code=None,
                                         gender_code=PMI_PREFER_NOT_TO_ANSWER_CODE,
                                         state=None,
                                         date_of_birth=None)

      self.submit_questionnaire_response('P2', questionnaire_id_2,
                                         race_code=None,
                                         gender_code=None,
                                         state='PIIState_VA',
                                         date_of_birth=None)

      self.submit_consent_questionnaire_response('P1', questionnaire_id_3,
                                                  CONSENT_PERMISSION_NO_CODE)

      self.submit_consent_questionnaire_response('P2', questionnaire_id_3,
                                                  CONSENT_PERMISSION_YES_CODE)

      sample_dao = BiobankStoredSampleDao()
      sample_dao.insert(
          BiobankStoredSample(
              biobankStoredSampleId='abc',
              biobankId=2,
              biobankOrderIdentifier='KIT',
              test='test',
              confirmed=TIME_2))
      sample_dao.insert(
          BiobankStoredSample(
              biobankStoredSampleId='def',
              biobankId=3,
              biobankOrderIdentifier='KIT',
              test='1SAL',
              confirmed=TIME_2))
      sample_dao.insert(
          BiobankStoredSample(
              biobankStoredSampleId='xyz',
              biobankId=4,
              biobankOrderIdentifier='KIT',
              test='1SAL',
              confirmed=TIME_2))
Example #10
0
  def _create_data(self):
    HPODao().insert(HPO(hpoId=PITT_HPO_ID + 1, name='AZ_TUCSON'))
    HPODao().insert(HPO(hpoId=PITT_HPO_ID + 2, name='TEST'))
    SqlTestBase.setup_codes(
        ANSWER_FIELD_TO_QUESTION_CODE.values() + [EHR_CONSENT_QUESTION_CODE],
        code_type=CodeType.QUESTION)
    SqlTestBase.setup_codes(
        FIELD_TO_QUESTIONNAIRE_MODULE_CODE.values(), code_type=CodeType.MODULE)
    # Import codes for white and female, but not male or black.
    SqlTestBase.setup_codes(
        [
            RACE_WHITE_CODE, CONSENT_PERMISSION_YES_CODE,
            CONSENT_PERMISSION_NO_CODE, 'female', 'PIIState_VA'
        ],
        code_type=CodeType.ANSWER)
    participant_dao = ParticipantDao()

    questionnaire_id = self.create_questionnaire('questionnaire3.json')
    questionnaire_id_2 = self.create_questionnaire('questionnaire4.json')
    questionnaire_id_3 = self.create_questionnaire(
        'all_consents_questionnaire.json')
    with FakeClock(TIME):
      participant = Participant(
          participantId=1,
          biobankId=2,
          providerLink=make_primary_provider_link_for_name('AZ_TUCSON'))
      participant_dao.insert(participant)
      self.send_consent('P1', email='*****@*****.**')

    with FakeClock(TIME):
      # Participant 2 starts out unpaired; later gets paired automatically when their physical
      # measurements come in.
      participant2 = Participant(
          participantId=2,
          biobankId=3)
      participant_dao.insert(participant2)
      self.send_consent('P2', email='*****@*****.**')

    with FakeClock(TIME):
      # Test HPO affiliation; this test participant is ignored.
      participant3 = Participant(participantId=3, biobankId=4,
                                 providerLink=make_primary_provider_link_for_name('TEST'))
      participant_dao.insert(participant3)
      self.send_consent('P3', email='*****@*****.**')

      # example.com e-mail; this test participant is ignored, too.
      participant4 = Participant(participantId=4, biobankId=5,
                                 providerLink=make_primary_provider_link_for_name('PITT'))
      participant_dao.insert(participant4)
      self.send_consent('P4', email='*****@*****.**')

    with FakeClock(TIME_2):
      # This update to participant has no effect, as the HPO ID didn't change.
      participant = self._participant_with_defaults(
          participantId=1, version=1, biobankId=2,
          providerLink=make_primary_provider_link_for_name('AZ_TUCSON'))
      participant_dao.update(participant)
      self.submit_questionnaire_response('P1', questionnaire_id,
                                         RACE_WHITE_CODE, 'male', None,
                                         datetime.date(1980, 1, 2))
      self.submit_questionnaire_response('P2', questionnaire_id, None, None,
                                         None, None)

    with FakeClock(TIME_3):
      participant = self._participant_with_defaults(
          participantId=1,
          version=2,
          biobankId=2,
          providerLink=make_primary_provider_link_for_name('PITT'))
      participant_dao.update(participant)
      self.send_post('Participant/P2/PhysicalMeasurements',
                     load_measurement_json(2))
      self.send_post('Participant/P2/BiobankOrder', load_biobank_order_json(2))
      self.submit_questionnaire_response('P1', questionnaire_id, 'black',
                                         'female', None,
                                         datetime.date(1980, 1, 3))
      self.submit_questionnaire_response('P2', questionnaire_id_2, None, None,
                                         'PIIState_VA', None)
      self._submit_consent_questionnaire_response('P1', questionnaire_id_3,
                                                  CONSENT_PERMISSION_NO_CODE)
      self._submit_consent_questionnaire_response('P2', questionnaire_id_3,
                                                  CONSENT_PERMISSION_YES_CODE)
      sample_dao = BiobankStoredSampleDao()
      sample_dao.insert(
          BiobankStoredSample(
              biobankStoredSampleId='abc',
              biobankId=2,
              test='test',
              confirmed=TIME_2))
      sample_dao.insert(
          BiobankStoredSample(
              biobankStoredSampleId='def',
              biobankId=3,
              test='1SAL',
              confirmed=TIME_2))
Example #11
0
  def _create_data(self):
    HPODao().insert(HPO(hpoId=AZ_HPO_ID + 1, name='AZ_TUCSON_2'))
    HPODao().insert(HPO(hpoId=PITT_HPO_ID + 4, name='TEST'))
    SqlTestBase.setup_codes(
        ANSWER_FIELD_TO_QUESTION_CODE.values() + [EHR_CONSENT_QUESTION_CODE],
        code_type=CodeType.QUESTION)
    SqlTestBase.setup_codes(
        FIELD_TO_QUESTIONNAIRE_MODULE_CODE.values(), code_type=CodeType.MODULE)
    # Import codes for white and female, but not male or black.
    SqlTestBase.setup_codes(
        [
            RACE_WHITE_CODE, CONSENT_PERMISSION_YES_CODE,
            RACE_NONE_OF_THESE_CODE, PMI_PREFER_NOT_TO_ANSWER_CODE,
            CONSENT_PERMISSION_NO_CODE, 'female', 'PIIState_VA'
        ],
        code_type=CodeType.ANSWER)
    participant_dao = ParticipantDao()

    questionnaire_id = self.create_questionnaire('questionnaire3.json')
    questionnaire_id_2 = self.create_questionnaire('questionnaire4.json')
    questionnaire_id_3 = self.create_questionnaire(
        'all_consents_questionnaire.json')

    with FakeClock(TIME):
      participant = self._participant_with_defaults(
          participantId=1,
          version=2,
          biobankId=2,
          providerLink=make_primary_provider_link_for_name('PITT'))
      participant_dao.insert(participant)
      self.send_consent('P1', email='*****@*****.**')

      # Participant 2 starts out unpaired; later gets paired automatically when their physical
      # measurements come in.
      participant2 = Participant(participantId=2, biobankId=3)
      participant_dao.insert(participant2)
      self.send_consent('P2', email='*****@*****.**')

      # Test HPO affiliation; this test participant is ignored.
      participant3 = Participant(
          participantId=3,
          biobankId=4,
          providerLink=make_primary_provider_link_for_name('TEST'))
      participant_dao.insert(participant3)
      self.send_consent('P3', email='*****@*****.**')

      # example.com e-mail; this test participant is ignored, too.
      participant4 = Participant(
          participantId=4,
          biobankId=5,
          providerLink=make_primary_provider_link_for_name('PITT'))
      participant_dao.insert(participant4)
      self.send_consent('P4', email='*****@*****.**')

      participant5 = Participant(
          participantId=5,
          biobankId=6,
          providerLink=make_primary_provider_link_for_name('PITT'))
      participant_dao.insert(participant5)
      self.send_consent('P5', email='*****@*****.**')

      # A withdrawn participant should be excluded from metrics.
      participant6 = Participant(
          participantId=6,
          biobankId=7,
          providerLink=make_primary_provider_link_for_name('PITT')
      )
      participant_dao.insert(participant6)
      self.send_consent('P6', email='*****@*****.**')
      participant6.withdrawalStatus=WithdrawalStatus.NO_USE
      participant_dao.update(participant6)

      self.send_post('Participant/P2/PhysicalMeasurements',
                     load_measurement_json(2))
      self.send_post('Participant/P2/BiobankOrder', load_biobank_order_json(2))
      self.submit_questionnaire_response('P1', questionnaire_id,
                                         RACE_WHITE_CODE, 'female', None,
                                         datetime.date(1980, 1, 2))
      self.submit_questionnaire_response(
          'P2', questionnaire_id, PMI_PREFER_NOT_TO_ANSWER_CODE, 'male', None,
          datetime.date(1920, 1, 3))
      self.submit_questionnaire_response('P2', questionnaire_id_2, None, None,
                                         'PIIState_VA', None)
      self.submit_questionnaire_response('P5', questionnaire_id, None, None,
                                         None, datetime.date(1970, 1, 2))
      self.submit_consent_questionnaire_response('P1', questionnaire_id_3,
                                                 CONSENT_PERMISSION_NO_CODE)
      self.submit_consent_questionnaire_response('P2', questionnaire_id_3,
                                                 CONSENT_PERMISSION_YES_CODE)
      sample_dao = BiobankStoredSampleDao()
      sample_dao.insert(
          BiobankStoredSample(
              biobankStoredSampleId='abc',
              biobankId=2,
              biobankOrderIdentifier='KIT',
              test='test',
              confirmed=TIME))
      sample_dao.insert(
          BiobankStoredSample(
              biobankStoredSampleId='def',
              biobankId=3,
              biobankOrderIdentifier='KIT',
              test='1SAL',
              confirmed=TIME))
      # Required to update the HPO linkage (and test filtering for P3).
      sample_dao.insert(
          BiobankStoredSample(
              biobankStoredSampleId='xyz',
              biobankId=4,
              biobankOrderIdentifier='KIT',
              test='1SAL',
              confirmed=TIME))
Example #12
0
 def add_sample(participant, test_code, sample_id):
     sample_dao.insert(
         BiobankStoredSample(biobankStoredSampleId=sample_id,
                             biobankId=participant.biobankId,
                             test=test_code))
Example #13
0
 def _store_biobank_sample(self, participant, test_code):
   BiobankStoredSampleDao().insert(BiobankStoredSample(
       biobankStoredSampleId='s' + participant['participantId'] + test_code,
       biobankId=participant['biobankId'][1:],
       test=test_code,
       confirmed=TIME_1))