示例#1
0
def patient(id):
    fhir = FHIR()
    patient = fhir.get_patient(id)
    observations = fhir.get_patient_observations(id)

    return render_template('patientinfo.html',
                           observations=observations,
                           patient=patient)
示例#2
0
def observations(id):
    fhir = FHIR()
    patient = fhir.get_patient(id)
    observations = fhir.get_patient_observations(id)
    spreadSheet = {
        'bodyWeight': [],
        'BMI': [],
        'dBP': [],
        'sBP': [],
        'pain': [],
        'latestObs': {
            'uuid': "",
            'latestDate': "",
            'type': "",
            'status': "",
            'weight': "",
            'sBP': "",
            'BMI': ""
        }
    }
    for i in observations:
        components = i.components
        for i2 in components:
            value = i2.value
            if value == None: continue
            date = i.effective_datetime
            dateStr = str(date.day) + "/" + str(date.month) + "/" + str(
                date.year)
            display = i2.display
            if display == "Body Weight":
                spreadSheet['bodyWeight'].append((dateStr, value))
            elif display == "Diastolic Blood Pressure":
                spreadSheet['dBP'].append((dateStr, value))
            elif display == "Systolic Blood Pressure":
                spreadSheet['sBP'].append((dateStr, value))
            elif display == "Body Mass Index":
                spreadSheet['BMI'].append((dateStr, value))
            elif "Pain severity" in display:
                spreadSheet['pain'].append((dateStr, value))

    dictItemsToBeSorted = [
        spreadSheet['bodyWeight'], spreadSheet['BMI'], spreadSheet['dBP'],
        spreadSheet['sBP'], spreadSheet['pain']
    ]
    sortTime(dictItemsToBeSorted)

    spreadSheet['latestObs']['uuid'] = observations[-1].uuid
    tmp = observations[-1].effective_datetime
    spreadSheet['latestObs']['latestDate'] = str(tmp.day) + "/" + str(
        tmp.month) + "/" + str(tmp.year)
    spreadSheet['latestObs']['type'] = observations[-1].type
    spreadSheet['latestObs']['status'] = observations[-1].status
    spreadSheet['latestObs']['weight'] = spreadSheet['bodyWeight'][-1][-1]
    spreadSheet['latestObs']['sBP'] = spreadSheet['sBP'][-1][-1]
    spreadSheet['latestObs']['BMI'] = spreadSheet['BMI'][-1][-1]
    return render_template("observations.html",
                           obsData=spreadSheet,
                           patient=patient)
示例#3
0
 def __init__(self, patients_object: Patients):
     fhir = FHIR()
     self.patients = patients_object
     self.patients_uuid_list = self.patients.get_uuid()  # List
     if type(self.patients_uuid_list
             ) is not list:  # type is str when only patient is given
         self.patients_uuid_list = [self.patients_uuid_list]
     self.get_patient_observations_by_uuid = lambda x: fhir.get_patient_observations(
         x)
def getAttributes(uuid, obType, requiredAttributes):
    fhir = FHIR('https://localhost:5001/api/', verify_ssl=False)
    obs = fhir.get_patient_observations(uuid)
    count = 0
    attribList = []
    for ob in obs:
        if ob.type == obType:
            for i in ob.components:
                if count in requiredAttributes:
                    attribList.append(str(i))
                count += 1
    return attribList
示例#5
0
def observationstats():
    fhir = FHIR()
    patients = fhir.get_all_patients()
    observations = []

    for patient in patients:
        observations.extend(fhir.get_patient_observations(patient.uuid))

    total_obsv = len(observations)

    observation_types = [observation.type for observation in observations]
    most_frequent_observation_type = max(set(observation_types),
                                         key=observation_types.count)

    observation_components = []
    for observation in observations:
        observation_components.extend(observation.components)

    total_obsv_components = len(observation_components)

    observation_component_types = [
        observation_component.display
        for observation_component in observation_components
    ]
    most_frequent_observation_component_type = max(set(observation_types),
                                                   key=observation_types.count)

    obsvstats_dictionary = {
        "totalObsv": total_obsv,
        "mfObservationType": most_frequent_observation_type,
        "totalObsvComp": total_obsv_components,
        "mfObsvCompType": most_frequent_observation_component_type
    }

    response = jsonify(obsvstats_dictionary)
    return response
