Example #1
0
    def test_doesnt_update_a_different_patient(self):
        other_patient = Patient.objects.create()
        patient = models.Patient()
        patient.save()
        yesterday = timezone.make_aware(datetime.datetime.now() -
                                        datetime.timedelta(1))
        InpatientAdmission.objects.create(datetime_of_admission=yesterday,
                                          external_identifier="1",
                                          patient=patient)

        now = datetime.datetime.now().strftime(
            settings.DATETIME_INPUT_FORMATS[0])

        update_dict = dict(datetime_of_admission=now,
                           external_identifier="",
                           patient_id=other_patient.id)

        a = InpatientAdmission()
        a.update_from_dict(update_dict, self.user)

        results = InpatientAdmission.objects.all()
        self.assertEqual(2, len(results))

        self.assertEqual(results[0].datetime_of_admission.date(),
                         yesterday.date())

        self.assertEqual(results[1].datetime_of_admission.date(),
                         datetime.date.today())
Example #2
0
    def test_bulk_update_patient_subrecords(self):
        original_patient = models.Patient()

        d = {
            "demographics": [{
                "first_name": "Samantha",
                "surname": "Sun",
                "hospital_number": "123312"
            }],
            "patient_colour": [
                {
                    "name": "green"
                },
                {
                    "name": "purple"
                },
            ]
        }
        original_patient.bulk_update(d, self.user)

        patient = Patient.objects.get()
        demographics = patient.demographics()
        self.assertEqual(demographics.first_name, "Samantha")
        self.assertEqual(demographics.surname, "Sun")
        self.assertEqual(demographics.hospital_number, "123312")

        colours = patient.patientcolour_set.all()
        self.assertEqual(len(colours), 2)
        self.assertTrue(patient.episode_set.exists())
Example #3
0
    def test_bulk_update_create_new_episode_for_preexisting_patient_if_not_passed_explicitly(
            self):
        original_patient = models.Patient()

        d = {
            "demographics": [{
                "first_name": "Samantha",
                "surname": "Sun",
                "hospital_number": "123312"
            }],
            "hat_wearer": [
                {
                    "name": "bowler"
                },
                {
                    "name": "wizard"
                },
            ],
            "location": [
                {
                    "ward": "a ward",
                    "bed": "a bed"
                },
            ]
        }
        original_patient.save()
        original_patient.create_episode()
        self.assertEqual(1, original_patient.episode_set.count())
        original_patient.bulk_update(d, self.user)
        self.assertEqual(2, original_patient.episode_set.count())
        self.assertEqual(models.Episode.objects.count(), 2)
        location = original_patient.episode_set.last().location_set.first()
        self.assertEqual(location.ward, "a ward")
Example #4
0
    def test_bulk_update_with_existing_patient_episode(self):
        original_patient = models.Patient()
        original_patient.save()
        original_episode = original_patient.create_episode()

        d = {
            "demographics": [{
                "first_name": "Samantha",
                "surname": "Sun",
                "hospital_number": "123312"
            }],
            "patient_colour": [
                {
                    "name": "green"
                },
                {
                    "name": "purple"
                },
            ]
        }
        original_patient.bulk_update(d, self.user)

        patient = Patient.objects.get()
        demographics = patient.demographics()
        self.assertEqual(demographics.first_name, "Samantha")
        self.assertEqual(demographics.surname, "Sun")
        self.assertEqual(demographics.hospital_number, "123312")

        colours = patient.patientcolour_set.all()
        self.assertEqual(len(colours), 2)
        self.assertEqual(
            set([colours[0].name, colours[1].name]),
            set(["green", "purple"]),
        )
        self.assertTrue(patient.episode_set.get(), original_episode)
