def getPatient(patientID): fhir = FHIR('https://localhost:5001/api/', verify_ssl=False) try: patient = fhir.get_patient(patientID) except: patient = None return patient
def get_report(request, uid): fhir = FHIR('https://localhost:5001/api/', verify_ssl=False) if request.method == 'GET': try: patient = fhir.get_patient(uid) fbcReqAttributes = ("laboratory", [2, 13, 5, 3, 15, 16, 17, 6]) bpReqAttributes = ("vital-signs", [3, 4, 5]) otherReqAttributes = ("laboratory", [22, 23, 24, 25, 26, 27, 28, 33, 55]) fbcAttributes = getAttributes(uid, fbcReqAttributes[0], fbcReqAttributes[1]) bpAttributes = getAttributes(uid, bpReqAttributes[0], bpReqAttributes[1]) otherAttributes = getAttributes(uid, otherReqAttributes[0], otherReqAttributes[1]) myDict = { 'UID': patient.uuid, 'Name': patient.name.full_name, 'Address': str(patient.addresses[0]), 'Full-Blood Count Attributes': makeDict(fbcAttributes), 'Blood Pressure Values': makeDict(bpAttributes), 'Other blood readings': makeDict(otherAttributes) } response = json.dumps(myDict) return HttpResponse(response, content_type='text/json') except ConnectionError: response = json.dumps([{'Error': 'No patient found'}]) return HttpResponse(response, content_type='text/json')
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)
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)
def __init__(self, page=None, patient_uuid=None): fhir = FHIR() self.uuid_presented = False self.patients = fhir.get_all_patients() if patient_uuid is not None: self.uuid_presented = True self.specific_patient = fhir.get_patient(patient_uuid) if page is not None: try: assert patient_uuid is None self.patients = fhir.get_patient_page(page) except AssertionError: sys.exit( "Error: patients page and patient uuid cannot be initialised at the same time" )
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)
def getSpecificPatient(uuid): fhir = FHIR() patients = fhir.get_all_patients() specific_patient = fhir.get_patient(uuid) return specific_patient
with serial.Serial('COM7', 9600, timeout=10) as ser: ser.flush() sleep(1) ser.write(b"!FHIR Hackathon!") ser.write(b"Waiting....") print("Finished starting") current_uuid = '8f789d0b-3145-4cf2-8504-13159edaa747' while True: value = ser.readline().decode('ASCII') print(value) if value.startswith("PATIENT:"): uuid = value.split(":")[1] uuid = uuid[:8] + '-' + uuid[8:12] + '-' + uuid[ 12:16] + '-' + uuid[16:20] + '-' + uuid[20:] try: current_patient = fhir.get_patient(uuid) current_uuid = uuid except ConnectionError: pass observations = None ser.write((current_patient.name.prefix + current_patient.name.given).ljust(16).encode('ASCII')) ser.write((current_patient.name.family).ljust(16).encode('ASCII')) if value.startswith("SELECT"): sleep(0.2) print("SELECT pressed") uuid = '8f789d0b-3145-4cf2-8504-13159edaa747' current_uuid = uuid current_patient = fhir.get_patient(current_uuid) observations = None ser.write((current_patient.name.prefix +