def lookup_patient(federated_principal_alias): """ Queries a patient by FPA. Args: federated_principal_alias: ID of a person in Cerner's Identity Federation. Returns: {"name": "<patient's name>", "id": <FHIR server's patient ID>} """ identifier = f'{CERNER_FPA_URN}|{federated_principal_alias}' search = Patient.where(struct={'identifier': identifier}) patients = search.perform_resources(demo_fhir_server()) return {'name': patients[0].name[0].text, 'id': patients[0].id}
def check_patient(patient_email): # Prepare the client fhir = client.FHIRClient(settings={ 'app_id': settings.FHIR_APP_ID, 'api_base': settings.FHIR_URL }) # Set the search parameters struct = { 'identifier': 'http://schema.org/email|{}'.format(patient_email) } # Get the questionnaire search = Patient.where(struct=struct) resources = search.perform_resources(fhir.server) if not resources: logger.warning('Patient not found: {}'.format( FHIR._obfuscate_email(patient_email))) raise FHIR.PatientDoesNotExist