示例#6
0
def save_doc(text, dropdown):
    # Full list of patients
    fhir = FHIR()
    patients = fhir.get_all_patients()
    document = Document()
    new_line = " "

    # Find number of patients
    number_of_patients = 0
    for i in patients:
        number_of_patients = number_of_patients + 1

    # Index of Patient
    if dropdown == "Forename":
        result = forename(text)
    elif dropdown == "Surname":
        result = surname(text)
    else:
        result = unique_identifier(text)
    patient = patients[result]

    # Address of Patient
    address = patient.addresses[0]
    communications = patient.communications

    # Date Today
    today = date.today()

    # Marital Status
    marital_status_patient = patient.marital_status.marital_status

    # Age
    age = today.year - patient.birth_date.year - (
        (today.month, today.day) <
        (patient.birth_date.month, patient.birth_date.day))

    # Records of patients
    patient_data = {"Unique Identifier": patient.uuid.upper(), "Surname": patient.name.family,
                    "Forename": patient.name.given, "Gender": patient.gender.capitalize(),
                    "Birthday": str(patient.birth_date.day) + "." + str(patient.birth_date.month) + "." \
                                + str(patient.birth_date.year), "Age": str(age),
                    "Marital Status": str(marital_status_patient), "Address": address.full_address,
                    "Languages Spoken": communications.languages}

    # Records of a patient
    observations = fhir.get_patient_observations(
        patient_data["Unique Identifier"].lower())

    # Number of observations for 1 Patient
    count = 0
    for i in observations:
        count = count + 1

    # NHS Image
    LOGO = "1280px-NHS-Logo.svg.png"
    logo = document.add_picture(LOGO, width=Inches(1.50))
    document.add_heading(patient.name.full_name, 1)
    document.add_heading(new_line, 1)

    # Adding general information about a patient in a word document
    for data in patient_data:
        p = document.add_paragraph()
        p.add_run(data + ": ").bold = True
        p.add_run(patient_data[data])
    document.add_heading(new_line, 1)

    # Creating a table
    table = document.add_table(rows=1, cols=8)
    hdr_cells = table.rows[0].cells
    hdr_cells[0].text = 'Observation(s)       '
    hdr_cells[1].text = 'Number'
    hdr_cells[2].text = 'Type'
    hdr_cells[3].text = 'Status      '
    hdr_cells[5].text = 'Issued Date'
    hdr_cells[6].text = 'Code'
    hdr_cells[7].text = 'Result'

    # Adding data into the table
    for i in range(0, count):
        row_cells = table.add_row().cells
        row_cells[0].text = str(i + 1)
        row_cells[1].text = observations[i].uuid.upper()
        row_cells[2].text = observations[i].type.capitalize()
        row_cells[3].text = observations[i].status.capitalize()
        row_cells[5].text = str(observations[i].issued_datetime)
        for component in observations[i].components:
            row_cells[6].text = component.code
            row_cells[7].text = component.display + ": " + component.quantity()

    # Save the document
    document.save(
        str(patient.name.given[0]) + "." + str(patient.name.family) + "." +
        str(age) + '.docx')
