Example #1
0
def copyProjectExperiments(project, new_project):

    t_experiments = Experiment.objects.filter(project=project)
    for experiment in t_experiments:

        new_experiment = Experiment(project=new_project,
                                    name=str(experiment.name),
                                    notes=str(experiment.notes))
        new_experiment.save()
        t_conditions = Condition.objects.filter(experiment=experiment)
        for condition in t_conditions:
            new_condition = Condition(experiment=new_experiment,
                                      name=str(condition.name),
                                      notes=str(condition.notes))
            new_condition.save()

            t_observations = Observation.objects.filter(condition=condition)
            for t_observation in t_observations:
                new_observation = Observation(
                    condition=new_condition,
                    species=t_observation.species,
                    time=t_observation.time,
                    value=t_observation.value,
                    stddev=t_observation.stddev,
                    steady_state=t_observation.steady_state,
                    min_steady_state=t_observation.min_steady_state,
                    max_steady_state=t_observation.max_steady_state)

                new_observation.save()

            t_treatments = Treatment.objects.filter(condition=condition)
            for t_treatment in t_treatments:
                new_treatment = Treatment(condition=new_condition,
                                          species=t_treatment.species,
                                          time=t_treatment.time,
                                          value=t_treatment.value)

                new_treatment.save()

            new_condition.save()
        new_experiment.save()
Example #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()
    '''
Example #3
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()

	'''