Example #5
0
    def test_updates_with_external_identifer(self):
        patient = models.Patient()
        patient.save()
        yesterday = timezone.make_aware(datetime.datetime.now() - datetime.timedelta(1))
        InpatientAdmission.objects.create(
            datetime_of_admission=yesterday,
            external_identifier="1",
            patient=patient
        )

        now = timezone.make_aware(datetime.datetime.now()).strftime(
            settings.DATETIME_INPUT_FORMATS[0]
        )

        update_dict = dict(
            datetime_of_admission=now,
            external_identifier="1",
            patient_id=patient.id
        )

        a = InpatientAdmission()
        a.update_from_dict(update_dict, self.user)

        result = InpatientAdmission.objects.get()
        self.assertEqual(
            result.datetime_of_admission.date(),
            datetime.date.today()
        )
Example #6
0
    def test_bulk_update_without_demographics(self):
        original_patient = models.Patient()

        d = {
            "patient_colour": [
                {"name": "green"},
                {"name": "purple"},
            ]
        }

        original_patient.bulk_update(d, self.user)
        self.assertEqual(
            original_patient.demographics().hospital_number, ""
        )
Example #7
0
    def test_bulk_update_without_demographics(self):
        original_patient = models.Patient()

        d = {
            "patient_colour": [
                {
                    "name": "green"
                },
                {
                    "name": "purple"
                },
            ]
        }

        with self.assertRaises(ValueError):
            original_patient.bulk_update(d, self.user)
Example #8
0
    def test_bulk_update_episode_subrecords_without_episode(self):
        original_patient = models.Patient()

        d = {
            "demographics": [{
                "first_name": "Samantha",
                "surname": "Sun",
                "hospital_number": "123312"
            }],
            "hat_wearer": [
                {
                    "name": "bowler"
                },
                {
                    "name": "wizard"
                },
            ],
            "location": [
                {
                    "ward": "a ward",
                    "bed": "a bed"
                },
            ]
        }
        self.assertFalse(models.Episode.objects.exists())
        original_patient.bulk_update(d, self.user)

        patient = Patient.objects.get()
        demographics = patient.demographics()
        self.assertEqual(demographics.first_name, "Samantha")
        self.assertEqual(demographics.surname, "Sun")
        self.assertEqual(demographics.hospital_number, "123312")
        self.assertEqual(models.Episode.objects.count(), 1)
        episode = patient.episode_set.get()

        hat_wearers = episode.hatwearer_set.all()
        self.assertEqual(len(hat_wearers), 2)
        expected = set(["bowler", "wizard"])
        found = set([hat_wearers[0].name, hat_wearers[1].name])
        self.assertEqual(expected, found)
        self.assertEqual(hat_wearers[0].episode, episode)
        self.assertEqual(hat_wearers[1].episode, episode)

        location = episode.location_set.get()
        self.assertEqual(location.bed, "a bed")
        self.assertEqual(location.ward, "a ward")
Example #9
0
    def test_bulk_update_tagging(self):
        original_patient = models.Patient()
        original_patient.save()

        d = {
            "demographics": [{
                "first_name": "Samantha",
                "surname": "Sun",
                "hospital_number": "123312"
            }],
            "tagging": [
                {"id": 1, 'inpatient': True},
            ]
        }
        original_patient.bulk_update(d, self.user)
        episode = original_patient.episode_set.first()
        self.assertEqual(['inpatient'], episode.get_tag_names(self.user))
Example #10
0
    def test_bulk_update_patient_subrecords_respects_order(self):
        patient = models.Patient()

        d = {
            "demographics": [{
                "first_name": "Samantha",
                "surname": "Sun",
                "hospital_number": "123312"
            }],
            "patient_colour": [
                {"name": "green"},
                {"name": "purple"},
            ]
        }
        patient.bulk_update(d, self.user)
        colours = patient.patientcolour_set.all()
        expected = set(["green", "purple"])
        found = set([colours[0].name, colours[1].name])
        self.assertEqual(expected, found)
Example #11
0
 def test_create_episode(self):
     patient = models.Patient()
     patient.save()
     episode = patient.create_episode()
     self.assertEqual(models.Episode, episode.__class__)
     self.assertEqual(patient, episode.patient)