Skip to content

Commit

Permalink
test: update patient birth date and adjust age calculation in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dermatologist committed Jan 25, 2025
1 parent 3996f4d commit 408fbbb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/resources/flattenfhir/patient.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
}
],
"gender": "male",
"birthDate": "1974-12-25",
"birthDate": "1974-01-01",
"_birthDate": {
"extension": [
{
Expand Down
59 changes: 47 additions & 12 deletions tests/test_flattenfhir.py
Original file line number Diff line number Diff line change
@@ -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. "
assert flatten_fhir.flattened == "Xray report: Normal chest x-ray was created. "

0 comments on commit 408fbbb

Please sign in to comment.