Ejemplo n.º 1
0
    def _change_index(self, old_index_patient, new_index_patient):
        self.set_as_index_patient(new_index_patient)
        updated_rels = set([])
        original_relatives = set(
            [r.pk for r in old_index_patient.relatives.all()])
        for relative_dict in self.relatives:
            if relative_dict["class"] == "PatientRelative":
                patient_relative = PatientRelative.objects.get(
                    pk=relative_dict["pk"])
                patient_relative.patient = new_index_patient
                patient_relative.relationship = relative_dict["relationship"]
                patient_relative.save()
                updated_rels.add(patient_relative.pk)

            elif relative_dict["class"] == "Patient":
                # index 'demoted' : create patient rel object
                patient = Patient.objects.get(pk=relative_dict["pk"])

                new_patient_relative = PatientRelative()
                new_patient_relative.date_of_birth = patient.date_of_birth
                new_patient_relative.patient = new_index_patient
                new_patient_relative.relative_patient = patient
                new_patient_relative.given_names = relative_dict["given_names"]
                new_patient_relative.family_name = relative_dict["family_name"]
                self.set_as_relative(patient)
                new_patient_relative.relationship = relative_dict[
                    "relationship"]
                new_patient_relative.save()
                updated_rels.add(new_patient_relative.pk)
            else:
                fml_log("???? %s" % relative_dict)

        promoted_relatives = original_relatives - updated_rels
        fml_log("promoted rels = %s" % promoted_relatives)
Ejemplo n.º 2
0
 def _update_relatives(self):
     for relative_dict in self.relatives:
         if relative_dict['class'] == "PatientRelative":
             rel = PatientRelative.objects.get(pk=relative_dict["pk"])
             if rel.relationship != relative_dict["relationship"]:
                 rel.relationship = relative_dict["relationship"]
                 rel.save()
         elif relative_dict['class'] == "Patient":
             patient = Patient.objects.get(pk=relative_dict["pk"])
             rel = PatientRelative()
             rel.date_of_birth = patient.date_of_birth
             rel.patient = self.index_patient
             rel.given_names = relative_dict["given_names"]
             rel.family_name = relative_dict["family_name"]
             rel.relationship = relative_dict["relationship"]
             rel.relative_patient = patient
             rel.save()
             self.set_as_relative(patient)
Ejemplo n.º 3
0
    def _change_index(self, old_index_patient, new_index_patient):
        self.set_as_index_patient(new_index_patient)
        updated_rels = set([])
        index_and_rels = set()
        original_relatives = set([r.pk for r in old_index_patient.relatives.all()])
        for relative_dict in self.relatives:
            if relative_dict["class"] == "PatientRelative":
                patient_relative = PatientRelative.objects.get(pk=relative_dict["pk"])
                patient_relative.patient = new_index_patient
                patient_relative.relationship = relative_dict["relationship"]
                patient_relative.save()
                updated_rels.add(patient_relative.patient.id)
                index_and_rels.add(patient_relative.relative_patient.id)
                index_and_rels.add(patient_relative.patient.id)
            elif relative_dict["class"] == "Patient":
                # index 'demoted' : create patient rel object
                patient = Patient.objects.get(pk=relative_dict["pk"])

                new_patient_relative = PatientRelative()
                new_patient_relative.date_of_birth = patient.date_of_birth
                new_patient_relative.patient = new_index_patient
                new_patient_relative.relative_patient = patient
                new_patient_relative.given_names = relative_dict["given_names"]
                new_patient_relative.family_name = relative_dict["family_name"]
                self.set_as_relative(patient)
                new_patient_relative.relationship = relative_dict["relationship"]
                new_patient_relative.save()
                updated_rels.add(new_patient_relative.patient.id)
                index_and_rels.add(new_patient_relative.relative_patient.id)
                index_and_rels.add(new_patient_relative.patient.id)
            else:
                fml_log("???? %s" % relative_dict)

        # recalculate fields for the changed patients
        call_command('update_calculated_fields', registry_code=self.registry_model.code, patient_id=index_and_rels)

        promoted_relatives = original_relatives - updated_rels
        fml_log("promoted rels = %s" % promoted_relatives)