Skip to content

Commit

Permalink
Merge pull request #198 from dermatologist/feature/fix-age-1
Browse files Browse the repository at this point in the history
test: update patient birth date and adjust age calculation in tests
  • Loading branch information
dermatologist authored Jan 25, 2025
2 parents 3996f4d + 71e424c commit 951d206
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion t_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
53 changes: 39 additions & 14 deletions tests/test_flattenfhir.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,85 @@

from src.fhiry.flattenfhir import FlattenFhir
from pkg_resources import resource_filename
import json


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. "
assert "Medical record of a male patient" in flatten_fhir.flattened


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 "RBS recorded" in flatten_fhir.flattened


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. "
assert "Chemotherapy was completed" in flatten_fhir.flattened


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. "
assert "Bacterial sepsis was diagnosed" in flatten_fhir.flattened


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 951d206

Please sign in to comment.