示例#7
0
def getstatistics(id):
    fhir = FHIR()
    patient = fhir.get_patient(id)
    observations = fhir.get_patient_observations(id)

    bp_dict = {"date": [], "dbp": [], "sbp": []}

    hr_dict = {"date": [], "hr": []}

    rr_dict = {"date": [], "rr": []}

    bw_dict = {"date": [], "bw": []}

    bh_dict = {"date": [], "bh": []}

    bmi_dict = {"date": [], "bmi": []}

    bmip_dict = {"date": [], "bmip": []}

    ps_dict = {"date": [], "ps": []}

    temp_bp_dates = []
    bp_observations = []
    temp_hr_dates = []
    hr_observations = []
    temp_rr_dates = []
    rr_observations = []

    temp_bw_dates = []
    bw_observations = []
    temp_bh_dates = []
    bh_observations = []
    temp_bmi_dates = []
    bmi_observations = []
    temp_bmip_dates = []
    bmip_observations = []

    temp_ps_dates = []
    ps_observations = []

    for observation in observations:
        if observation.components[0].display == "Blood Pressure":
            bp_observations.append(observation)
            temp_bp_dates.append(observation.effective_datetime)

        if observation.components[0].display == "Heart rate":
            hr_observations.append(observation)
            temp_hr_dates.append(observation.effective_datetime)

        if observation.components[0].display == "Respiratory rate":
            rr_observations.append(observation)
            temp_rr_dates.append(observation.effective_datetime)

        if observation.components[0].display == "Body Weight":
            bw_observations.append(observation)
            temp_bw_dates.append(observation.effective_datetime)

        if observation.components[0].display == "Body Height":
            bh_observations.append(observation)
            temp_bh_dates.append(observation.effective_datetime)

        if observation.components[0].display == "Body Mass Index":
            bmi_observations.append(observation)
            temp_bmi_dates.append(observation.effective_datetime)

        if observation.components[
                0].display == "Body mass index (BMI) [Percentile] Per age and gender":
            bmip_observations.append(observation)
            temp_bmip_dates.append(observation.effective_datetime)

        if observation.components[
                0].display == "Pain severity - 0-10 verbal numeric rating [Score] - Reported":
            ps_observations.append(observation)
            temp_ps_dates.append(observation.effective_datetime)

    temp_hr_dates.sort()
    temp_bp_dates.sort()
    temp_rr_dates.sort()
    temp_bw_dates.sort()
    temp_bh_dates.sort()
    temp_bmi_dates.sort()
    temp_bmip_dates.sort()
    temp_ps_dates.sort()

    for i in range(0, len(temp_bp_dates)):
        for observation in bp_observations:
            if temp_bp_dates[i] == observation.effective_datetime:
                bp_dict["date"].append(
                    int(time.mktime(temp_bp_dates[i].timetuple())) * 1000)
                bp_dict["dbp"].append(observation.components[1].value)
                bp_dict["sbp"].append(observation.components[2].value)
                break

    for i in range(0, len(temp_hr_dates)):
        for observation in hr_observations:
            if temp_hr_dates[i] == observation.effective_datetime:
                hr_dict["date"].append(
                    int(time.mktime(temp_hr_dates[i].timetuple())) * 1000)
                hr_dict["hr"].append(observation.components[0].value)
                break

    for i in range(0, len(temp_rr_dates)):
        for observation in rr_observations:
            if temp_rr_dates[i] == observation.effective_datetime:
                rr_dict["date"].append(
                    int(time.mktime(temp_rr_dates[i].timetuple())) * 1000)
                rr_dict["rr"].append(observation.components[0].value)
                break

    for i in range(0, len(temp_bw_dates)):
        for observation in bw_observations:
            if temp_bw_dates[i] == observation.effective_datetime:
                bw_dict["date"].append(
                    int(time.mktime(temp_bw_dates[i].timetuple())) * 1000)
                bw_dict["bw"].append(observation.components[0].value)
                break

    for i in range(0, len(temp_bh_dates)):
        for observation in bh_observations:
            if temp_bh_dates[i] == observation.effective_datetime:
                bh_dict["date"].append(
                    int(time.mktime(temp_bh_dates[i].timetuple())) * 1000)
                bh_dict["bh"].append(observation.components[0].value)
                break

    for i in range(0, len(temp_bmi_dates)):
        for observation in bmi_observations:
            if temp_bmi_dates[i] == observation.effective_datetime:
                bmi_dict["date"].append(
                    int(time.mktime(temp_bmi_dates[i].timetuple())) * 1000)
                bmi_dict["bmi"].append(observation.components[0].value)
                break

    for i in range(0, len(temp_bmip_dates)):
        for observation in bmip_observations:
            if temp_bmip_dates[i] == observation.effective_datetime:
                bmip_dict["date"].append(
                    int(time.mktime(temp_bmip_dates[i].timetuple())) * 1000)
                bmip_dict["bmip"].append(observation.components[0].value)
                break

    for i in range(0, len(temp_ps_dates)):
        for observation in ps_observations:
            if temp_ps_dates[i] == observation.effective_datetime:
                ps_dict["date"].append(
                    int(time.mktime(temp_ps_dates[i].timetuple())) * 1000)
                ps_dict["ps"].append(observation.components[0].value)
                break

    return render_template('statistics.html',
                           patient=patient,
                           bp_dict=bp_dict,
                           hr_dict=hr_dict,
                           rr_dict=rr_dict,
                           bw_dict=bw_dict,
                           bh_dict=bh_dict,
                           bmi_dict=bmi_dict,
                           bmip_dict=bmip_dict,
                           ps_dict=ps_dict)
示例#8
0
from fhir_parser import FHIR

fhir = FHIR()
patients = fhir.get_all_patients()
observations = []

for patient in patients:
    observations.extend(fhir.get_patient_observations(patient.uuid))

print("Total of {} observations".format(len(observations)))

observation_types = [observation.type for observation in observations]
most_frequent_observation_type = max(set(observation_types),
                                     key=observation_types.count)
print(
    "Most common observation type: {}".format(most_frequent_observation_type))

observation_components = []
for observation in observations:
    observation_components.extend(observation.components)

print("Total of {} observation components".format(len(observation_components)))

observation_component_types = [
    observation_component.display
    for observation_component in observation_components
]
most_frequent_observation_component_type = max(set(observation_types),
                                               key=observation_types.count)
print("Most common observation component type: {}".format(
    most_frequent_observation_component_type))
     ser.write((current_patient.birth_date.isoformat()
                ).ljust(16).encode('ASCII'))
     ser.write((' '.join(current_patient.communications.languages)
                ).ljust(16).encode('ASCII'))
 if value.startswith("LEFT"):
     print("LEFT pressed")
     sleep(0.2)
     ser.write((str(
         current_patient.marital_status)).ljust(16).encode('ASCII'))
     ser.write(((
         current_patient.telecoms[0].number)).ljust(16).encode('ASCII'))
 if value.startswith("UP"):
     print("UP pressed")
     sleep(0.2)
     if observations is None:
         observations = fhir.get_patient_observations(
             current_patient.uuid)
         cur_ob = 0
     if cur_ob != 0:
         cur_ob -= 1
     ser.write((str(observations[cur_ob].components[0].display)
                ).ljust(16).encode('ASCII'))
     ser.write(((str(observations[cur_ob].components[0].quantity()))
                ).ljust(16).encode('ASCII'))
 if value.startswith("DOWN"):
     print("DOWN pressed")
     sleep(0.2)
     if observations is None:
         observations = fhir.get_patient_observations(
             current_patient.uuid)
         cur_ob = 0
     if cur_ob < len(observations):