Exemplo n.º 1
0
    def _make_biobank_order(self, **kwargs):
        """Makes a new BiobankOrder (same values every time) with valid/complete defaults.

    Kwargs pass through to BiobankOrder constructor, overriding defaults.
    """
        for k, default_value in (('biobankOrderId', '1'), ('created',
                                                           clock.CLOCK.now()),
                                 ('participantId',
                                  self.participant.participantId),
                                 ('sourceSiteId', 1), ('sourceUsername',
                                                       '*****@*****.**'),
                                 ('collectedSiteId', 1), ('collectedUsername',
                                                          '*****@*****.**'),
                                 ('processedSiteId', 1), ('processedUsername',
                                                          '*****@*****.**'),
                                 ('finalizedSiteId',
                                  2), ('finalizedUsername',
                                       '*****@*****.**'), ('identifiers', [
                                           BiobankOrderIdentifier(system='a',
                                                                  value='c')
                                       ]), ('samples', [
                                           BiobankOrderedSample(
                                               biobankOrderId='1',
                                               test=BIOBANK_TESTS[0],
                                               description=u'description',
                                               finalized=self.TIME_1,
                                               processingRequired=True)
                                       ])):
            if k not in kwargs:
                kwargs[k] = default_value
        return BiobankOrder(**kwargs)
Exemplo n.º 2
0
    def _make_biobank_order(self, **kwargs):
        """Makes a new BiobankOrder (same values every time) with valid/complete defaults.

    Kwargs pass through to BiobankOrder constructor, overriding defaults.
    """
        participantId = kwargs['participantId']
        modified = datetime.datetime(2019, 03, 25, 15, 59, 30)

        for k, default_value in (
            ('biobankOrderId', u'1'),
            ('created', clock.CLOCK.now()),
                # ('participantId', self.participant.participantId),
            ('sourceSiteId', 1),
            ('sourceUsername', u'*****@*****.**'),
            ('collectedSiteId', 1),
            ('collectedUsername', u'*****@*****.**'),
            ('processedSiteId', 1),
            ('processedUsername', u'*****@*****.**'),
            ('finalizedSiteId', 2),
            ('finalizedUsername', u'*****@*****.**'),
            ('version', 1),
            ('identifiers', [BiobankOrderIdentifier(system=u'a', value=u'c')]),
            ('samples', [
                BiobankOrderedSample(test=u'1SAL2',
                                     description=u'description',
                                     processingRequired=True)
            ]),
            ('dvOrders', [
                BiobankDVOrder(participantId=participantId,
                               modified=modified,
                               version=1)
            ])):
            if k not in kwargs:
                kwargs[k] = default_value
        return BiobankOrder(**kwargs)
    def insert_biobank_order(self, pid, resource):
        obj = BiobankOrder()
        obj.participantId = long(pid)
        obj.created = clock.CLOCK.now()
        obj.created = datetime.datetime.now()
        obj.orderStatus = BiobankOrderStatus.UNSET
        obj.biobankOrderId = resource['biobankOrderId']
        test = self.get(resource['id'])
        obj.dvOrders = [test]

        bod = BiobankOrderDao()
        obj.samples = [
            BiobankOrderedSample(test='1SAL2',
                                 processingRequired=False,
                                 description=u'salivary pilot kit')
        ]
        self._add_identifiers_and_main_id(obj, ObjectView(resource))
        bod.insert(obj)
