def from_client_json(self, resource_json, id_=None, expected_version=None, 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) # order.finalizedTime uses the time from biobank_ordered_sample.finalized try: order.finalizedTime = self.get_random_sample_finalized_time( resource).date.replace(tzinfo=None) except AttributeError: order.finalizedTime = None 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) if resource.amendedReason: order.amendedReason = resource.amendedReason if resource.amendedInfo: order.amendedUsername, order.amendedSiteId = self._parse_handling_info( resource.amendedInfo) order.version = expected_version return order
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) 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) 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