def test_no_external_identifier(self):
        Result.objects.create(
            result_status="Incomplete",
            external_identifier="1",
            patient=self.patient
        )

        update_dict = dict(
            result_status="Complete",
            patient_id=self.patient.id
        )

        a = Result()
        a.update_from_dict(update_dict, self.user)
        results = Result.objects.all()
        self.assertEqual(2, len(results))
        self.assertEqual(
            results[0].result_status, "Incomplete"
        )
        self.assertEqual(
            results[1].result_status, "Complete"
        )
        self.assertEqual(
            results[1].external_identifier, None
        )
Example #2
0
    def test_no_external_identifier(self):
        Result.objects.create(
            result_status="Incomplete",
            external_identifier="1",
            patient=self.patient
        )

        update_dict = dict(
            result_status="Complete",
            patient_id=self.patient.id
        )

        a = Result()
        a.update_from_dict(update_dict, self.user)
        results = Result.objects.all()
        self.assertEqual(2, len(results))
        self.assertEqual(
            results[0].result_status, "Incomplete"
        )
        self.assertEqual(
            results[1].result_status, "Complete"
        )
        self.assertEqual(
            results[1].external_identifier, None
        )
Example #3
0
    def test_updates_with_external_identifer(self):
        Result.objects.create(result_status="Incomplete",
                              external_identifier="1",
                              patient=self.patient)

        update_dict = dict(result_status="Complete",
                           external_identifier="1",
                           patient_id=self.patient.id)

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

        result = Result.objects.get()
        self.assertEqual(result.result_status, "Complete")
Example #4
0
    def test_next_updates_a_different_patient(self):
        other_patient = Patient.objects.create()
        Result.objects.create(result_status="Incomplete",
                              external_identifier="1",
                              patient=self.patient)

        update_dict = dict(result_status="Complete",
                           external_identifier="1",
                           patient_id=other_patient.id)

        a = Result()
        a.update_from_dict(update_dict, self.user)
        results = Result.objects.all()
        self.assertEqual(2, len(results))
        self.assertEqual(results[0].patient, self.patient)
        self.assertEqual(results[1].patient, other_patient)
Example #5
0
    def test_updates_with_external_identifer(self):
        Result.objects.create(
            result_status="Incomplete",
            external_identifier="1",
            patient=self.patient
        )

        update_dict = dict(
            result_status="Complete",
            external_identifier="1",
            patient_id=self.patient.id
        )

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

        result = Result.objects.get()
        self.assertEqual(
            result.result_status, "Complete"
        )
Example #6
0
    def test_next_updates_a_different_patient(self):
        other_patient = Patient.objects.create()
        Result.objects.create(
            result_status="Incomplete",
            external_identifier="1",
            patient=self.patient
        )

        update_dict = dict(
            result_status="Complete",
            external_identifier="1",
            patient_id=other_patient.id
        )

        a = Result()
        a.update_from_dict(update_dict, self.user)
        results = Result.objects.all()
        self.assertEqual(2, len(results))
        self.assertEqual(
            results[0].patient, self.patient
        )
        self.assertEqual(
            results[1].patient, other_patient
        )
Example #7
0
    def test_to_dict_and_from_dict(self):
        datetime_format = settings.DATETIME_INPUT_FORMATS[0]

        request_datetime = datetime.datetime(2016, 1, 2).strftime(
            datetime_format
        )
        observation_datetime = datetime.datetime(2016, 1, 6).strftime(
            datetime_format
        )
        last_edited = datetime.datetime(2016, 1, 7).strftime(
            datetime_format
        )

        result_args = dict(
            patient_id=self.patient.id,
            lab_number="234324",
            profile_code="2343344",
            external_identifier="234324.2343344",
            profile_description="RENAL PROFILE",
            request_datetime=request_datetime,
            observation_datetime=observation_datetime,
            last_edited=last_edited,
            result_status="FINAL",
            observations=[{
                u'comments': None,
                u'observation_value': u'250',
                u'reference_range': u'150-400',
                u'result_status': None,
                u'test_code': u'PLT',
                u'test_name': u'Platelet count',
                u'units': u'x10^9/L',
                u'value_type': u'NM'
            }, {
                u'comments': None,
                u'observation_value': u'10.0',
                u'reference_range': u'7-13',
                u'result_status': None,
                u'test_code': u'MPVU',
                u'test_name': u'MPV',
                u'units': u'fL',
                u'value_type': u'NM'
            }]
        )

        result = Result()
        result.update_from_dict(result_args, self.user)

        found_result = Result.objects.get()
        self.assertEqual(found_result.lab_number, "234324")
        self.assertEqual(found_result.profile_code, "2343344")

        back_to_dict = found_result.to_dict(self.user)
        del back_to_dict["updated"]
        del back_to_dict["updated_by_id"]
        del back_to_dict["created"]
        del back_to_dict["created_by_id"]
        del back_to_dict["consistency_token"]
        del back_to_dict["id"]
        result_args["request_datetime"] = datetime.datetime(
            2016, 1, 2, tzinfo=pytz.UTC
        )
        result_args["observation_datetime"] = datetime.datetime(
            2016, 1, 6, tzinfo=pytz.UTC
        )
        result_args["last_edited"] = datetime.datetime(
            2016, 1, 7, tzinfo=pytz.UTC
        )

        self.assertEqual(result_args, back_to_dict)
Example #8
0
    def test_to_dict_and_from_dict(self):
        datetime_format = settings.DATETIME_INPUT_FORMATS[0]

        request_datetime = datetime.datetime(2016, 1,
                                             2).strftime(datetime_format)
        observation_datetime = datetime.datetime(2016, 1,
                                                 6).strftime(datetime_format)
        last_edited = datetime.datetime(2016, 1, 7).strftime(datetime_format)

        result_args = dict(patient_id=self.patient.id,
                           lab_number="234324",
                           profile_code="2343344",
                           external_identifier="234324.2343344",
                           profile_description="RENAL PROFILE",
                           request_datetime=request_datetime,
                           observation_datetime=observation_datetime,
                           last_edited=last_edited,
                           result_status="FINAL",
                           observations=[{
                               u'comments': None,
                               u'observation_value': u'250',
                               u'reference_range': u'150-400',
                               u'result_status': None,
                               u'test_code': u'PLT',
                               u'test_name': u'Platelet count',
                               u'units': u'x10^9/L',
                               u'value_type': u'NM'
                           }, {
                               u'comments': None,
                               u'observation_value': u'10.0',
                               u'reference_range': u'7-13',
                               u'result_status': None,
                               u'test_code': u'MPVU',
                               u'test_name': u'MPV',
                               u'units': u'fL',
                               u'value_type': u'NM'
                           }])

        result = Result()
        result.update_from_dict(result_args, self.user)

        found_result = Result.objects.get()
        self.assertEqual(found_result.lab_number, "234324")
        self.assertEqual(found_result.profile_code, "2343344")

        back_to_dict = found_result.to_dict(self.user)
        del back_to_dict["updated"]
        del back_to_dict["updated_by_id"]
        del back_to_dict["created"]
        del back_to_dict["created_by_id"]
        del back_to_dict["consistency_token"]
        del back_to_dict["id"]
        result_args["request_datetime"] = datetime.datetime(2016,
                                                            1,
                                                            2,
                                                            tzinfo=pytz.UTC)
        result_args["observation_datetime"] = datetime.datetime(
            2016, 1, 6, tzinfo=pytz.UTC)
        result_args["last_edited"] = datetime.datetime(2016,
                                                       1,
                                                       7,
                                                       tzinfo=pytz.UTC)

        self.assertEqual(result_args, back_to_dict)