def create_patient_resource(resource_id, nhs_number, title, first_name,
                            last_name, gender, date_of_birth, address_line_1,
                            city, postcode, place_of_birth):
    """
    Helper function to create a basic fhir patient
    :return: Patient
    """
    pat_address = Address({
        'line': [address_line_1],
        'city': city,
        'postalCode': postcode
    })
    nhs_number = Identifier({'value': nhs_number})
    name = HumanName({
        'prefix': [title],
        'family': last_name,
        'given': [first_name]
    })
    birth_address = Address({'city': place_of_birth})
    place_of_birth = Extension({
        'url': 'http://hl7.org/fhir/StructureDefinition/birthPlace',
        'valueAddress': birth_address.as_json()
    })
    patient = Patient({
        'id': resource_id,
        'identifier': [nhs_number.as_json()],
        'gender': gender,
        'name': [name.as_json()],
        'birthDate': date_of_birth,
        'address': [pat_address.as_json()],
        'extension': [place_of_birth.as_json()]
    })
    return patient
コード例 #2
0
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}
コード例 #3
0
def create_operation_definition_for_death_registration(free_text=None):
    practitioner = create_simple_practitioner()
    patient = Patient({
        'id': 'patient-1',
        'identifier': [{
            'value': 'NHSNO22222'
        }],
        'deceasedBoolean': True,
        'deceasedDateTime': '2019-04-20 09:00:04.159338'
    })

    op_param_interchange_sequence = creators.create_parameter_with_binding(
        name=ParameterName.INTERCHANGE_SEQ_NO, value="000001")
    op_param_message_sequence = creators.create_parameter_with_binding(
        name=ParameterName.MESSAGE_SEQ_NO, value="000001")
    op_param_nhais_cypher = creators.create_parameter_with_binding(
        name=ParameterName.NHAIS_CYPHER, value="XX1")
    op_param_sender_cypher = creators.create_parameter_with_binding(
        name=ParameterName.SENDER_CYPHER, value="TES5")
    op_param_transaction_number = creators.create_parameter_with_binding(
        name=ParameterName.TRANSACTION_NO, value="17")
    op_param_practitioner = creators.create_parameter_with_resource_ref(
        name=ParameterName.REGISTER_PRACTITIONER,
        resource_type=ResourceType.PRACTITIONER,
        reference="practitioner-1")
    op_param_patient = creators.create_parameter_with_resource_ref(
        name=ParameterName.REGISTER_PATIENT,
        resource_type=ResourceType.PATIENT,
        reference="patient-1")
    parameters = [
        op_param_interchange_sequence, op_param_message_sequence,
        op_param_nhais_cypher, op_param_sender_cypher,
        op_param_transaction_number, op_param_practitioner, op_param_patient
    ]
    if free_text:
        parameters.append(
            creators.create_parameter_with_binding(
                name=ParameterName.FREE_TEXT, value=free_text))

    op_def = creators.create_operation_definition(
        name=OperationName.REGISTER_DEATH,
        code="gpc.registerpatient",
        date_time="2019-04-23 09:00:04.159338",
        contained=[practitioner, patient],
        parameters=parameters)

    return op_def
コード例 #4
0
 def to_fhir_res(self):
     data = {
         'id': self.id,
         'identifier': [{
             'value': self.identifier
         }],
         'name': [{
             'given': self.given_name.split(' '),
             'family': self.family_name
         }],
         'gender': {'m': 'male', 'f': 'female', 'u': 'unknown', 'o': 'other'}[self.gender],
         'birthDate': self.birthdate.isoformat() if self.birthdate is not None else None,
         'address': [{
             'text': self.address
         }]
     }
     return Patient(data)
コード例 #5
0
ファイル: fhir.py プロジェクト: hms-dbmi/fhirquestionnaire
    def get_demo_patient(email):
        """
        Returns an instance of a FHIR Patient using dummy info for testing

        :param email: The email of the testing user
        :type email: str
        :return: Test Patient resource object
        :rtype: Patient
        """
        return Patient(
            jsondict={
                'id':
                'TEST',
                'identifier': [{
                    'system': PPMFHIR.patient_email_identifier_system,
                    'value': email
                }]
            })
コード例 #6
0
ファイル: fhir.py プロジェクト: hms-dbmi/fhirquestionnaire
    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
コード例 #7
0
ファイル: patient.py プロジェクト: svituz/fhir-server
def _get_patient(patient_id):
    p = FHIRPatient()
    p.id = str(patient_id)
    return p
コード例 #8
0
ファイル: client.py プロジェクト: julsas/ops2fhir
 def post_patient_validate(self, pat: patient.Patient):
     url = f'{self.base_url}/Patient/$validate'
     data = json.dumps(pat.as_json())
     return self.session.post(url, data)
コード例 #9
0
from fhirclient.client import FHIRServer
from fhirclient.models.patient import Patient

