Skip to content

Commit

Permalink
Add tests for explode_and_flatten
Browse files Browse the repository at this point in the history
  • Loading branch information
pipliggins committed Mar 11, 2024
1 parent f60f819 commit 20ec796
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
24 changes: 12 additions & 12 deletions tests/test_encounter_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@
],
"appointment": [{"reference": "Appointment/example"}],
"actualPeriod": {"start": "2013-03-11", "end": "2013-03-20"},
# "reason": [
# {
# "value": [
# {
# "concept": {
# "text": "The patient seems to suffer from bilateral pneumonia and renal insufficiency, most likely due to chemotherapy." # noqa: E501
# }
# }
# ]
# }
# ],
"reason": [
{
"value": [
{
"concept": {
"text": "The patient seems to suffer from bilateral pneumonia and renal insufficiency, most likely due to chemotherapy." # noqa: E501
}
}
]
}
],
# "diagnosis": [
# {
# "condition": [{"reference": {"reference": "Condition/stroke"}}],
Expand Down Expand Up @@ -161,14 +161,14 @@
"type.text": "Inpatient stay for nine days",
"episodeOfCare": "EpisodeOfCare/example",
"basedOn": "ServiceRequest/myringotomy",
"reason.value.concept.text": "The patient seems to suffer from bilateral pneumonia and renal insufficiency, most likely due to chemotherapy.", # noqa: E501
"priority.code": "http://snomed.info/sct|394849002",
"priority.text": "High priority",
"subject": "Patient/f201",
"partOf": "Encounter/f203",
"serviceProvider": "Organization/2",
"actualPeriod.start": datetime.date(2013, 3, 11),
"actualPeriod.end": datetime.date(2013, 3, 20),
# "reason.value.concept.text": "The patient seems to suffer from bilateral pneumonia and renal insufficiency, most likely due to chemotherapy.", # noqa: E501
# diagnosis.condition: ["Condition/stroke", "Condition/f201"],
# diagnosis.use.code: ["http://terminology.hl7.org/CodeSystem/diagnosis-role|AD", "http://terminology.hl7.org/CodeSystem/diagnosis-role|DD"], # noqa: E501
"admission.origin": "Location/2",
Expand Down
31 changes: 31 additions & 0 deletions tests/test_fhir2flat_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,37 @@ def test_flatten_column(data, expected):
pd.testing.assert_frame_equal(result, expected)


@pytest.mark.parametrize(
"data_lists, expected",
[
(
(
{
"reason": [
[{"value": [{"concept": {"text": "bilateral pneumonia."}}]}]
],
},
["reason"],
),
{
"reason.value.concept.text": ["bilateral pneumonia."],
},
)
],
)
def test_explode_and_flatten_no_multiples(data_lists, expected):
# Create a mock DataFrame
data, lists = data_lists
df = pd.DataFrame(data, index=[0])

# Call the function
result = f2f.explode_and_flatten(df, lists)

# Check the result
expected = pd.DataFrame(expected)
pd.testing.assert_frame_equal(result, expected)


@pytest.mark.parametrize(
"data, expected",
[
Expand Down
2 changes: 0 additions & 2 deletions tests/test_patient_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import os
from fhirflat.resources.patient import Patient

# Test Patient --------------------------------------------

PATIENT_DICT_INPUT = {
"id": "f001",
"active": True,
Expand Down

0 comments on commit 20ec796

Please sign in to comment.