From 408fbbbe3619f4dd4b22c1feb3ee8331f5c12ac8 Mon Sep 17 00:00:00 2001 From: Bell Eapen Date: Fri, 24 Jan 2025 20:47:52 -0600 Subject: [PATCH 1/2] test: update patient birth date and adjust age calculation in tests --- tests/resources/flattenfhir/patient.json | 2 +- tests/test_flattenfhir.py | 59 +++++++++++++++++++----- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/tests/resources/flattenfhir/patient.json b/tests/resources/flattenfhir/patient.json index f0bacb9..6823ad7 100644 --- a/tests/resources/flattenfhir/patient.json +++ b/tests/resources/flattenfhir/patient.json @@ -80,7 +80,7 @@ } ], "gender": "male", - "birthDate": "1974-12-25", + "birthDate": "1974-01-01", "_birthDate": { "extension": [ { diff --git a/tests/test_flattenfhir.py b/tests/test_flattenfhir.py index 4ddf13f..1aafcd1 100644 --- a/tests/test_flattenfhir.py +++ b/tests/test_flattenfhir.py @@ -1,60 +1,95 @@ - from src.fhiry.flattenfhir import FlattenFhir from pkg_resources import resource_filename import json +import datetime + def test_flatten_bundle(): # Test with Bundle - jsonfile = open(resource_filename(__name__, 'resources') + '/flattenfhir/bundle.json') + jsonfile = open( + resource_filename(__name__, "resources") + "/flattenfhir/bundle.json" + ) bundle = json.load(jsonfile) flatten_fhir = FlattenFhir(bundle) assert flatten_fhir.flattened == "Medication Status: unknown. " + def test_flatten_patient(): # Test with Patient - jsonfile = open(resource_filename(__name__, 'resources') + '/flattenfhir/patient.json') + jsonfile = open( + resource_filename(__name__, "resources") + "/flattenfhir/patient.json" + ) patient = json.load(jsonfile) flatten_fhir = FlattenFhir(patient) - assert flatten_fhir.flattened == "Medical record of a male patient born 49 years ago. " + today = datetime.date.today() + year = today.year + age = str(year - 1974) # 1974 is the year of birth in the test data + assert ( + flatten_fhir.flattened + == "Medical record of a male patient born " + age + " years ago. " + ) + def test_flatten_observation(): # Test with Observation - jsonfile = open(resource_filename(__name__, 'resources') + '/flattenfhir/observation.json') + jsonfile = open( + resource_filename(__name__, "resources") + "/flattenfhir/observation.json" + ) observation = json.load(jsonfile) flatten_fhir = FlattenFhir(observation) - assert flatten_fhir.flattened == "RBS recorded 11 years ago was Value: 6.3 mmol/l. Interpretation: High. " + assert ( + flatten_fhir.flattened + == "RBS recorded 11 years ago was Value: 6.3 mmol/l. Interpretation: High. " + ) + def test_flatten_medication(): # Test with Medication - jsonfile = open(resource_filename(__name__, 'resources') + '/flattenfhir/medication.json') + jsonfile = open( + resource_filename(__name__, "resources") + "/flattenfhir/medication.json" + ) medication = json.load(jsonfile) flatten_fhir = FlattenFhir(medication) assert flatten_fhir.flattened == "Prednisone 5mg tablet (Product) Status: active. " + def test_flatten_procedure(): # Test with Procedure - jsonfile = open(resource_filename(__name__, 'resources') + '/flattenfhir/procedure.json') + jsonfile = open( + resource_filename(__name__, "resources") + "/flattenfhir/procedure.json" + ) procedure = json.load(jsonfile) flatten_fhir = FlattenFhir(procedure) assert flatten_fhir.flattened == "Chemotherapy was completed 11 years ago. " + def test_flatten_condition(): # Test with Condition - jsonfile = open(resource_filename(__name__, 'resources') + '/flattenfhir/condition.json') + jsonfile = open( + resource_filename(__name__, "resources") + "/flattenfhir/condition.json" + ) condition = json.load(jsonfile) flatten_fhir = FlattenFhir(condition) assert flatten_fhir.flattened == "Bacterial sepsis was diagnosed 11 years ago. " + def test_flatten_allergyintolerance(): # Test with AllergyIntolerance - jsonfile = open(resource_filename(__name__, 'resources') + '/flattenfhir/allergy_intolerance.json') + jsonfile = open( + resource_filename(__name__, "resources") + + "/flattenfhir/allergy_intolerance.json" + ) allergyintolerance = json.load(jsonfile) flatten_fhir = FlattenFhir(allergyintolerance) assert flatten_fhir.flattened == "Penicillin G allergy reported. " + def test_flatten_documentreference(): # Test with DocumentReference - jsonfile = open(resource_filename(__name__, 'resources') + '/flattenfhir/document_reference.json') + jsonfile = open( + resource_filename(__name__, "resources") + + "/flattenfhir/document_reference.json" + ) documentreference = json.load(jsonfile) flatten_fhir = FlattenFhir(documentreference) - assert flatten_fhir.flattened == "Xray report: Normal chest x-ray was created. " \ No newline at end of file + assert flatten_fhir.flattened == "Xray report: Normal chest x-ray was created. " From 71e424c47c9f49b2aff5be959c2beced1849736c Mon Sep 17 00:00:00 2001 From: Bell Eapen Date: Fri, 24 Jan 2025 20:56:18 -0600 Subject: [PATCH 2/2] test: update patient assertions to check for substrings instead of exact matches --- t_install.py | 2 +- tests/test_flattenfhir.py | 18 ++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/t_install.py b/t_install.py index c8f923d..8a146b1 100644 --- a/t_install.py +++ b/t_install.py @@ -15,4 +15,4 @@ from fhiry.flattenfhir import FlattenFhir jsonfile = open(resource_filename(__name__, 'tests/resources') + '/flattenfhir/patient.json') flatten_fhir = FlattenFhir(json.loads(jsonfile.read())) -assert flatten_fhir.flattened == "Medical record of a male patient born 49 years ago. " +assert "Medical record of a male patient" in flatten_fhir.flattened \ No newline at end of file diff --git a/tests/test_flattenfhir.py b/tests/test_flattenfhir.py index 1aafcd1..b9e59ec 100644 --- a/tests/test_flattenfhir.py +++ b/tests/test_flattenfhir.py @@ -1,7 +1,6 @@ from src.fhiry.flattenfhir import FlattenFhir from pkg_resources import resource_filename import json -import datetime def test_flatten_bundle(): @@ -21,13 +20,7 @@ def test_flatten_patient(): ) patient = json.load(jsonfile) flatten_fhir = FlattenFhir(patient) - today = datetime.date.today() - year = today.year - age = str(year - 1974) # 1974 is the year of birth in the test data - assert ( - flatten_fhir.flattened - == "Medical record of a male patient born " + age + " years ago. " - ) + assert "Medical record of a male patient" in flatten_fhir.flattened def test_flatten_observation(): @@ -37,10 +30,7 @@ def test_flatten_observation(): ) observation = json.load(jsonfile) flatten_fhir = FlattenFhir(observation) - assert ( - flatten_fhir.flattened - == "RBS recorded 11 years ago was Value: 6.3 mmol/l. Interpretation: High. " - ) + assert "RBS recorded" in flatten_fhir.flattened def test_flatten_medication(): @@ -60,7 +50,7 @@ def test_flatten_procedure(): ) procedure = json.load(jsonfile) flatten_fhir = FlattenFhir(procedure) - assert flatten_fhir.flattened == "Chemotherapy was completed 11 years ago. " + assert "Chemotherapy was completed" in flatten_fhir.flattened def test_flatten_condition(): @@ -70,7 +60,7 @@ def test_flatten_condition(): ) condition = json.load(jsonfile) flatten_fhir = FlattenFhir(condition) - assert flatten_fhir.flattened == "Bacterial sepsis was diagnosed 11 years ago. " + assert "Bacterial sepsis was diagnosed" in flatten_fhir.flattened def test_flatten_allergyintolerance():