from django.test import TestCase from access_core.clinical.models import ( ClinicalObservation, LabResult, LabResultItem, LoincCode, UCUMUnit, ) from access_core.identity.models import Beneficiary from access_core.intake.models import IntakeRecord from access_core.monitoring.models import CarePeriod, ClinicalTrack class LoincCodeTest(TestCase): def test_create_loinc(self): code = LoincCode.objects.create( loinc_number="2345-7", component="Glucose", common_name="Blood Glucose", property="Mass Concentration", system="Serum/Plasma", ) self.assertEqual(code.loinc_number, "2345-7") self.assertEqual(str(code), "2345-7 - Glucose") class UCUMUnitTest(TestCase): def test_create_unit(self): unit = UCUMUnit.objects.create( ucum_code="mg/dL", description="Milligrams per deciliter" ) self.assertEqual(unit.ucum_code, "mg/dL") class ClinicalObservationTest(TestCase): @classmethod def setUpTestData(cls): cls.track = ClinicalTrack.objects.create(track_name="CKM") cls.intake = IntakeRecord.objects.create( external_form_id="synth-obs-001", first_name="Test", last_name="User", dob="1960-01-01", sex="female", is_synthetic=True, ) cls.beneficiary = Beneficiary.objects.create( intake_record=cls.intake, first_name="Test", last_name="User", dob="1960-01-01", sex="female", is_synthetic=True, ) cls.care_period = CarePeriod.objects.create( beneficiary=cls.beneficiary, clinical_track=cls.track, start_date="2026-01-01", ) cls.loinc = LoincCode.objects.create( loinc_number="2345-7", component="Glucose", ) def test_create_observation(self): obs = ClinicalObservation.objects.create( beneficiary=self.beneficiary, care_period=self.care_period, observation_type="lab", measure_name="Fasting Glucose", loinc_code=self.loinc, value_numeric=110, unit="mg/dL", ucum_unit="mg/dL", collection_date="2026-07-01", data_source="labcorp", is_synthetic=True, status="approved", ) self.assertEqual(obs.value_numeric, 110) self.assertEqual(obs.status, "approved") self.assertTrue(obs.is_synthetic) class LabResultTest(TestCase): def test_create_lab_result(self): intake = IntakeRecord.objects.create( external_form_id="synth-lab-001", first_name="Lab", last_name="Patient", dob="1955-01-01", sex="male", is_synthetic=True, ) ben = Beneficiary.objects.create( intake_record=intake, first_name="Lab", last_name="Patient", dob="1955-01-01", sex="male", is_synthetic=True, ) lab = LabResult.objects.create( beneficiary=ben, result_date="2026-07-01", lab_facility="Quest", source_type="structured_feed", is_synthetic=True, ) item = LabResultItem.objects.create( lab_result=lab, test_name="Glucose", value=95.0, unit="mg/dL", status="approved", ) self.assertEqual(item.value, 95.0)