server = FHIRServer(None, "http://hapi.fhir.org/baseR4")
p = Patient.read("921009", server)
print("-" * 40)
print("Patient Information")
print("-" * 40)
print(f"NAME: {p.name[0].text}")
print(f"BIRTHDATE: {p.birthDate.date.isoformat()}")

from fhirclient.models.condition import Condition

# from fhirclient.models.bundle import Bundle

# conditionBundle = Condition.where( { "subject": "921009" } ).perform( server )
# if conditionBundle.entry is None:
conditions = Condition.where({"subject": "921009"}).perform_resources(server)
if not conditions:
    print("PROBLEM LIST: None")
else:
    print("PROBLEM LIST:")
    i = 1
    # for entry in conditionBundle.entry:
    for cond in conditions:
        # cond = entry.resource
        print(
            f"{i:>3d}. {cond.code.text:<40s} Severity: {cond.severity.text:<12s}"
        )
        i += 1
コード例 #10
0
def get_patient_detail(fhir, pat_id):
    pat = Patient.read(pat_id, fhir.server)

    # If set, use this to query on a fixed time point.
    if REF_DATE:
        ref_date = REF_DATE
    else:
        ref_date = datetime.now()

    # Only the last 24 hours are considered.
    past24 = ref_date - timedelta(days=1)

    # Vital signs for the patient. Includes SBP, HR, RR, satO2, temp
    search = Observation.where(struct={
        'subject': pat_id,
        'category': VITAL_SIGNS_CATEGORY,
        'date': {
            '$gte': past24.strftime('%Y-%m-%dT%H:%M:%SZ'),
        },
    })

    bp = []
    hr = []
    rr = []
    temp = []
    o2 = []

    # Implicitly fetches pages on demand.
    for r in search.perform_resources(fhir.server):
        # Resource code.
        system = r.code.coding[0].system
        code = r.code.coding[0].code

        if system != LOINC_SYSTEM:
            continue

        # Extract systolic component from blood pressure.
        if code == LOINC_BP:
            sbp = None
            dbp = None

            for c in r.component:
                if c.code.coding[0].code == LOINC_SBP:
                    sbp = {
                        'time': r.effectiveDateTime.isostring,
                        'value': c.valueQuantity.value,
                        'unit': c.valueQuantity.unit,
                    }
                elif c.code.coding[0].code == LOINC_DBP:
                    dbp = {
                        'time': r.effectiveDateTime.isostring,
                        'value': c.valueQuantity.value,
                        'unit': c.valueQuantity.unit,
                    }

            if sbp or dbp:
                bp.append({
                    'systolic': sbp,
                    'diastolic': dbp,
                })

        elif code == LOINC_HR:
            hr.append({
                'time': r.effectiveDateTime.isostring,
                'value': r.valueQuantity.value,
                'unit': r.valueQuantity.unit,
            })

        elif code == LOINC_RR:
            rr.append({
                'time': r.effectiveDateTime.isostring,
                'value': r.valueQuantity.value,
                'unit': r.valueQuantity.unit,
            })

        elif code == LOINC_TEMP:
            temp.append({
                'time': r.effectiveDateTime.isostring,
                'value': r.valueQuantity.value,
                'unit': r.valueQuantity.unit,
            })

        elif code == LOINC_O2:
            o2.append({
                'time': r.effectiveDateTime.isostring,
                'value': r.valueQuantity.value,
                'unit': r.valueQuantity.unit,
            })

    mrn = None
    if pat.identifier:
        mrn = pat.identifier[0].value

    return {
        'id': pat_id,
        'mrn': mrn,
        'name': parse_human_name(pat.name[0]),
        'birth_date': pat.birthDate.isostring,
        'gender': pat.gender,
        'measures': {
            'heart_rate': hr,
            'respiratory_rate': rr,
            'temperature': temp,
            'pulse_ox': o2,
            'blood_pressure': bp,
            'mental_status': None,
            'eating_status': None,
        },
    }
コード例 #11
0
from fhirclient.client import FHIRServer
from fhirclient.models.patient import Patient

server = FHIRServer(None, "http://hapi.fhir.org/baseDstu3")
p = Patient.read("2716055", server)
print("-" * 40)
print("Patient Information")
print("-" * 40)
print(f"NAME: {p.name[0].text}")
print(f"BIRTHDATE: {p.birthDate.date.isoformat()}")

from fhirclient.models.condition import Condition

conditions = Condition.where({"subject": "2716055"}).perform_resources(server)
if not conditions:
    print("PROBLEM LIST: None")
else:
    print("PROBLEM LIST:")
    i = 1
    for cond in conditions:
        print(
            f"{i:>3d}. {cond.code.text:<40s} Severity: {cond.severity.text:<12s}"
        )
        i += 1

from fhirclient.models.encounter import Encounter

encounters = Encounter.where({"subject": "2716055"}).perform_resources(server)
if not encounters:
    print("ENCOUNTER LIST: None")
else: