Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft attempt at ingestion using mapping file #24

Merged
merged 21 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b7f0848
Draft attempt at ingestion using mapping file
pipliggins May 8, 2024
dd61500
Ignore duplicate keys if values are the same
pipliggins May 13, 2024
a80c963
Improve single row 1:1 test without output comparison
pipliggins May 13, 2024
7a456ed
Multiple rows of encounter can be read in & out
pipliggins May 14, 2024
21e777b
Draft one-to-many conversion for observation
pipliggins May 14, 2024
cfadee9
Update overwritten cleanup() func in remaining classes
pipliggins May 15, 2024
b591be9
Start condensing ingestion code
pipliggins May 15, 2024
c142643
Create generic data conversion function for users
pipliggins May 15, 2024
6f9f4ad
Remove load_data functions
pipliggins May 15, 2024
e352003
Make fhirflat installable
pipliggins May 15, 2024
464dd67
Allow mappings from google sheets
pipliggins May 15, 2024
a49d78b
Update test workflow for package
pipliggins May 15, 2024
de6c177
Allow lists to be created during ingestion.
pipliggins May 17, 2024
234fd09
Improve references
pipliggins May 20, 2024
c524efe
Add race extension
pipliggins May 20, 2024
9fa116f
Misc fixes, add presenceAbsence and prespecifiedQuery extensions
pipliggins May 20, 2024
60e943b
Misc updates, now passes private checks on dengue data subset
pipliggins May 22, 2024
9bf774c
Fix some typehinting errors
pipliggins May 22, 2024
dd4afe9
Update init file
pipliggins May 22, 2024
bef7c35
Update some relative imports and fix different types test warning
pipliggins May 22, 2024
08eda15
Fix more types
pipliggins May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fhirflat/flat2fhir.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create_codeable_concept(
"""Re-creates a codeableConcept structure from the FHIRflat representation."""

# for reading in from ingestion pipeline
if (name + ".code" and name + ".system") in old_dict:
if name + ".code" in old_dict and name + ".system" in old_dict:
code = old_dict[name + ".code"]
if isinstance(code, list) and len(code) > 1:
new_dict = {"coding": []}
Expand Down
4 changes: 4 additions & 0 deletions fhirflat/resources/extension_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ class birthSexType(AbstractType):
__resource_type__ = "birthSex"


class raceType(AbstractType):
__resource_type__ = "Race"


class dateTimeExtensionType(AbstractType):
__resource_type__ = "dateTimeExtension"
5 changes: 5 additions & 0 deletions fhirflat/resources/extension_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(self):
"Duration": (None, ".extensions"),
"Age": (None, ".extensions"),
"birthSex": (None, ".extensions"),
"Race": (None, ".extensions"),
"dateTimeExtension": (None, ".extensions"),
}

Expand Down Expand Up @@ -230,5 +231,9 @@ def birthsex_validator(v: Union[StrBytes, dict, Path, FHIRAbstractModel]):
return Validators().fhir_model_validator("birthSex", v)


def race_validator(v: Union[StrBytes, dict, Path, FHIRAbstractModel]):
return Validators().fhir_model_validator("Race", v)


def datetimeextension_validator(v: Union[StrBytes, dict, Path, FHIRAbstractModel]):
return Validators().fhir_model_validator("dateTimeExtension", v)
36 changes: 36 additions & 0 deletions fhirflat/resources/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,42 @@ def elements_sequence(cls):
]


class Race(_DataType):
"""
An ISARIC extension collecting data on the race of a patient.
"""

resource_type = Field("Race", const=True)
abhidg marked this conversation as resolved.
Show resolved Hide resolved

url = Field("race", const=True, alias="url")

valueCodeableConcept: fhirtypes.CodeableConceptType = Field(
None,
alias="valueCodeableConcept",
title="Value of extension",
description=(
"Value of extension - must be one of a constrained set of the data "
"types (see [Extensibility](extensibility.html) for a list)."
),
# if property is element of this resource.
element_property=True,
element_required=True,
)

@classmethod
def elements_sequence(cls):
"""returning all elements names from
``Extension`` according specification,
with preserving original sequence order.
"""
return [
"id",
"extension",
"url",
"valueCodeableConcept",
]


# ------------------- extension types ------------------------------


Expand Down
34 changes: 17 additions & 17 deletions fhirflat/resources/patient.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from fhir.resources.patient import Patient
from .base import FHIRFlatBase
from .extension_types import (
ageType,
birthSexType,
)
from .extensions import Age, birthSex
from .extension_types import ageType, birthSexType, raceType
from .extensions import Age, birthSex, Race
import orjson

from ..flat2fhir import expand_concepts
Expand All @@ -16,18 +13,20 @@


class Patient(Patient, FHIRFlatBase):
extension: list[Union[ageType, birthSexType, fhirtypes.ExtensionType]] = Field(
None,
alias="extension",
title="Additional content defined by implementations",
description=(
"""
extension: list[Union[ageType, birthSexType, raceType, fhirtypes.ExtensionType]] = (
Field(
None,
alias="extension",
title="Additional content defined by implementations",
description=(
"""
Contains the G.H 'age' and 'birthSex' extensions,
and allows extensions from other implementations to be included."""
),
# if property is element of this resource.
element_property=True,
union_mode="smart",
),
# if property is element of this resource.
element_property=True,
union_mode="smart",
)
)

# attributes to exclude from the flat representation
Expand All @@ -47,9 +46,10 @@ class Patient(Patient, FHIRFlatBase):
def validate_extension_contents(cls, extensions):
age_count = sum(isinstance(item, Age) for item in extensions)
birthsex_count = sum(isinstance(item, birthSex) for item in extensions)
race_count = sum(isinstance(item, Race) for item in extensions)

if age_count > 1 or birthsex_count > 1:
raise ValueError("Age and birthSex can only appear once.")
if age_count > 1 or birthsex_count > 1 or race_count > 1:
raise ValueError("Age, birthSex and Race can only appear once.")

return extensions

Expand Down
Loading