Ejemplo n.º 1
0
def refreshDBwithFHIR(request):
    #get json from dir
    with open("hit_server/FHIRJsonResponse.json") as data_file:
        data = json.load(data_file)

    for p in data.keys():
        print p, data[p]["Contact Info"]["first_name"], data[p][
            "Contact Info"]["last_name"]
        patientobj = PatientInfo()  # create a patient object.
        patientobj.pid = p
        patientobj.first_name = data[p]["Contact Info"]["first_name"]
        patientobj.last_name = data[p]["Contact Info"]["last_name"]
        patientobj.save()

        #first add all conditions to patient?

        all_conditions = data[p]["Conditions"].keys()
        for con in all_conditions:
            conditionobj = Condition()
            conditionobj.condition_name = data[p]["Conditions"][con]["name"]
            conditionobj.onset_date = data[p]["Conditions"][con]["onset_date"]
            conditionobj.condition_code = data[p]["Conditions"][con]["code"]
            conditionobj.condition_desc = data[p]["Conditions"][con]["text"]
            conditionobj.condition_for_patients = patientobj  # how to use related object

            conditionobj.save()

        all_medications = data[p]["Medications"].keys()

        if len(all_medications) == 0:
            pass

        else:
            for meds in all_medications:
                medicationobj = Medication()
                medicationobj.med_status = data[p]["Medications"][meds][
                    "status"]
                medicationobj.med_name = data[p]["Medications"][meds]["name"]
                medicationobj.med_code = data[p]["Medications"][meds]["code"]
                medicationobj.med_dosage_value = data[p]["Medications"][meds][
                    "dosage_value"]
                medicationobj.med_dosage_text = data[p]["Medications"][meds][
                    "dosage_text"]
                medicationobj.med_dosage_units = data[p]["Medications"][meds][
                    "dosage_units"]
                medicationobj.med_date_written = data[p]["Medications"][meds][
                    "date_written"]
                medicationobj.med_code_system = data[p]["Medications"][meds][
                    "code_system"]

                medicationobj.medications_for_patients = patientobj  # how to use related object

                medicationobj.save()

        all_observations = data[p]["Observations"].keys()
        for obs in all_observations:
            observationobj = Observation()
            observationobj.obs_name = data[p]["Observations"][obs]["name"]
            observationobj.obs_code = data[p]["Observations"][obs]["code"]
            observationobj.obs_desc = data[p]["Observations"][obs]["text"]

            check_existance_of_value = data[p]["Observations"][obs].keys()
            if "value" in check_existance_of_value:
                observationobj.obs_value = data[p]["Observations"][obs][
                    "value"]
            else:
                observationobj.obs_value = 0.0

            if "units" in check_existance_of_value:
                observationobj.obs_units = data[p]["Observations"][obs][
                    "units"]
            else:
                observationobj.obs_units = "NULL"

            observationobj.obs_date = data[p]["Observations"][obs]["date_time"]

            observationobj.obs_for_patients = patientobj  # how to use related object

            observationobj.save()

    return HttpResponse()
    '''
Ejemplo n.º 2
0
def refreshDBwithFHIR(request):
	#get json from dir
	with open("hit_server/FHIRJsonResponse.json") as data_file:
		data = json.load(data_file)

	for p in data.keys():
		print p, data[p]["Contact Info"]["first_name"], data[p]["Contact Info"]["last_name"]
		patientobj = PatientInfo()  			# create a patient object.
		patientobj.pid = p
		patientobj.first_name = data[p]["Contact Info"]["first_name"]
		patientobj.last_name = data[p]["Contact Info"]["last_name"]
		patientobj.save()

		#first add all conditions to patient?

		all_conditions = data[p]["Conditions"].keys()
		for con in all_conditions:
			conditionobj = Condition()
			conditionobj.condition_name = data[p]["Conditions"][con]["name"]
			conditionobj.onset_date = data[p]["Conditions"][con]["onset_date"]
			conditionobj.condition_code = data[p]["Conditions"][con]["code"]
			conditionobj.condition_desc = data[p]["Conditions"][con]["text"]
			conditionobj.condition_for_patients = patientobj   # how to use related object

			conditionobj.save()

		all_medications = data[p]["Medications"].keys()

		if len(all_medications) == 0:
			pass

		else:
			for meds in all_medications:
				medicationobj = Medication()
				medicationobj.med_status = data[p]["Medications"][meds]["status"]
				medicationobj.med_name = data[p]["Medications"][meds]["name"]
				medicationobj.med_code = data[p]["Medications"][meds]["code"]
				medicationobj.med_dosage_value = data[p]["Medications"][meds]["dosage_value"]
				medicationobj.med_dosage_text = data[p]["Medications"][meds]["dosage_text"]
				medicationobj.med_dosage_units = data[p]["Medications"][meds]["dosage_units"]
				medicationobj.med_date_written = data[p]["Medications"][meds]["date_written"]
				medicationobj.med_code_system = data[p]["Medications"][meds]["code_system"]


				medicationobj.medications_for_patients = patientobj   # how to use related object

				medicationobj.save()


		all_observations = data[p]["Observations"].keys()
		for obs in all_observations:
			observationobj = Observation()
			observationobj.obs_name = data[p]["Observations"][obs]["name"]
			observationobj.obs_code = data[p]["Observations"][obs]["code"]
			observationobj.obs_desc = data[p]["Observations"][obs]["text"]

			check_existance_of_value = data[p]["Observations"][obs].keys()
			if "value" in check_existance_of_value:
				observationobj.obs_value = data[p]["Observations"][obs]["value"]
			else:
				observationobj.obs_value = 0.0

			if "units" in check_existance_of_value:
				observationobj.obs_units = data[p]["Observations"][obs]["units"]
			else:
				observationobj.obs_units = "NULL"


			observationobj.obs_date = data[p]["Observations"][obs]["date_time"]

			observationobj.obs_for_patients = patientobj   # how to use related object

			observationobj.save()

	return HttpResponse()

	'''