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())
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() )
def test_update_from_dict_no_id_or_patient_id(self): a = InpatientAdmission() with self.assertRaises(ValueError): a.update_from_dict({})