Exemplo n.º 4
0
 def _insert_order(self,
                   participant,
                   order_id,
                   tests,
                   order_time,
                   finalized_tests=None,
                   kit_id=None,
                   tracking_number=None,
                   collected_note=None,
                   processed_note=None,
                   finalized_note=None):
     order = BiobankOrder(biobankOrderId=order_id,
                          participantId=participant.participantId,
                          sourceSiteId=1,
                          finalizedSiteId=2,
                          collectedSiteId=1,
                          finalizedUsername='******',
                          created=order_time,
                          collectedNote=collected_note,
                          processedNote=processed_note,
                          finalizedNote=finalized_note,
                          samples=[])
     id_1 = BiobankOrderIdentifier(
         system="https://orders.mayomedicallaboratories.com",
         value=order_id)
     id_2 = BiobankOrderIdentifier(system="https://www.pmi-ops.org",
                                   value='O%s' % order_id)
     order.identifiers.append(id_1)
     order.identifiers.append(id_2)
     if kit_id:
         order.identifiers.append(
             BiobankOrderIdentifier(system=_KIT_ID_SYSTEM, value=kit_id))
     if tracking_number:
         order.identifiers.append(
             BiobankOrderIdentifier(system=_TRACKING_NUMBER_SYSTEM,
                                    value=tracking_number))
     for test_code in tests:
         finalized_time = order_time
         if finalized_tests and not test_code in finalized_tests:
             finalized_time = None
         order.samples.append(
             BiobankOrderedSample(biobankOrderId=order.biobankOrderId,
                                  test=test_code,
                                  description=u'test',
                                  processingRequired=False,
                                  collected=order_time,
                                  processed=order_time,
                                  finalized=finalized_time))
     return self.order_dao.insert(order)
Exemplo n.º 5
0
    def test_schema_biobank_order_and_datetime_roundtrip(self):
        bo_id = 1
        now = isodate.parse_datetime('2016-01-04T10:28:50-04:00')

        write_session = self.database.make_session()

        p = self._create_participant(write_session)
        site = Site(siteId=1,
                    siteName='site',
                    googleGroup='*****@*****.**',
                    mayolinkClientNumber=12345,
                    hpoId=1)
        write_session.add(site)
        write_session.commit()

        bo = BiobankOrder(biobankOrderId=bo_id,
                          participantId=p.participantId,
                          created=now,
                          sourceSiteId=1,
                          version=1,
                          sourceUsername='******',
                          collectedSiteId=1,
                          collectedUsername='******',
                          processedSiteId=1,
                          processedUsername='******',
                          finalizedSiteId=1,
                          finalizedUsername='******',
                          collectedNote=r'written by ' + self.fake.last_name(),
                          processedNote=u'd',
                          finalizedNote=u'e',
                          logPosition=LogPosition())
        bo.identifiers.append(BiobankOrderIdentifier(system='a', value='b'))
        bo.samples.append(
            BiobankOrderedSample(test='a',
                                 description=u'a test invented by ' +
                                 self.fake.first_name(),
                                 processingRequired=True,
                                 collected=now,
                                 processed=now,
                                 finalized=now))
        write_session.add(bo)
        write_session.commit()

        read_session = self.database.make_session()
        bo = read_session.query(BiobankOrder).get(bo_id)
        self.assertEquals(
            bo.created.isoformat(),
            now.astimezone(tzutc()).replace(tzinfo=None).isoformat())
    def from_client_json(self,
                         resource_json,
                         participant_id=None,
                         client_id=None):
        resource = _FhirBiobankOrder(resource_json)
        if not resource.created.date:  # FHIR warns but does not error on bad date values.
            raise BadRequest('Invalid created date %r.' %
                             resource.created.origval)

        order = BiobankOrder(
            participantId=participant_id,
            created=resource.created.date.replace(tzinfo=None))

        if not resource.created_info:
            raise BadRequest(
                'Created Info is required, but was missing in request.')
        order.sourceUsername, order.sourceSiteId = self._parse_handling_info(
            resource.created_info)
        order.collectedUsername, order.collectedSiteId = self._parse_handling_info(
            resource.collected_info)
        if order.collectedSiteId is None:
            raise BadRequest('Collected site is required in request.')
        order.processedUsername, order.processedSiteId = self._parse_handling_info(
            resource.processed_info)
        order.finalizedUsername, order.finalizedSiteId = self._parse_handling_info(
            resource.finalized_info)

        if resource.notes:
            order.collectedNote = resource.notes.collected
            order.processedNote = resource.notes.processed
            order.finalizedNote = resource.notes.finalized
        if resource.subject != self._participant_id_to_subject(participant_id):
            raise BadRequest(
                'Participant ID %d from path and %r in request do not match, should be %r.'
                % (participant_id, resource.subject,
                   self._participant_id_to_subject(participant_id)))
        self._add_identifiers_and_main_id(order, resource)
        self._add_samples(order, resource)
        return order