From c4e5ea21a44e79b0736a892d83e61c6caf3be07c Mon Sep 17 00:00:00 2001 From: Adam Kells Date: Tue, 21 Jan 2025 10:25:58 +0000 Subject: [PATCH 1/2] first pass at transition to fhir.resources --- healthchain/data_generators/basegenerators.py | 11 +++-- .../data_generators/conditiongenerators.py | 28 +++++++----- poetry.lock | 43 ++++++++++++++++++- pyproject.toml | 1 + .../test_condition_generators.py | 13 +++--- 5 files changed, 72 insertions(+), 24 deletions(-) diff --git a/healthchain/data_generators/basegenerators.py b/healthchain/data_generators/basegenerators.py index 8470f9e1..897744c2 100644 --- a/healthchain/data_generators/basegenerators.py +++ b/healthchain/data_generators/basegenerators.py @@ -23,10 +23,13 @@ urlModel, uuidModel, ) -from healthchain.fhir_resources.generalpurpose import ( - CodeableConcept, - Coding, -) + +# from healthchain.fhir_resources.generalpurpose import ( +# CodeableConcept, +# Coding, +# ) +from fhir.resources.codeableconcept import CodeableConcept +from fhir.resources.coding import Coding faker = Faker() diff --git a/healthchain/data_generators/conditiongenerators.py b/healthchain/data_generators/conditiongenerators.py index 1b4bc5ae..de67edcc 100644 --- a/healthchain/data_generators/conditiongenerators.py +++ b/healthchain/data_generators/conditiongenerators.py @@ -7,16 +7,23 @@ register_generator, CodeableConceptGenerator, ) -from healthchain.fhir_resources.generalpurpose import ( - CodeableConcept, - Coding, - Reference, -) -from healthchain.fhir_resources.condition import ( - Condition, - ConditionStage, - ConditionParticipant, -) + +# from healthchain.fhir_resources.generalpurpose import ( +# CodeableConcept, +# Coding, +# Reference, +# ) +from fhir.resources.codeableconcept import CodeableConcept +from fhir.resources.coding import Coding +from fhir.resources.reference import Reference + +# from healthchain.fhir_resources.condition import ( +# Condition, +# ConditionStage, +# ConditionParticipant, +# ) +from fhir.resources.condition import Condition, ConditionStage, ConditionParticipant + from healthchain.data_generators.value_sets.conditioncodes import ( ConditionCodeSimple, ConditionCodeComplex, @@ -156,7 +163,6 @@ def generate( constraints=constraints ) return Condition( - resourceType="Condition", id=generator_registry.get("IdGenerator").generate(), clinicalStatus=generator_registry.get("ClinicalStatusGenerator").generate(), verificationStatus=generator_registry.get( diff --git a/poetry.lock b/poetry.lock index 225de705..c4313f63 100644 --- a/poetry.lock +++ b/poetry.lock @@ -633,6 +633,45 @@ typing-extensions = ">=4.8.0" all = ["email-validator (>=2.0.0)", "fastapi-cli[standard] (>=0.0.5)", "httpx (>=0.23.0)", "itsdangerous (>=1.1.0)", "jinja2 (>=2.11.2)", "orjson (>=3.2.1)", "pydantic-extra-types (>=2.0.0)", "pydantic-settings (>=2.0.0)", "python-multipart (>=0.0.7)", "pyyaml (>=5.3.1)", "ujson (>=4.0.1,!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0)", "uvicorn[standard] (>=0.12.0)"] standard = ["email-validator (>=2.0.0)", "fastapi-cli[standard] (>=0.0.5)", "httpx (>=0.23.0)", "jinja2 (>=2.11.2)", "python-multipart (>=0.0.7)", "uvicorn[standard] (>=0.12.0)"] +[[package]] +name = "fhir-core" +version = "1.0.0" +description = "FHIR Core library" +optional = false +python-versions = ">=3.8" +files = [ + {file = "fhir_core-1.0.0-py2.py3-none-any.whl", hash = "sha256:8f58015563dd1ebc2dcc2185197ed269b1a2d68f098d0fd617e2dd4e16cb2376"}, + {file = "fhir_core-1.0.0.tar.gz", hash = "sha256:654cd30eeffcd49212097e6a2abb590f0b9d33dac36bf39b1518bbd0841c0f2c"}, +] + +[package.dependencies] +pydantic = ">=2.7.4,<3.0" + +[package.extras] +dev = ["Jinja2 (==2.11.1)", "MarkupSafe (==1.1.1)", "PyYAML (>=6.0.1)", "black", "certifi", "colorlog (==2.10.0)", "coverage", "fhirspec", "flake8 (==6.0)", "flake8-bugbear (>=22.12.6)", "flake8-isort (>=6.0.0)", "importlib-metadata (>=5.2.0)", "isort (>=5.11.4)", "lxml", "mypy", "pytest (>5.4.0)", "pytest-cov (>=2.10.0)", "requests (==2.23.0)", "setuptools (==65.6.3)", "types-PyYAML", "types-requests", "types-simplejson", "zest-releaser[recommended]"] +test = ["PyYAML (>=6.0.1)", "black", "coverage", "flake8 (==6.0)", "flake8-bugbear (>=22.12.6)", "flake8-isort (>=6.0.0)", "importlib-metadata (>=5.2.0)", "isort (>=5.11.4)", "lxml", "mypy", "pytest (>5.4.0)", "pytest-cov (>=2.10.0)", "pytest-runner", "requests (==2.23.0)", "setuptools (==65.6.3)", "types-PyYAML", "types-requests", "types-simplejson"] + +[[package]] +name = "fhir-resources" +version = "8.0.0" +description = "FHIR Resources as Model Class" +optional = false +python-versions = ">=3.8" +files = [ + {file = "fhir.resources-8.0.0-py2.py3-none-any.whl", hash = "sha256:9c46d6d79c6d6629c3bea6f244bcc6e8e0e4d15757a675f19d9d1c05c9ab2199"}, + {file = "fhir.resources-8.0.0.tar.gz", hash = "sha256:84dac3af31eaf90d5b0386cac21d26c50e6fb1526d68b88a2c42d112978e9cf9"}, +] + +[package.dependencies] +fhir-core = ">=1.0.0" + +[package.extras] +all = ["PyYAML (>=5.4.1)", "lxml"] +dev = ["Jinja2 (==2.11.1)", "MarkupSafe (==1.1.1)", "black", "certifi", "colorlog (==2.10.0)", "coverage", "fhirspec", "flake8 (==6.0)", "flake8-bugbear (>=22.12.6)", "flake8-isort (>=6.0.0)", "importlib-metadata (>=5.2.0)", "isort (>=5.11.4)", "mypy", "pytest (>5.4.0)", "pytest-cov (>=2.10.0)", "requests (==2.23.0)", "setuptools (==65.6.3)", "typed-ast (>=1.5.4)", "types-PyYAML", "types-requests", "types-simplejson", "zest-releaser[recommended]"] +test = ["PyYAML (>=5.4.1)", "black", "coverage", "flake8 (==6.0)", "flake8-bugbear (>=22.12.6)", "flake8-isort (>=6.0.0)", "importlib-metadata (>=5.2.0)", "isort (>=5.11.4)", "lxml", "mypy", "pytest (>5.4.0)", "pytest-cov (>=2.10.0)", "pytest-runner", "requests (==2.23.0)", "setuptools (==65.6.3)", "typed-ast (>=1.5.4)", "types-PyYAML", "types-requests", "types-simplejson"] +xml = ["lxml"] +yaml = ["PyYAML (>=5.4.1)"] + [[package]] name = "filelock" version = "3.16.1" @@ -1698,8 +1737,8 @@ files = [ [package.dependencies] numpy = [ {version = ">=1.20.3", markers = "python_version < \"3.10\""}, - {version = ">=1.21.0", markers = "python_version >= \"3.10\" and python_version < \"3.11\""}, {version = ">=1.23.2", markers = "python_version >= \"3.11\""}, + {version = ">=1.21.0", markers = "python_version >= \"3.10\" and python_version < \"3.11\""}, ] python-dateutil = ">=2.8.2" pytz = ">=2020.1" @@ -3353,4 +3392,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = ">=3.8,<3.12" -content-hash = "555c8932c3b2be4327a1f01ff3dbe418085a30c9ed5c0891f27c006827fd4ba0" +content-hash = "f317cb685fbe5ee37470f03beeaca699601a5bb5029bcc359e76d2939dc6668c" diff --git a/pyproject.toml b/pyproject.toml index fd5604d8..19b9c127 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,7 @@ spyne = "^2.14.0" lxml = "^5.2.2" xmltodict = "^0.13.0" +fhir-resources = "^8.0.0" [tool.poetry.group.dev.dependencies] ruff = "^0.4.2" pytest = "^8.2.0" diff --git a/tests/generators_tests/test_condition_generators.py b/tests/generators_tests/test_condition_generators.py index 3c9db9f3..3794ab2f 100644 --- a/tests/generators_tests/test_condition_generators.py +++ b/tests/generators_tests/test_condition_generators.py @@ -13,10 +13,10 @@ def test_ClinicalStatusGenerator(): clinical_status = ClinicalStatusGenerator.generate() assert ( - clinical_status.coding_field[0].system_field + clinical_status.coding[0].system == "http://terminology.hl7.org/CodeSystem/condition-clinical" ) - assert clinical_status.coding_field[0].code_field in ( + assert clinical_status.coding[0].code in ( "active", "recurrence", "inactive", @@ -27,10 +27,10 @@ def test_ClinicalStatusGenerator(): def test_VerificationStatusGenerator(): verification_status = VerificationStatusGenerator.generate() assert ( - verification_status.coding_field[0].system_field + verification_status.coding[0].system == "http://terminology.hl7.org/CodeSystem/condition-ver-status" ) - assert verification_status.coding_field[0].code_field in ( + assert verification_status.coding[0].code in ( "provisional", "confirmed", ) @@ -38,15 +38,14 @@ def test_VerificationStatusGenerator(): def test_CategoryGenerator(): category = CategoryGenerator.generate() - assert category.coding_field[0].system_field == "http://snomed.info/sct" - assert category.coding_field[0].code_field in ("55607006", "404684003") + assert category.coding[0].system == "http://snomed.info/sct" + assert category.coding[0].code in ("55607006", "404684003") def test_ConditionGenerator(): condition_model = ConditionGenerator.generate("Patient/456", "Encounter/789") value_set = [x.code for x in ConditionCodeSimple().value_set] value_set.extend([x.code for x in ConditionCodeComplex().value_set]) - assert condition_model.resourceType == "Condition" assert condition_model.subject_field.reference_field == "Patient/456" assert condition_model.encounter_field.reference_field == "Encounter/789" assert condition_model.id_field is not None From cc6efa972cb455bd4b6b33a759482695f03272ed Mon Sep 17 00:00:00 2001 From: Adam Kells Date: Wed, 22 Jan 2025 19:51:42 +0000 Subject: [PATCH 2/2] remove fhir resources --- healthchain/data_generators/basegenerators.py | 64 +- .../data_generators/cdsdatagenerator.py | 6 +- .../data_generators/conditiongenerators.py | 10 - .../data_generators/encountergenerators.py | 45 +- .../medicationadministrationgenerators.py | 20 +- .../medicationrequestgenerators.py | 19 +- .../data_generators/patientgenerators.py | 95 ++- .../data_generators/practitionergenerators.py | 52 +- .../data_generators/proceduregenerators.py | 5 +- healthchain/fhir_resources/__init__.py | 21 - healthchain/fhir_resources/bundleresources.py | 78 --- healthchain/fhir_resources/condition.py | 238 ------- .../fhir_resources/documentreference.py | 293 -------- healthchain/fhir_resources/encounter.py | 367 ---------- healthchain/fhir_resources/generalpurpose.py | 651 ------------------ .../medicationadministration.py | 260 ------- .../fhir_resources/medicationrequest.py | 353 ---------- healthchain/fhir_resources/patient.py | 378 ---------- healthchain/fhir_resources/practitioner.py | 177 ----- healthchain/fhir_resources/primitives.py | 38 - healthchain/fhir_resources/procedure.py | 289 -------- .../fhir_resources/resourceregistry.py | 167 ----- healthchain/models/data/cdsfhirdata.py | 2 +- tests/conftest.py | 6 +- .../test_fhir_resources_base.py | 59 -- .../test_fhir_resources_bundle.py | 15 - .../test_fhir_resources_patient.py | 79 --- .../test_fhir_resources_practitioner.py | 45 -- .../test_condition_generators.py | 14 +- .../test_encounter_generators.py | 19 +- ...st_medication_administration_generators.py | 8 +- .../test_medication_request_generators.py | 8 +- .../test_patient_generators.py | 5 +- .../test_practitioner_generators.py | 39 +- .../test_procedure_generators.py | 7 +- 35 files changed, 164 insertions(+), 3768 deletions(-) delete mode 100644 healthchain/fhir_resources/__init__.py delete mode 100644 healthchain/fhir_resources/bundleresources.py delete mode 100644 healthchain/fhir_resources/condition.py delete mode 100644 healthchain/fhir_resources/documentreference.py delete mode 100644 healthchain/fhir_resources/encounter.py delete mode 100644 healthchain/fhir_resources/generalpurpose.py delete mode 100644 healthchain/fhir_resources/medicationadministration.py delete mode 100644 healthchain/fhir_resources/medicationrequest.py delete mode 100644 healthchain/fhir_resources/patient.py delete mode 100644 healthchain/fhir_resources/practitioner.py delete mode 100644 healthchain/fhir_resources/primitives.py delete mode 100644 healthchain/fhir_resources/procedure.py delete mode 100644 healthchain/fhir_resources/resourceregistry.py delete mode 100644 tests/fhir_resources_unit_tests/test_fhir_resources_base.py delete mode 100644 tests/fhir_resources_unit_tests/test_fhir_resources_bundle.py delete mode 100644 tests/fhir_resources_unit_tests/test_fhir_resources_patient.py delete mode 100644 tests/fhir_resources_unit_tests/test_fhir_resources_practitioner.py diff --git a/healthchain/data_generators/basegenerators.py b/healthchain/data_generators/basegenerators.py index 897744c2..5918ac9b 100644 --- a/healthchain/data_generators/basegenerators.py +++ b/healthchain/data_generators/basegenerators.py @@ -4,30 +4,8 @@ import string from faker import Faker -from healthchain.fhir_resources.primitives import ( - booleanModel, - canonicalModel, - codeModel, - dateModel, - dateTimeModel, - decimalModel, - idModel, - instantModel, - integerModel, - markdownModel, - positiveIntModel, - stringModel, - timeModel, - unsignedIntModel, - uriModel, - urlModel, - uuidModel, -) - -# from healthchain.fhir_resources.generalpurpose import ( -# CodeableConcept, -# Coding, -# ) + + from fhir.resources.codeableconcept import CodeableConcept from fhir.resources.coding import Coding @@ -68,14 +46,14 @@ def generate(): class BooleanGenerator(BaseGenerator): @staticmethod def generate(): - return booleanModel(random.choice(["true", "false"])) + return random.choice([True, False]) @register_generator class CanonicalGenerator(BaseGenerator): @staticmethod def generate(): - return canonicalModel(f"https://example/{faker.uri_path()}") + return f"https://example/{faker.uri_path()}" @register_generator @@ -83,107 +61,105 @@ class CodeGenerator(BaseGenerator): # TODO: Codes can technically have whitespace but here I've left it out for simplicity @staticmethod def generate(): - return codeModel( - "".join(random.choices(string.ascii_uppercase + string.digits, k=6)) - ) + return "".join(random.choices(string.ascii_uppercase + string.digits, k=6)) @register_generator class DateGenerator(BaseGenerator): @staticmethod def generate(): - return dateModel(faker.date()) + return faker.date() @register_generator class DateTimeGenerator(BaseGenerator): @staticmethod def generate(): - return dateTimeModel(faker.date_time().isoformat()) + return faker.date_time().isoformat() @register_generator class DecimalGenerator(BaseGenerator): @staticmethod def generate(): - return decimalModel(faker.random_number()) + return faker.random_number() @register_generator class IdGenerator(BaseGenerator): @staticmethod def generate(): - return idModel(faker.uuid4()) + return faker.uuid4() @register_generator class InstantGenerator(BaseGenerator): @staticmethod def generate(): - return instantModel(faker.date_time().isoformat()) + return faker.date_time().isoformat() @register_generator class IntegerGenerator(BaseGenerator): @staticmethod def generate(): - return integerModel(faker.random_int()) + return faker.random_int() @register_generator class MarkdownGenerator(BaseGenerator): @staticmethod def generate(): - return markdownModel(faker.text()) + return faker.text() @register_generator class PositiveIntGenerator(BaseGenerator): @staticmethod def generate(): - return positiveIntModel(faker.random_int(min=1)) + return faker.random_int(min=1) @register_generator class StringGenerator(BaseGenerator): @staticmethod def generate(): - return stringModel(faker.word()) + return faker.word() @register_generator class TimeGenerator(BaseGenerator): @staticmethod def generate(): - return timeModel(faker.time()) + return faker.time() @register_generator class UnsignedIntGenerator(BaseGenerator): @staticmethod def generate(): - return unsignedIntModel(faker.random_int(min=0)) + return faker.random_int(min=0) @register_generator class UriGenerator(BaseGenerator): @staticmethod def generate(): - return uriModel(f"https://example/{faker.uri_path()}") + return f"https://example/{faker.uri_path()}" @register_generator class UrlGenerator(BaseGenerator): @staticmethod def generate(): - return urlModel(f"https://example/{faker.uri_path()}") + return f"https://example/{faker.uri_path()}" @register_generator class UuidGenerator(BaseGenerator): @staticmethod def generate(): - return uuidModel(faker.uuid4()) + return faker.uuid4() class CodeableConceptGenerator(BaseGenerator): @@ -204,7 +180,7 @@ def generate_from_valueset(ValueSet): system=value_set_instance.system, code=code, display=display, - # extension=[ExtensionModel(value_set_instance.extension)], + # extension=[Extension(value_set_instance.extension)], ) ] ) diff --git a/healthchain/data_generators/cdsdatagenerator.py b/healthchain/data_generators/cdsdatagenerator.py index d471ef17..c4c912d5 100644 --- a/healthchain/data_generators/cdsdatagenerator.py +++ b/healthchain/data_generators/cdsdatagenerator.py @@ -7,10 +7,10 @@ from pathlib import Path from healthchain.base import Workflow -from healthchain.fhir_resources.bundleresources import Bundle, BundleEntry +from fhir.resources.bundle import Bundle, BundleEntry from healthchain.data_generators.basegenerators import generator_registry -from healthchain.fhir_resources.documentreference import DocumentReference -from healthchain.fhir_resources.generalpurpose import Narrative +from fhir.resources.documentreference import DocumentReference +from fhir.resources.narrative import Narrative from healthchain.models.data.cdsfhirdata import CdsFhirData logger = logging.getLogger(__name__) diff --git a/healthchain/data_generators/conditiongenerators.py b/healthchain/data_generators/conditiongenerators.py index de67edcc..67a5b608 100644 --- a/healthchain/data_generators/conditiongenerators.py +++ b/healthchain/data_generators/conditiongenerators.py @@ -8,20 +8,10 @@ CodeableConceptGenerator, ) -# from healthchain.fhir_resources.generalpurpose import ( -# CodeableConcept, -# Coding, -# Reference, -# ) from fhir.resources.codeableconcept import CodeableConcept from fhir.resources.coding import Coding from fhir.resources.reference import Reference -# from healthchain.fhir_resources.condition import ( -# Condition, -# ConditionStage, -# ConditionParticipant, -# ) from fhir.resources.condition import Condition, ConditionStage, ConditionParticipant from healthchain.data_generators.value_sets.conditioncodes import ( diff --git a/healthchain/data_generators/encountergenerators.py b/healthchain/data_generators/encountergenerators.py index 235ebe05..f41f53d4 100644 --- a/healthchain/data_generators/encountergenerators.py +++ b/healthchain/data_generators/encountergenerators.py @@ -1,45 +1,37 @@ from typing import Optional from faker import Faker -from healthchain.fhir_resources.encounter import ( - Encounter, - EncounterLocation, -) -from healthchain.fhir_resources.primitives import dateTimeModel -from healthchain.fhir_resources.generalpurpose import ( - Coding, - CodeableConcept, - Period, - Reference, -) +from fhir.resources.encounter import Encounter, EncounterLocation + +from fhir.resources.coding import Coding +from fhir.resources.codeableconcept import CodeableConcept +from fhir.resources.period import Period +from fhir.resources.reference import Reference from healthchain.data_generators.basegenerators import ( BaseGenerator, generator_registry, register_generator, ) +from datetime import datetime + faker = Faker() @register_generator class PeriodGenerator(BaseGenerator): - """ - A generator class for creating FHIR Period resources. - - Methods: - generate() -> Period: - Generates a FHIR Period resource with random start and end times. - """ - @staticmethod def generate(): - start = faker.date_time() - end = faker.date_time_between(start_date=start).isoformat() - start = start.isoformat() + # Use date_between instead of date() for more control + start = faker.date_between( + start_date="-30y", # You can adjust this range + end_date="today", + ) + end = faker.date_between_dates(date_start=start, date_end=datetime.now()) return Period( - start=dateTimeModel(start), - end=dateTimeModel(end), + start=start, + end=end, ) @@ -155,7 +147,6 @@ def generate( Faker.seed(random_seed) patient_reference = "Patient/123" return Encounter( - resourceType="Encounter", id=generator_registry.get("IdGenerator").generate(), status=faker.random_element( elements=( @@ -166,9 +157,9 @@ def generate( "cancelled", ) ), - class_field=[generator_registry.get("ClassGenerator").generate()], + class_fhir=[generator_registry.get("ClassGenerator").generate()], priority=generator_registry.get("EncounterPriorityGenerator").generate(), - type_field=[generator_registry.get("EncounterTypeGenerator").generate()], + type=[generator_registry.get("EncounterTypeGenerator").generate()], subject={"reference": patient_reference, "display": patient_reference}, actualPeriod=generator_registry.get("PeriodGenerator").generate(), location=[generator_registry.get("EncounterLocationGenerator").generate()], diff --git a/healthchain/data_generators/medicationadministrationgenerators.py b/healthchain/data_generators/medicationadministrationgenerators.py index 8e8b2b1a..dedea1cd 100644 --- a/healthchain/data_generators/medicationadministrationgenerators.py +++ b/healthchain/data_generators/medicationadministrationgenerators.py @@ -1,15 +1,10 @@ from typing import Optional from faker import Faker -from healthchain.fhir_resources.medicationadministration import ( - MedicationAdministration, - MedicationAdministrationDosage, -) -from healthchain.fhir_resources.generalpurpose import ( - Reference, - CodeableReference, -) -from healthchain.fhir_resources.medicationrequest import Medication +from fhir.resources.medicationadministration import MedicationAdministration +from fhir.resources.medicationadministration import MedicationAdministrationDosage +from fhir.resources.reference import Reference +from fhir.resources.codeablereference import CodeableReference from healthchain.data_generators.basegenerators import ( BaseGenerator, generator_registry, @@ -42,16 +37,9 @@ def generate( encounter_reference: str, constraints: Optional[list] = None, ): - contained_medication = Medication( - code=generator_registry.get( - "MedicationRequestContainedGenerator" - ).generate() - ) return MedicationAdministration( - resourceType="MedicationAdministration", id=generator_registry.get("IdGenerator").generate(), status=generator_registry.get("EventStatusGenerator").generate(), - contained=[contained_medication], medication=CodeableReference( reference=Reference(reference="Medication/123") ), diff --git a/healthchain/data_generators/medicationrequestgenerators.py b/healthchain/data_generators/medicationrequestgenerators.py index c0fbe5fa..8ef25e67 100644 --- a/healthchain/data_generators/medicationrequestgenerators.py +++ b/healthchain/data_generators/medicationrequestgenerators.py @@ -1,15 +1,6 @@ from typing import Optional from faker import Faker -from healthchain.fhir_resources.medicationrequest import ( - MedicationRequest, - Medication, - Dosage, -) -from healthchain.fhir_resources.generalpurpose import ( - Reference, - CodeableReference, -) from healthchain.data_generators.basegenerators import ( BaseGenerator, generator_registry, @@ -19,6 +10,10 @@ from healthchain.data_generators.value_sets.medicationcodes import ( MedicationRequestMedication, ) +from fhir.resources.medicationrequest import MedicationRequest +from fhir.resources.dosage import Dosage +from fhir.resources.reference import Reference +from fhir.resources.codeablereference import CodeableReference faker = Faker() @@ -51,16 +46,10 @@ def generate( Faker.seed(random_seed) subject_reference = "Patient/123" encounter_reference = "Encounter/123" - contained_medication = Medication( - code=generator_registry.get( - "MedicationRequestContainedGenerator" - ).generate() - ) return MedicationRequest( resourceType="MedicationRequest", id=generator_registry.get("IdGenerator").generate(), status=generator_registry.get("EventStatusGenerator").generate(), - contained=[contained_medication], medication=CodeableReference( reference=Reference(reference="Medication/123") ), diff --git a/healthchain/data_generators/patientgenerators.py b/healthchain/data_generators/patientgenerators.py index 7076ed31..61b15704 100644 --- a/healthchain/data_generators/patientgenerators.py +++ b/healthchain/data_generators/patientgenerators.py @@ -6,39 +6,35 @@ generator_registry, register_generator, ) -from healthchain.fhir_resources.primitives import ( - stringModel, - uriModel, - codeModel, - dateTimeModel, - positiveIntModel, -) -from healthchain.fhir_resources.generalpurpose import ( - Period, - CodeableConcept, - Coding, -) -from healthchain.fhir_resources.patient import ( - Patient, - HumanName, - ContactPoint, - Address, -) + +from datetime import datetime + +from fhir.resources.humanname import HumanName +from fhir.resources.contactpoint import ContactPoint +from fhir.resources.address import Address +from fhir.resources.period import Period +from fhir.resources.codeableconcept import CodeableConcept +from fhir.resources.coding import Coding +from fhir.resources.patient import Patient faker = Faker() +# TODO: Move to common gens @register_generator class PeriodGenerator(BaseGenerator): @staticmethod def generate(): - start = faker.date_time() - end = faker.date_time_between(start_date=start).isoformat() - start = start.isoformat() + # Use date_between instead of date() for more control + start = faker.date_between( + start_date="-30y", # You can adjust this range + end_date="today", + ) + end = faker.date_between_dates(date_start=start, date_end=datetime.now()) return Period( - start=dateTimeModel(start), - end=dateTimeModel(end), + start=start, + end=end, ) @@ -47,10 +43,10 @@ class ContactPointGenerator(BaseGenerator): @staticmethod def generate(): return ContactPoint( - system=codeModel(faker.random_element(elements=("phone", "fax"))), - value=stringModel(faker.phone_number()), - use=codeModel(faker.random_element(elements=("home", "work"))), - rank=positiveIntModel(1), + system=faker.random_element(elements=("phone", "fax")), + value=faker.phone_number(), + use=faker.random_element(elements=("home", "work")), + rank=1, period=generator_registry.get("PeriodGenerator").generate(), ) @@ -60,19 +56,15 @@ class AddressGenerator(BaseGenerator): @staticmethod def generate(): return Address( - use=codeModel( - faker.random_element(elements=("home", "work", "temp", "old")) - ), - type=codeModel( - faker.random_element(elements=("postal", "physical", "both")) - ), - text=stringModel(faker.address()), - line=[stringModel(faker.street_address())], - city=stringModel(faker.city()), - district=stringModel(faker.state()), - state=stringModel(faker.state_abbr()), - postalCode=stringModel(faker.postcode()), - country=stringModel(faker.country_code()), + use=faker.random_element(elements=("home", "work", "temp", "old")), + type=faker.random_element(elements=("postal", "physical", "both")), + text=faker.address(), + line=[faker.street_address()], + city=faker.city(), + district=faker.state(), + state=faker.state_abbr(), + postalCode=faker.postcode(), + country=faker.country_code(), period=generator_registry.get("PeriodGenerator").generate(), ) @@ -90,14 +82,12 @@ def generate(): return CodeableConcept( coding=[ Coding( - system=uriModel( - "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus" - ), - code=codeModel(marital_code), - display=stringModel(marital_status_dict.get(marital_code)), + system="http://terminology.hl7.org/CodeSystem/v3-MaritalStatus", + code=marital_code, + display=marital_status_dict.get(marital_code), ) ], - text=stringModel(marital_status_dict.get(marital_code)), + text=marital_status_dict.get(marital_code), ) @@ -106,10 +96,10 @@ class HumanNameGenerator(BaseGenerator): @staticmethod def generate(): return HumanName( - family=stringModel(faker.last_name()), - given=[stringModel(faker.first_name())], - prefix=[stringModel(faker.prefix())], - suffix=[stringModel(faker.suffix())], + family=faker.last_name(), + given=[faker.first_name()], + prefix=[faker.prefix()], + suffix=[faker.suffix()], ) @@ -122,13 +112,12 @@ def generate( ) -> Patient: Faker.seed(random_seed) return Patient( - resourceType="Patient", id=generator_registry.get("IdGenerator").generate(), active=generator_registry.get("BooleanGenerator").generate(), name=[generator_registry.get("HumanNameGenerator").generate()], telecom=[generator_registry.get("ContactPointGenerator").generate()], - gender=codeModel( - faker.random_element(elements=("male", "female", "other", "unknown")) + gender=faker.random_element( + elements=("male", "female", "other", "unknown") ), birthDate=generator_registry.get("DateGenerator").generate(), address=[ diff --git a/healthchain/data_generators/practitionergenerators.py b/healthchain/data_generators/practitionergenerators.py index 6ea94cfc..f0950cb2 100644 --- a/healthchain/data_generators/practitionergenerators.py +++ b/healthchain/data_generators/practitionergenerators.py @@ -6,21 +6,14 @@ generator_registry, register_generator, ) -from healthchain.fhir_resources.primitives import ( - booleanModel, - stringModel, - uriModel, - codeModel, -) -from healthchain.fhir_resources.generalpurpose import ( - CodeableConcept, - Coding, -) -from healthchain.fhir_resources.practitioner import ( + +from fhir.resources.practitioner import ( Practitioner, - PractitionerQualification, PractitionerCommunication, + PractitionerQualification, ) +from fhir.resources.codeableconcept import CodeableConcept +from fhir.resources.coding import Coding faker = Faker() @@ -45,16 +38,12 @@ def generate(): return CodeableConcept( coding=[ Coding( - system=uriModel("http://example.org"), - code=codeModel(random_qual), - display=stringModel( - QualificationGenerator.qualification_dict.get(random_qual) - ), + system="http://example.org", + code=random_qual, + display=QualificationGenerator.qualification_dict.get(random_qual), ) ], - text=stringModel( - QualificationGenerator.qualification_dict.get(random_qual) - ), + text=QualificationGenerator.qualification_dict.get(random_qual), ) @@ -63,7 +52,7 @@ class Practitioner_QualificationGenerator(BaseGenerator): @staticmethod def generate(): return PractitionerQualification( - id=stringModel(faker.uuid4()), + id=faker.uuid4(), code=generator_registry.get("QualificationGenerator").generate(), # TODO: Modify period generator to have flexibility to set to present date period=generator_registry.get("PeriodGenerator").generate(), @@ -91,12 +80,12 @@ def generate(): return CodeableConcept( coding=[ Coding( - system=uriModel("http://terminology.hl7.org/CodeSystem/languages"), - code=codeModel(language), - display=stringModel(language_value_dict.get(language)), + system="http://terminology.hl7.org/CodeSystem/languages", + code=language, + display=language_value_dict.get(language), ) ], - text=stringModel(language_value_dict.get(language)), + text=language_value_dict.get(language), ) @@ -105,9 +94,9 @@ class Practitioner_CommunicationGenerator(BaseGenerator): @staticmethod def generate(): return PractitionerCommunication( - id=stringModel(faker.uuid4()), + id=faker.uuid4(), language=generator_registry.get("LanguageGenerator").generate(), - preferred=booleanModel("true"), + preferred=True, ) @@ -116,13 +105,12 @@ class PractitionerGenerator(BaseGenerator): @staticmethod def generate(constraints: Optional[list] = None): return Practitioner( - resourceType="Practitioner", - id=stringModel(faker.uuid4()), - active=booleanModel("true"), + id=faker.uuid4(), + active=True, name=[generator_registry.get("HumanNameGenerator").generate()], telecom=[generator_registry.get("ContactPointGenerator").generate()], - gender=codeModel( - faker.random_element(elements=("male", "female", "other", "unknown")) + gender=faker.random_element( + elements=("male", "female", "other", "unknown") ), address=[generator_registry.get("AddressGenerator").generate()], qualification=[ diff --git a/healthchain/data_generators/proceduregenerators.py b/healthchain/data_generators/proceduregenerators.py index e3881fd2..2c9f8156 100644 --- a/healthchain/data_generators/proceduregenerators.py +++ b/healthchain/data_generators/proceduregenerators.py @@ -7,12 +7,12 @@ register_generator, CodeableConceptGenerator, ) -from healthchain.fhir_resources.generalpurpose import Reference -from healthchain.fhir_resources.procedure import Procedure from healthchain.data_generators.value_sets.procedurecodes import ( ProcedureCodeSimple, ProcedureCodeComplex, ) +from fhir.resources.procedure import Procedure +from fhir.resources.reference import Reference faker = Faker() @@ -51,7 +51,6 @@ def generate( constraints=constraints ) return Procedure( - resourceType="Procedure", id=generator_registry.get("IdGenerator").generate(), status=generator_registry.get("EventStatusGenerator").generate(), code=code, diff --git a/healthchain/fhir_resources/__init__.py b/healthchain/fhir_resources/__init__.py deleted file mode 100644 index aa2fce59..00000000 --- a/healthchain/fhir_resources/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -from .bundleresources import Bundle -from .condition import Condition -from .patient import Patient -from .practitioner import Practitioner -from .procedure import Procedure -from .documentreference import DocumentReference -from .encounter import Encounter -from .medicationadministration import MedicationAdministration -from .medicationrequest import MedicationRequest - -__all__ = [ - "Bundle", - "Condition", - "Patient", - "Practitioner", - "Procedure", - "DocumentReference", - "Encounter", - "MedicationAdministration", - "MedicationRequest", -] diff --git a/healthchain/fhir_resources/bundleresources.py b/healthchain/fhir_resources/bundleresources.py deleted file mode 100644 index 63b94aff..00000000 --- a/healthchain/fhir_resources/bundleresources.py +++ /dev/null @@ -1,78 +0,0 @@ -from pydantic import Field, BaseModel, model_validator -from typing import List, Literal, Any - -from healthchain.fhir_resources.resourceregistry import ImplementedResourceRegistry - -implemented_resources = [f"{item.value}" for item in ImplementedResourceRegistry] - - -class BundleEntry(BaseModel): - resource_field: Any = Field( - default=None, - alias="resource", - description="The Resource for the entry. The purpose/meaning of the resource is determined by the Bundle.type. This is allowed to be a Parameters resource if and only if it is referenced by something else within the Bundle that provides context/meaning.", - ) - - @model_validator(mode="before") - @classmethod - def validate_and_convert_resource(cls, values): - """ - Validates and converts the resource field in the BundleEntry. - - This method performs the following tasks: - 1. Checks if the resource is None, in which case it returns the values unchanged. - 2. If the resource is already a Pydantic BaseModel, it verifies that it's an implemented resource type. - 3. If the resource is a dictionary, it checks for the presence of a 'resourceType' key and validates that it's an implemented resource type. - 4. Dynamically imports the appropriate resource class based on the resourceType. - 5. Recursively converts nested dictionaries to the appropriate Pydantic models. - - Args: - cls: The class on which this method is called. - values (dict): A dictionary containing the field values of the BundleEntry. - - Returns: - dict: The validated and potentially modified values dictionary. - - Raises: - ValueError: If the resource is invalid or of an unsupported type. - """ - resource = values.get("resource") - - if resource is None: - return values # Return unchanged if resource is None - - if isinstance(resource, BaseModel): - # If it's already a Pydantic model (e.g., Patient), use it directly - if resource.__class__.__name__ not in implemented_resources: - raise ValueError( - f"Invalid resource type: {resource.__class__.__name__}. Must be one of {implemented_resources}." - ) - return values - - if not isinstance(resource, dict) or "resourceType" not in resource: - raise ValueError( - "Invalid resource: must be a dictionary with a 'resourceType' key or a valid FHIR resource model" - ) - - resource_type = resource["resourceType"] - if resource_type not in implemented_resources: - raise ValueError( - f"Invalid resourceType: {resource_type}. Must be one of {implemented_resources}." - ) - - # Import the appropriate resource class dynamically - module = __import__("healthchain.fhir_resources", fromlist=[resource_type]) - resource_class = getattr(module, resource_type) - - # Convert the dictionary to the appropriate Pydantic model - values["resource"] = resource_class(**resource) - return values - - -class Bundle(BaseModel): - resourceType: Literal["Bundle"] = "Bundle" - entry_field: List[BundleEntry] = Field( - default_factory=list, - alias="entry", - description="An entry in a bundle resource - will either contain a resource or information about a resource (transactions and history only).", - ) diff --git a/healthchain/fhir_resources/condition.py b/healthchain/fhir_resources/condition.py deleted file mode 100644 index e05b366c..00000000 --- a/healthchain/fhir_resources/condition.py +++ /dev/null @@ -1,238 +0,0 @@ -from pydantic import BaseModel, Field -from typing import List, Literal - -from healthchain.fhir_resources.primitives import ( - stringModel, - idModel, - uriModel, - codeModel, - dateTimeModel, -) -from healthchain.fhir_resources.generalpurpose import ( - Extension, - Identifier, - CodeableConcept, - Reference, - Period, - CodeableReference, - Narrative, - Age, - Range, - Meta, - Annotation, -) - - -class ConditionParticipant(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - function_field: CodeableConcept = Field( - default=None, - alias="function", - description="Distinguishes the type of involvement of the actor in the activities related to the condition.", - ) - actor_field: Reference = Field( - default=None, - alias="actor", - description="Indicates who or what participated in the activities related to the condition.", - ) - - -class ConditionStage(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - summary_field: CodeableConcept = Field( - default=None, - alias="summary", - description="A simple summary of the stage such as Stage 3 or Early Onset. The determination of the stage is disease-specific, such as cancer, retinopathy of prematurity, kidney diseases, Alzheimer's, or Parkinson disease.", - ) - assessment_field: List[Reference] = Field( - default=None, - alias="assessment", - description="Reference to a formal record of the evidence on which the staging assessment is based.", - ) - type_field: CodeableConcept = Field( - default=None, - alias="type", - description="The kind of staging, such as pathological or clinical staging.", - ) - - -class Condition(BaseModel): - resourceType: Literal["Condition"] = "Condition" - id_field: idModel = Field( - default=None, - alias="id", - description="The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.", - ) - meta_field: Meta = Field( - default=None, - alias="meta", - description="The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.", - ) - implicitRules_field: uriModel = Field( - default=None, - alias="implicitRules", - description="A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.", - ) - language_field: codeModel = Field( - default=None, - alias="language", - description="The base language in which the resource is written.", - ) - text_field: Narrative = Field( - default=None, - alias="text", - description="A human-readable narrative that contains a summary of the resource and can be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it clinically safe for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", - ) - # contained_field: List[ResourceListModel] = Field( - # default=None, - # alias="contained", - # description="These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, nor can they have their own independent transaction scope. This is allowed to be a Parameters resource if and only if it is referenced by a resource that provides context/meaning.", - # ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the resource. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the resource and that modifies the understanding of the element that contains it and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - identifier_field: List[Identifier] = Field( - default=None, - alias="identifier", - description="Business identifiers assigned to this condition by the performer or other systems which remain constant as the resource is updated and propagates from server to server.", - ) - clinicalStatus_field: CodeableConcept = Field( - default=None, - alias="clinicalStatus", - description="The clinical status of the condition.", - ) - verificationStatus_field: CodeableConcept = Field( - default=None, - alias="verificationStatus", - description="The verification status to support the clinical status of the condition. The verification status pertains to the condition, itself, not to any specific condition attribute.", - ) - category_field: List[CodeableConcept] = Field( - default=None, - alias="category", - description="A category assigned to the condition.", - ) - severity_field: CodeableConcept = Field( - default=None, - alias="severity", - description="A subjective assessment of the severity of the condition as evaluated by the clinician.", - ) - code_field: CodeableConcept = Field( - default=None, - alias="code", - description="Identification of the condition, problem or diagnosis.", - ) - bodySite_field: List[CodeableConcept] = Field( - default=None, - alias="bodySite", - description="The anatomical location where this condition manifests itself.", - ) - subject_field: Reference = Field( - default=None, - alias="subject", - description="Indicates the patient or group who the condition record is associated with.", - ) - encounter_field: Reference = Field( - default=None, - alias="encounter", - description="The Encounter during which this Condition was created or to which the creation of this record is tightly associated.", - ) - onsetDateTime_field: dateTimeModel = Field( - default=None, - alias="onsetDateTime", - description="Estimated or actual date or date-time the condition began, in the opinion of the clinician.", - ) - onsetAge_field: Age = Field( - default=None, - alias="onsetAge", - description="Estimated or actual date or date-time the condition began, in the opinion of the clinician.", - ) - onsetPeriod_field: Period = Field( - default=None, - alias="onsetPeriod", - description="Estimated or actual date or date-time the condition began, in the opinion of the clinician.", - ) - onsetRange_field: Range = Field( - default=None, - alias="onsetRange", - description="Estimated or actual date or date-time the condition began, in the opinion of the clinician.", - ) - abatementDateTime_field: dateTimeModel = Field( - default=None, - alias="abatementDateTime", - description="The date or estimated date that the condition resolved or went into remission. This is called abatement because of the many overloaded connotations associated with remission or resolution - Some conditions, such as chronic conditions, are never really resolved, but they can abate.", - ) - abatementAge_field: Age = Field( - default=None, - alias="abatementAge", - description="The date or estimated date that the condition resolved or went into remission. This is called abatement because of the many overloaded connotations associated with remission or resolution - Some conditions, such as chronic conditions, are never really resolved, but they can abate.", - ) - abatementPeriod_field: Period = Field( - default=None, - alias="abatementPeriod", - description="The date or estimated date that the condition resolved or went into remission. This is called abatement because of the many overloaded connotations associated with remission or resolution - Some conditions, such as chronic conditions, are never really resolved, but they can abate.", - ) - abatementRange_field: Range = Field( - default=None, - alias="abatementRange", - description="The date or estimated date that the condition resolved or went into remission. This is called abatement because of the many overloaded connotations associated with remission or resolution - Some conditions, such as chronic conditions, are never really resolved, but they can abate.", - ) - recordedDate_field: dateTimeModel = Field( - default=None, - alias="recordedDate", - description="The recordedDate represents when this particular Condition record was created in the system, which is often a system-generated date.", - ) - participant_field: List[ConditionParticipant] = Field( - default=None, - alias="participant", - description="Indicates who or what participated in the activities related to the condition and how they were involved.", - ) - stage_field: List[ConditionStage] = Field( - default=None, - alias="stage", - description="A simple summary of the stage such as Stage 3 or Early Onset. The determination of the stage is disease-specific, such as cancer, retinopathy of prematurity, kidney diseases, Alzheimer's, or Parkinson disease.", - ) - evidence_field: List[CodeableReference] = Field( - default=None, - alias="evidence", - description="Supporting evidence / manifestations that are the basis of the Condition's verification status, such as evidence that confirmed or refuted the condition.", - ) - note_field: List[Annotation] = Field( - default=None, - alias="note", - description="Additional information about the Condition. This is a general notes/comments entry for description of the Condition, its diagnosis and prognosis.", - ) diff --git a/healthchain/fhir_resources/documentreference.py b/healthchain/fhir_resources/documentreference.py deleted file mode 100644 index 33d505cc..00000000 --- a/healthchain/fhir_resources/documentreference.py +++ /dev/null @@ -1,293 +0,0 @@ -from pydantic import BaseModel, Field -from typing import List, Literal - -from healthchain.fhir_resources.primitives import ( - idModel, - uriModel, - codeModel, - dateTimeModel, - instantModel, - markdownModel, - stringModel, -) -from healthchain.fhir_resources.generalpurpose import ( - Extension, - CodeableConcept, - Reference, - Period, - Narrative, - CodeableReference, - Coding, - Attachment, - Identifier, - Meta, -) - - -class DocumentReferenceAttester(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - mode_field: CodeableConcept = Field( - default=None, - alias="mode", - description="The type of attestation the authenticator offers.", - ) - time_field: dateTimeModel = Field( - default=None, - alias="time", - description="When the document was attested by the party.", - ) - party_field: Reference = Field( - default=None, - alias="party", - description="Who attested the document in the specified way.", - ) - - -class DocumentReferenceRelatesTo(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - code_field: CodeableConcept = Field( - default=None, - alias="code", - description="The type of relationship that this document has with anther document.", - ) - target_field: Reference = Field( - default=None, - alias="target", - description="The target document of this relationship.", - ) - - -class DocumentReferenceProfile(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - valueCoding_field: Coding = Field( - default=None, alias="valueCoding", description="Code|uri|canonical." - ) - - -class DocumentReferenceContent(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - attachment_field: Attachment = Field( - default=None, - alias="attachment", - description="The document or URL of the document along with critical metadata to prove content has integrity.", - ) - profile_field: List[DocumentReferenceProfile] = Field( - default=None, - alias="profile", - description="An identifier of the document constraints, encoding, structure, and template that the document conforms to beyond the base format indicated in the mimeType.", - ) - - -class DocumentReference(BaseModel): - resourceType: Literal["DocumentReference"] = "DocumentReference" - id_field: idModel = Field( - default=None, - alias="id", - description="The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.", - ) - meta_field: Meta = Field( - default=None, - alias="meta", - description="The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.", - ) - implicitRules_field: uriModel = Field( - default=None, - alias="implicitRules", - description="A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.", - ) - language_field: codeModel = Field( - default=None, - alias="language", - description="The base language in which the resource is written.", - ) - text_field: Narrative = Field( - default=None, - alias="text", - description="A human-readable narrative that contains a summary of the resource and can be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it clinically safe for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", - ) - # contained_field: List[ResourceListModel] = Field( - # default=None, - # alias="contained", - # description="These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, nor can they have their own independent transaction scope. This is allowed to be a Parameters resource if and only if it is referenced by a resource that provides context/meaning.", - # ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the resource. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the resource and that modifies the understanding of the element that contains it and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - identifier_field: List[Identifier] = Field( - default=None, - alias="identifier", - description="Other business identifiers associated with the document, including version independent identifiers.", - ) - version_field: stringModel = Field( - default=None, - alias="version", - description="An explicitly assigned identifer of a variation of the content in the DocumentReference.", - ) - basedOn_field: List[Reference] = Field( - default=None, - alias="basedOn", - description="A procedure that is fulfilled in whole or in part by the creation of this media.", - ) - status_field: codeModel = Field( - default=None, - alias="status", - description="The status of this document reference.", - ) - docStatus_field: codeModel = Field( - default=None, - alias="docStatus", - description="The status of the underlying document.", - ) - modality_field: List[CodeableConcept] = Field( - default=None, - alias="modality", - description="Imaging modality used. This may include both acquisition and non-acquisition modalities.", - ) - type_field: CodeableConcept = Field( - default=None, - alias="type", - description="Specifies the particular kind of document referenced (e.g. History and Physical, Discharge Summary, Progress Note). This usually equates to the purpose of making the document referenced.", - ) - category_field: List[CodeableConcept] = Field( - default=None, - alias="category", - description="A categorization for the type of document referenced - helps for indexing and searching. This may be implied by or derived from the code specified in the DocumentReference.type.", - ) - subject_field: Reference = Field( - default=None, - alias="subject", - description="Who or what the document is about. The document can be about a person, (patient or healthcare practitioner), a device (e.g. a machine) or even a group of subjects (such as a document about a herd of farm animals, or a set of patients that share a common exposure).", - ) - context_field: List[Reference] = Field( - default=None, - alias="context", - description="Describes the clinical encounter or type of care that the document content is associated with.", - ) - event_field: List[CodeableReference] = Field( - default=None, - alias="event", - description="This list of codes represents the main clinical acts, such as a colonoscopy or an appendectomy, being documented. In some cases, the event is inherent in the type Code, such as a History and Physical Report in which the procedure being documented is necessarily a History and Physical act.", - ) - bodySite_field: List[CodeableReference] = Field( - default=None, - alias="bodySite", - description="The anatomic structures included in the document.", - ) - facilityType_field: CodeableConcept = Field( - default=None, - alias="facilityType", - description="The kind of facility where the patient was seen.", - ) - practiceSetting_field: CodeableConcept = Field( - default=None, - alias="practiceSetting", - description="This property may convey specifics about the practice setting where the content was created, often reflecting the clinical specialty.", - ) - period_field: Period = Field( - default=None, - alias="period", - description="The time period over which the service that is described by the document was provided.", - ) - date_field: instantModel = Field( - default=None, - alias="date", - description="When the document reference was created.", - ) - author_field: List[Reference] = Field( - default=None, - alias="author", - description="Identifies who is responsible for adding the information to the document.", - ) - attester_field: List[DocumentReferenceAttester] = Field( - default=None, - alias="attester", - description="A participant who has authenticated the accuracy of the document.", - ) - custodian_field: Reference = Field( - default=None, - alias="custodian", - description="Identifies the organization or group who is responsible for ongoing maintenance of and access to the document.", - ) - relatesTo_field: List[DocumentReferenceRelatesTo] = Field( - default=None, - alias="relatesTo", - description="Relationships that this document has with other document references that already exist.", - ) - description_field: markdownModel = Field( - default=None, - alias="description", - description="Human-readable description of the source document.", - ) - securityLabel_field: List[CodeableConcept] = Field( - default=None, - alias="securityLabel", - description="A set of Security-Tag codes specifying the level of privacy/security of the Document found at DocumentReference.content.attachment.url. Note that DocumentReference.meta.security contains the security labels of the data elements in DocumentReference, while DocumentReference.securityLabel contains the security labels for the document the reference refers to. The distinction recognizes that the document may contain sensitive information, while the DocumentReference is metadata about the document and thus might not be as sensitive as the document. For example: a psychotherapy episode may contain highly sensitive information, while the metadata may simply indicate that some episode happened.", - ) - content_field: List[DocumentReferenceContent] = Field( - default=None, - alias="content", - description="The document and format referenced. If there are multiple content element repetitions, these must all represent the same document in different format, or attachment metadata.", - ) diff --git a/healthchain/fhir_resources/encounter.py b/healthchain/fhir_resources/encounter.py deleted file mode 100644 index 2b96580d..00000000 --- a/healthchain/fhir_resources/encounter.py +++ /dev/null @@ -1,367 +0,0 @@ -from pydantic import BaseModel, Field -from typing import List, Literal - -from healthchain.fhir_resources.primitives import ( - stringModel, - idModel, - uriModel, - codeModel, - dateTimeModel, -) -from healthchain.fhir_resources.generalpurpose import ( - Extension, - Identifier, - CodeableConcept, - Reference, - Period, - CodeableReference, - Narrative, - Meta, -) - - -class EncounterParticipant(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - type_field: List[CodeableConcept] = Field( - default=None, - alias="type", - description="Role of participant in encounter.", - ) - period_field: Period = Field( - default=None, - alias="period", - description="The period of time that the specified participant participated in the encounter. These can overlap or be sub-sets of the overall encounter's period.", - ) - actor_field: Reference = Field( - default=None, - alias="actor", - description="Person involved in the encounter, the patient/group is also included here to indicate that the patient was actually participating in the encounter. Not including the patient here covers use cases such as a case meeting between practitioners about a patient - non contact times.", - ) - - -class EncounterReason(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - use_field: List[CodeableConcept] = Field( - default=None, - alias="use", - description="What the reason value should be used as e.g. Chief Complaint, Health Concern, Health Maintenance (including screening).", - ) - value_field: List[CodeableReference] = Field( - default=None, - alias="value", - description="Reason the encounter takes place, expressed as a code or a reference to another resource. For admissions, this can be used for a coded admission diagnosis.", - ) - - -class EncounterDiagnosis(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - condition_field: List[CodeableReference] = Field( - default=None, - alias="condition", - description="The coded diagnosis or a reference to a Condition (with other resources referenced in the evidence.detail), the use property will indicate the purpose of this specific diagnosis.", - ) - use_field: List[CodeableConcept] = Field( - default=None, - alias="use", - description="Role that this diagnosis has within the encounter (e.g. admission, billing, discharge …).", - ) - - -class EncounterAdmission(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - preAdmissionIdentifier_field: Identifier = Field( - default=None, - alias="preAdmissionIdentifier", - description="Pre-admission identifier.", - ) - origin_field: Reference = Field( - default=None, - alias="origin", - description="The location/organization from which the patient came before admission.", - ) - admitSource_field: CodeableConcept = Field( - default=None, - alias="admitSource", - description="From where patient was admitted (physician referral, transfer).", - ) - reAdmission_field: CodeableConcept = Field( - default=None, - alias="reAdmission", - description="Indicates that this encounter is directly related to a prior admission, often because the conditions addressed in the prior admission were not fully addressed.", - ) - destination_field: Reference = Field( - default=None, - alias="destination", - description="Location/organization to which the patient is discharged.", - ) - dischargeDisposition_field: CodeableConcept = Field( - default=None, - alias="dischargeDisposition", - description="Category or kind of location after discharge.", - ) - - -class EncounterLocation(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - location_field: Reference = Field( - default=None, - alias="location", - description="The location where the encounter takes place.", - ) - status_field: codeModel = Field( - default=None, - alias="status", - description="The status of the participants' presence at the specified location during the period specified. If the participant is no longer at the location, then the period will have an end date/time.", - ) - form_field: CodeableConcept = Field( - default=None, - alias="form", - description="This will be used to specify the required levels (bed/ward/room/etc.) desired to be recorded to simplify either messaging or query.", - ) - period_field: Period = Field( - default=None, - alias="period", - description="Time period during which the patient was present at the location.", - ) - - -class Encounter(BaseModel): - resourceType: Literal["Encounter"] = "Encounter" - id_field: idModel = Field( - default=None, - alias="id", - description="The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.", - ) - meta_field: Meta = Field( - default=None, - alias="meta", - description="The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.", - ) - implicitRules_field: uriModel = Field( - default=None, - alias="implicitRules", - description="A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.", - ) - language_field: codeModel = Field( - default=None, - alias="language", - description="The base language in which the resource is written.", - ) - text_field: Narrative = Field( - default=None, - alias="text", - description="A human-readable narrative that contains a summary of the resource and can be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it clinically safe for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", - ) - # contained_field: List[ResourceListModel] = Field(default=None, alias="contained", description="These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, nor can they have their own independent transaction scope. This is allowed to be a Parameters resource if and only if it is referenced by a resource that provides context/meaning.") - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the resource. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the resource and that modifies the understanding of the element that contains it and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - identifier_field: List[Identifier] = Field( - default=None, - alias="identifier", - description="Identifier(s) by which this encounter is known.", - ) - status_field: codeModel = Field( - default=None, - alias="status", - description="The current state of the encounter (not the state of the patient within the encounter - that is subjectState).", - ) - class_field: List[CodeableConcept] = Field( - default=None, - alias="class", - description="Concepts representing classification of patient encounter such as ambulatory (outpatient), inpatient, emergency, home health or others due to local variations.", - ) - priority_field: CodeableConcept = Field( - default=None, - alias="priority", - description="Indicates the urgency of the encounter.", - ) - type_field: List[CodeableConcept] = Field( - default=None, - alias="type", - description="Specific type of encounter (e.g. e-mail consultation, surgical day-care, skilled nursing, rehabilitation).", - ) - serviceType_field: List[CodeableReference] = Field( - default=None, - alias="serviceType", - description="Broad categorization of the service that is to be provided (e.g. cardiology).", - ) - subject_field: Reference = Field( - default=None, - alias="subject", - description="The patient or group related to this encounter. In some use-cases the patient MAY not be present, such as a case meeting about a patient between several practitioners or a careteam.", - ) - subjectStatus_field: CodeableConcept = Field( - default=None, - alias="subjectStatus", - description="The subjectStatus value can be used to track the patient's status within the encounter. It details whether the patient has arrived or departed, has been triaged or is currently in a waiting status.", - ) - episodeOfCare_field: List[Reference] = Field( - default=None, - alias="episodeOfCare", - description="Where a specific encounter should be classified as a part of a specific episode(s) of care this field should be used. This association can facilitate grouping of related encounters together for a specific purpose, such as government reporting, issue tracking, association via a common problem. The association is recorded on the encounter as these are typically created after the episode of care and grouped on entry rather than editing the episode of care to append another encounter to it (the episode of care could span years).", - ) - basedOn_field: List[Reference] = Field( - default=None, - alias="basedOn", - description="The request this encounter satisfies (e.g. incoming referral or procedure request).", - ) - careTeam_field: List[Reference] = Field( - default=None, - alias="careTeam", - description="The group(s) of individuals, organizations that are allocated to participate in this encounter. The participants backbone will record the actuals of when these individuals participated during the encounter.", - ) - partOf_field: Reference = Field( - default=None, - alias="partOf", - description="Another Encounter of which this encounter is a part of (administratively or in time).", - ) - serviceProvider_field: Reference = Field( - default=None, - alias="serviceProvider", - description="The organization that is primarily responsible for this Encounter's services. This MAY be the same as the organization on the Patient record, however it could be different, such as if the actor performing the services was from an external organization (which may be billed seperately) for an external consultation. Refer to the colonoscopy example on the Encounter examples tab.", - ) - participant_field: List[EncounterParticipant] = Field( - default=None, - alias="participant", - description="The list of people responsible for providing the service.", - ) - appointment_field: List[Reference] = Field( - default=None, - alias="appointment", - description="The appointment that scheduled this encounter.", - ) - # virtualService_field: List[VirtualServiceDetailModel] = Field(default=None, alias="virtualService", description="Connection details of a virtual service (e.g. conference call).") - actualPeriod_field: Period = Field( - default=None, - alias="actualPeriod", - description="The actual start and end time of the encounter.", - ) - plannedStartDate_field: dateTimeModel = Field( - default=None, - alias="plannedStartDate", - description="The planned start date/time (or admission date) of the encounter.", - ) - plannedEndDate_field: dateTimeModel = Field( - default=None, - alias="plannedEndDate", - description="The planned end date/time (or discharge date) of the encounter.", - ) - # length_field: DurationModel = Field(default=None, alias="length", description="Actual quantity of time the encounter lasted. This excludes the time during leaves of absence.") - reason_field: List[EncounterReason] = Field( - default=None, - alias="reason", - description="The list of medical reasons that are expected to be addressed during the episode of care.", - ) - diagnosis_field: List[EncounterDiagnosis] = Field( - default=None, - alias="diagnosis", - description="The list of diagnosis relevant to this encounter.", - ) - account_field: List[Reference] = Field( - default=None, - alias="account", - description="The set of accounts that may be used for billing for this Encounter.", - ) - dietPreference_field: List[CodeableConcept] = Field( - default=None, - alias="dietPreference", - description="Diet preferences reported by the patient.", - ) - specialArrangement_field: List[CodeableConcept] = Field( - default=None, - alias="specialArrangement", - description="Any special requests that have been made for this encounter, such as the provision of specific equipment or other things.", - ) - specialCourtesy_field: List[CodeableConcept] = Field( - default=None, - alias="specialCourtesy", - description="Special courtesies that may be provided to the patient during the encounter (VIP, board member, professional courtesy).", - ) - admission_field: EncounterAdmission = Field( - default=None, - alias="admission", - description="Details about the stay during which a healthcare service is provided.", - ) - location_field: List[EncounterLocation] = Field( - default=None, - alias="location", - description="List of locations where the patient has been during this encounter.", - ) diff --git a/healthchain/fhir_resources/generalpurpose.py b/healthchain/fhir_resources/generalpurpose.py deleted file mode 100644 index 54f5c21e..00000000 --- a/healthchain/fhir_resources/generalpurpose.py +++ /dev/null @@ -1,651 +0,0 @@ -from __future__ import annotations - -from typing import List -from pydantic import BaseModel, Field - -from healthchain.fhir_resources.primitives import ( - stringModel, - uriModel, - dateTimeModel, - codeModel, - booleanModel, - markdownModel, - decimalModel, - comparatorModel, - positiveIntModel, - canonicalModel, - unsignedIntModel, - idModel, - instantModel, - timeModel, - integer64Model, - urlModel, -) - - -class Extension(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - url_field: uriModel = Field( - default=None, - alias="url", - description="Source of the definition for the extension code - a logical name or a URL.", - ) - - -class Period(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - start_field: dateTimeModel = Field( - default=None, - alias="start", - description="The start of the period. The boundary is inclusive.", - ) - end_field: dateTimeModel = Field( - default=None, - alias="end", - description="The end of the period. If the end of the period is missing, it means no end was known or planned at the time the instance was created. The start may be in the past, and the end date in the future, which means that period is expected/planned to end at that time.", - ) - - -class Identifier(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - # Identifier_use_field: useModel = Field(..., alias="use", description="The purpose of this identifier.") - type_field: CodeableConcept = Field( - default=None, - alias="type", - description="A coded type for the identifier that can be used to determine which identifier to use for a specific purpose.", - ) - system_field: uriModel = Field( - default=None, - alias="system", - description="Establishes the namespace for the value - that is, an absolute URL that describes a set values that are unique.", - ) - value_field: stringModel = Field( - default=None, - alias="value", - description="The portion of the identifier typically relevant to the user and which is unique within the context of the system.", - ) - period_field: Period = Field( - default=None, - alias="period", - description="Time period during which identifier is/was valid for use.", - ) - assigner_field: Reference = Field( - default=None, - alias="assigner", - description="Organization that issued/manages the identifier.", - ) - - -class Coding(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - system_field: uriModel = Field( - default=None, - alias="system", - description="The identification of the code system that defines the meaning of the symbol in the code.", - ) - version_field: stringModel = Field( - default=None, - alias="version", - description="The version of the code system which was used when choosing this code. Note that a well-maintained code system does not need the version reported, because the meaning of codes is consistent across versions. However this cannot consistently be assured, and when the meaning is not guaranteed to be consistent, the version SHOULD be exchanged.", - ) - code_field: codeModel = Field( - default=None, - alias="code", - description="A symbol in syntax defined by the system. The symbol may be a predefined code or an expression in a syntax defined by the coding system (e.g. post-coordination).", - ) - display_field: stringModel = Field( - default=None, - alias="display", - description="A representation of the meaning of the code in the system, following the rules of the system.", - ) - userSelected_field: booleanModel = Field( - default=None, - alias="userSelected", - description="Indicates that this coding was chosen by a user directly - e.g. off a pick list of available items (codes or displays).", - ) - - -class CodeableConcept(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - coding_field: List[Coding] = Field( - default=None, - alias="coding", - description="A reference to a code defined by a terminology system.", - ) - text_field: stringModel = Field( - default=None, - alias="text", - description="A human language representation of the concept as seen/selected/uttered by the user who entered the data and/or which represents the intended meaning of the user.", - ) - - -class Reference(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - reference_field: stringModel = Field( - default=None, - alias="reference", - description="A reference to a location at which the other resource is found. The reference may be a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources.", - ) - type_field: uriModel = Field( - default=None, - alias="type", - description="The expected type of the target of the reference. If both Reference.type and Reference.reference are populated and Reference.reference is a FHIR URL, both SHALL be consistent.", - ) - identifier_field: Identifier = Field( - default=None, - alias="identifier", - description="An identifier for the target resource. This is used when there is no way to reference the other resource directly, either because the entity it represents is not available through a FHIR server, or because there is no way for the author of the resource to convert a known identifier to an actual location. There is no requirement that a Reference.identifier point to something that is actually exposed as a FHIR instance, but it SHALL point to a business concept that would be expected to be exposed as a FHIR instance, and that instance would need to be of a FHIR resource type allowed by the reference.", - ) - display_field: stringModel = Field( - default=None, - alias="display", - description="Plain text narrative that identifies the resource in addition to the resource reference.", - ) - - -class CodeableReference(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - concept_field: CodeableConcept = Field( - default=None, - alias="concept", - description="A reference to a concept - e.g. the information is identified by its general class to the degree of precision found in the terminology.", - ) - reference_field: Reference = Field( - default=None, - alias="reference", - description="A reference to a resource the provides exact details about the information being referenced.", - ) - - -class Narrative(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - # Narrative_status_field: statusModel = Field(..., alias="status", description="The status of the narrative - whether it's entirely generated (from just the defined data or the extensions too), or whether a human authored it and it may contain additional data.") - div_field: stringModel = Field( - default=None, - alias="div", - description="The actual narrative content, a stripped down version of XHTML.", - ) - - -class Age(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - value_field: decimalModel = Field( - default=None, - alias="value", - description="The value of the measured amount. The value includes an implicit precision in the presentation of the value.", - ) - age_comparator_field: comparatorModel = Field( - ..., - alias="comparator", - description="How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is < , then the real value is < stated value.", - ) - unit_field: stringModel = Field( - default=None, alias="unit", description="A human-readable form of the unit." - ) - system_field: uriModel = Field( - default=None, - alias="system", - description="The identification of the system that provides the coded form of the unit.", - ) - code_field: codeModel = Field( - default=None, - alias="code", - description="A computer processable form of the unit in some unit representation system.", - ) - - -class Quantity(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - value_field: decimalModel = Field( - default=None, - alias="value", - description="The value of the measured amount. The value includes an implicit precision in the presentation of the value.", - ) - # Quantity_comparator_field: comparatorModel = Field(..., alias="comparator", description="How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is < , then the real value is < stated value.") - unit_field: stringModel = Field( - default=None, alias="unit", description="A human-readable form of the unit." - ) - system_field: uriModel = Field( - default=None, - alias="system", - description="The identification of the system that provides the coded form of the unit.", - ) - code_field: codeModel = Field( - default=None, - alias="code", - description="A computer processable form of the unit in some unit representation system.", - ) - - -class Range(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - low_field: Quantity = Field( - default=None, - alias="low", - description="The low limit. The boundary is inclusive.", - ) - high_field: Quantity = Field( - default=None, - alias="high", - description="The high limit. The boundary is inclusive.", - ) - - -class Ratio(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - numerator_field: Quantity = Field( - default=None, alias="numerator", description="The value of the numerator." - ) - denominator_field: Quantity = Field( - default=None, alias="denominator", description="The value of the denominator." - ) - - -class Timing(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - event_field: List[dateTimeModel] = Field( - default=None, - alias="event", - description="Identifies specific times when the event occurs.", - ) - repeat_field: TimingRepeat = Field( - default=None, - alias="repeat", - description="A set of rules that describe when the event is scheduled.", - ) - code_field: CodeableConcept = Field( - default=None, - alias="code", - description="A code for the timing schedule (or just text in code.text). Some codes such as BID are ubiquitous, but many institutions define their own additional codes. If a code is provided, the code is understood to be a complete statement of whatever is specified in the structured timing data, and either the code or the data may be used to interpret the Timing, with the exception that .repeat.bounds still applies over the code (and is not contained in the code).", - ) - - -class TimingRepeat(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - boundsDuration_field: Duration = Field( - default=None, - alias="boundsDuration", - description="Either a duration for the length of the timing schedule, a range of possible length, or outer bounds for start and/or end limits of the timing schedule.", - ) - boundsRange_field: Range = Field( - default=None, - alias="boundsRange", - description="Either a duration for the length of the timing schedule, a range of possible length, or outer bounds for start and/or end limits of the timing schedule.", - ) - boundsPeriod_field: Period = Field( - default=None, - alias="boundsPeriod", - description="Either a duration for the length of the timing schedule, a range of possible length, or outer bounds for start and/or end limits of the timing schedule.", - ) - count_field: positiveIntModel = Field( - default=None, - alias="count", - description="A total count of the desired number of repetitions across the duration of the entire timing specification. If countMax is present, this element indicates the lower bound of the allowed range of count values.", - ) - countMax_field: positiveIntModel = Field( - default=None, - alias="countMax", - description="If present, indicates that the count is a range - so to perform the action between [count] and [countMax] times.", - ) - duration_field: decimalModel = Field( - default=None, - alias="duration", - description="How long this thing happens for when it happens. If durationMax is present, this element indicates the lower bound of the allowed range of the duration.", - ) - durationMax_field: decimalModel = Field( - default=None, - alias="durationMax", - description="If present, indicates that the duration is a range - so to perform the action between [duration] and [durationMax] time length.", - ) - # Timing_Repeat_durationUnit_field: durationUnitModel = Field(..., alias="durationUnit", description="The units of time for the duration, in UCUM units") - frequency_field: positiveIntModel = Field( - default=None, - alias="frequency", - description="The number of times to repeat the action within the specified period. If frequencyMax is present, this element indicates the lower bound of the allowed range of the frequency.", - ) - frequencyMax_field: positiveIntModel = Field( - default=None, - alias="frequencyMax", - description="If present, indicates that the frequency is a range - so to repeat between [frequency] and [frequencyMax] times within the period or period range.", - ) - period_field: decimalModel = Field( - default=None, - alias="period", - description="Indicates the duration of time over which repetitions are to occur; e.g. to express 3 times per day, 3 would be the frequency and 1 day would be the period. If periodMax is present, this element indicates the lower bound of the allowed range of the period length.", - ) - periodMax_field: decimalModel = Field( - default=None, - alias="periodMax", - description="If present, indicates that the period is a range from [period] to [periodMax], allowing expressing concepts such as do this once every 3-5 days.", - ) - # Timing_Repeat_periodUnit_field: periodUnitModel = Field(..., alias="periodUnit", description="The units of time for the period in UCUM units") - dayOfWeek_field: List[codeModel] = Field( - default=None, - alias="dayOfWeek", - description="If one or more days of week is provided, then the action happens only on the specified day(s).", - ) - timeOfDay_field: List[timeModel] = Field( - default=None, - alias="timeOfDay", - description="Specified time of day for action to take place.", - ) - offset_field: unsignedIntModel = Field( - default=None, - alias="offset", - description="The number of minutes from the event. If the event code does not indicate whether the minutes is before or after the event, then the offset is assumed to be after the event.", - ) - - -class Meta(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - versionId_field: idModel = Field( - default=None, - alias="versionId", - description="The version specific identifier, as it appears in the version portion of the URL. This value changes when the resource is created, updated, or deleted.", - ) - lastUpdated_field: instantModel = Field( - default=None, - alias="lastUpdated", - description="When the resource last changed - e.g. when the version changed.", - ) - source_field: uriModel = Field( - default=None, - alias="source", - description="A uri that identifies the source system of the resource. This provides a minimal amount of [[[Provenance]]] information that can be used to track or differentiate the source of information in the resource. The source may identify another FHIR server, document, message, database, etc.", - ) - profile_field: List[canonicalModel] = Field( - default=None, - alias="profile", - description="A list of profiles (references to [[[StructureDefinition]]] resources) that this resource claims to conform to. The URL is a reference to [[[StructureDefinition.url]]].", - ) - security_field: List[Coding] = Field( - default=None, - alias="security", - description="Security labels applied to this resource. These tags connect specific resources to the overall security policy and infrastructure.", - ) - tag_field: List[Coding] = Field( - default=None, - alias="tag", - description="Tags applied to this resource. Tags are intended to be used to identify and relate resources to process and workflow, and applications are not required to consider the tags when interpreting the meaning of a resource.", - ) - - -class Duration(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - value_field: decimalModel = Field( - default=None, - alias="value", - description="The value of the measured amount. The value includes an implicit precision in the presentation of the value.", - ) - # Duration_comparator_field: comparatorModel = Field(..., alias="comparator", description="How the value should be understood and represented - whether the actual value is greater or less than the stated value due to measurement issues; e.g. if the comparator is < , then the real value is < stated value.") - unit_field: stringModel = Field( - default=None, alias="unit", description="A human-readable form of the unit." - ) - system_field: uriModel = Field( - default=None, - alias="system", - description="The identification of the system that provides the coded form of the unit.", - ) - code_field: codeModel = Field( - default=None, - alias="code", - description="A computer processable form of the unit in some unit representation system.", - ) - - -class Annotation(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - authorReference_field: Reference = Field( - default=None, - alias="authorReference", - description="The individual responsible for making the annotation.", - ) - time_field: dateTimeModel = Field( - default=None, - alias="time", - description="Indicates when this particular annotation was made.", - ) - text_field: markdownModel = Field( - default=None, - alias="text", - description="The text of the annotation in markdown format.", - ) - - -class Attachment(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - contentType_field: codeModel = Field( - default=None, - alias="contentType", - description="Identifies the type of the data in the attachment and allows a method to be chosen to interpret or render the data. Includes mime type parameters such as charset where appropriate.", - ) - language_field: codeModel = Field( - default=None, - alias="language", - description="The human language of the content. The value can be any valid value according to BCP 47.", - ) - data_field: stringModel = Field( - default=None, - alias="data", - description="The actual data of the attachment - a sequence of bytes, base64 encoded.", - ) - url_field: urlModel = Field( - default=None, - alias="url", - description="A location where the data can be accessed.", - ) - size_field: integer64Model = Field( - default=None, - alias="size", - description="The number of bytes of data that make up this attachment (before base64 encoding, if that is done).", - ) - hash_field: stringModel = Field( - default=None, - alias="hash", - description="The calculated hash of the data using SHA-1. Represented using base64.", - ) - title_field: stringModel = Field( - default=None, - alias="title", - description="A label or set of text to display in place of the data.", - ) - creation_field: dateTimeModel = Field( - default=None, - alias="creation", - description="The date that the attachment was first created.", - ) - height_field: positiveIntModel = Field( - default=None, - alias="height", - description="Height of the image in pixels (photo/video).", - ) - width_field: positiveIntModel = Field( - default=None, - alias="width", - description="Width of the image in pixels (photo/video).", - ) - frames_field: positiveIntModel = Field( - default=None, - alias="frames", - description="The number of frames in a photo. This is used with a multi-page fax, or an imaging acquisition context that takes multiple slices in a single image, or an animated gif. If there is more than one frame, this SHALL have a value in order to alert interface software that a multi-frame capable rendering widget is required.", - ) - duration_field: decimalModel = Field( - default=None, - alias="duration", - description="The duration of the recording in seconds - for audio and video.", - ) - pages_field: positiveIntModel = Field( - default=None, alias="pages", description="The number of pages when printed." - ) diff --git a/healthchain/fhir_resources/medicationadministration.py b/healthchain/fhir_resources/medicationadministration.py deleted file mode 100644 index 00b966e7..00000000 --- a/healthchain/fhir_resources/medicationadministration.py +++ /dev/null @@ -1,260 +0,0 @@ -from pydantic import BaseModel, Field -from typing import List, Literal - -from healthchain.fhir_resources.primitives import ( - stringModel, - idModel, - uriModel, - codeModel, - dateTimeModel, - booleanModel, -) -from healthchain.fhir_resources.generalpurpose import ( - Extension, - Identifier, - CodeableConcept, - Reference, - Period, - CodeableReference, - Narrative, - Quantity, - Timing, - Ratio, - Meta, - Annotation, -) - - -class MedicationAdministrationPerformer(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - function_field: CodeableConcept = Field( - default=None, - alias="function", - description="Distinguishes the type of involvement of the performer in the medication administration.", - ) - actor_field: CodeableReference = Field( - default=None, - alias="actor", - description="Indicates who or what performed the medication administration.", - ) - - -class MedicationAdministrationDosage(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - text_field: stringModel = Field( - default=None, - alias="text", - description="Free text dosage can be used for cases where the dosage administered is too complex to code. When coded dosage is present, the free text dosage may still be present for display to humans.", - ) - site_field: CodeableConcept = Field( - default=None, - alias="site", - description="A coded specification of the anatomic site where the medication first entered the body. For example, left arm.", - ) - route_field: CodeableConcept = Field( - default=None, - alias="route", - description="A code specifying the route or physiological path of administration of a therapeutic agent into or onto the patient. For example, topical, intravenous, etc.", - ) - method_field: CodeableConcept = Field( - default=None, - alias="method", - description="A coded value indicating the method by which the medication is intended to be or was introduced into or on the body. This attribute will most often NOT be populated. It is most commonly used for injections. For example, Slow Push, Deep IV.", - ) - dose_field: Quantity = Field( - default=None, - alias="dose", - description="The amount of the medication given at one administration event. Use this value when the administration is essentially an instantaneous event such as a swallowing a tablet or giving an injection.", - ) - rateRatio_field: Ratio = Field( - default=None, - alias="rateRatio", - description="Identifies the speed with which the medication was or will be introduced into the patient. Typically, the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr. May also be expressed as a rate per unit of time, e.g. 500 ml per 2 hours. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.", - ) - rateQuantity_field: Quantity = Field( - default=None, - alias="rateQuantity", - description="Identifies the speed with which the medication was or will be introduced into the patient. Typically, the rate for an infusion e.g. 100 ml per 1 hour or 100 ml/hr. May also be expressed as a rate per unit of time, e.g. 500 ml per 2 hours. Other examples: 200 mcg/min or 200 mcg/1 minute; 1 liter/8 hours.", - ) - - -class MedicationAdministration(BaseModel): - resourceType: Literal["MedicationAdministration"] = "MedicationAdministration" - id_field: idModel = Field( - default=None, - alias="id", - description="The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.", - ) - meta_field: Meta = Field( - default=None, - alias="meta", - description="The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.", - ) - implicitRules_field: uriModel = Field( - default=None, - alias="implicitRules", - description="A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.", - ) - language_field: codeModel = Field( - default=None, - alias="language", - description="The base language in which the resource is written.", - ) - text_field: Narrative = Field( - default=None, - alias="text", - description="A human-readable narrative that contains a summary of the resource and can be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it clinically safe for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", - ) - # contained_field: List[ResourceListModel] = Field( - # default=None, - # alias="contained", - # description="These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, nor can they have their own independent transaction scope. This is allowed to be a Parameters resource if and only if it is referenced by a resource that provides context/meaning.", - # ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the resource. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the resource and that modifies the understanding of the element that contains it and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - identifier_field: List[Identifier] = Field( - default=None, - alias="identifier", - description="Identifiers associated with this Medication Administration that are defined by business processes and/or used to refer to it when a direct URL reference to the resource itself is not appropriate. They are business identifiers assigned to this resource by the performer or other systems and remain constant as the resource is updated and propagates from server to server.", - ) - basedOn_field: List[Reference] = Field( - default=None, - alias="basedOn", - description="A plan that is fulfilled in whole or in part by this MedicationAdministration.", - ) - partOf_field: List[Reference] = Field( - default=None, - alias="partOf", - description="A larger event of which this particular event is a component or step.", - ) - status_field: codeModel = Field( - default=None, - alias="status", - description="Will generally be set to show that the administration has been completed. For some long running administrations such as infusions, it is possible for an administration to be started but not completed or it may be paused while some other process is under way.", - ) - statusReason_field: List[CodeableConcept] = Field( - default=None, - alias="statusReason", - description="A code indicating why the administration was not performed.", - ) - category_field: List[CodeableConcept] = Field( - default=None, - alias="category", - description="The type of medication administration (for example, drug classification like ATC, where meds would be administered, legal category of the medication).", - ) - medication_field: CodeableReference = Field( - default=None, - alias="medication", - description="Identifies the medication that was administered. This is either a link to a resource representing the details of the medication or a simple attribute carrying a code that identifies the medication from a known list of medications.", - ) - subject_field: Reference = Field( - default=None, - alias="subject", - description="The person or animal or group receiving the medication.", - ) - encounter_field: Reference = Field( - default=None, - alias="encounter", - description="The visit, admission, or other contact between patient and health care provider during which the medication administration was performed.", - ) - supportingInformation_field: List[Reference] = Field( - default=None, - alias="supportingInformation", - description="Additional information (for example, patient height and weight) that supports the administration of the medication. This attribute can be used to provide documentation of specific characteristics of the patient present at the time of administration. For example, if the dose says give x if the heartrate exceeds y, then the heart rate can be included using this attribute.", - ) - occurencePeriod_field: Period = Field( - default=None, - alias="occurencePeriod", - description="A specific date/time or interval of time during which the administration took place (or did not take place). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.", - ) - occurenceTiming_field: Timing = Field( - default=None, - alias="occurenceTiming", - description="A specific date/time or interval of time during which the administration took place (or did not take place). For many administrations, such as swallowing a tablet the use of dateTime is more appropriate.", - ) - recorded_field: dateTimeModel = Field( - default=None, - alias="recorded", - description="The date the occurrence of the MedicationAdministration was first captured in the record - potentially significantly after the occurrence of the event.", - ) - isSubPotent_field: booleanModel = Field( - default=None, - alias="isSubPotent", - description="An indication that the full dose was not administered.", - ) - subPotentReason_field: List[CodeableConcept] = Field( - default=None, - alias="subPotentReason", - description="The reason or reasons why the full dose was not administered.", - ) - performer_field: List[MedicationAdministrationPerformer] = Field( - default=None, - alias="performer", - description="The performer of the medication treatment. For devices this is the device that performed the administration of the medication. An IV Pump would be an example of a device that is performing the administration. Both the IV Pump and the practitioner that set the rate or bolus on the pump can be listed as performers.", - ) - reason_field: List[CodeableReference] = Field( - default=None, - alias="reason", - description="A code, Condition or observation that supports why the medication was administered.", - ) - request_field: Reference = Field( - default=None, - alias="request", - description="The original request, instruction or authority to perform the administration.", - ) - device_field: List[CodeableReference] = Field( - default=None, - alias="device", - description="The device that is to be used for the administration of the medication (for example, PCA Pump).", - ) - note_field: List[Annotation] = Field( - default=None, - alias="note", - description="Extra information about the medication administration that is not conveyed by the other attributes.", - ) - dosage_field: MedicationAdministrationDosage = Field( - default=None, - alias="dosage", - description="Describes the medication dosage information details e.g. dose, rate, site, route, etc.", - ) - eventHistory_field: List[Reference] = Field( - default=None, - alias="eventHistory", - description="A summary of the events of interest that have occurred, such as when the administration was verified.", - ) diff --git a/healthchain/fhir_resources/medicationrequest.py b/healthchain/fhir_resources/medicationrequest.py deleted file mode 100644 index c2114e2f..00000000 --- a/healthchain/fhir_resources/medicationrequest.py +++ /dev/null @@ -1,353 +0,0 @@ -from pydantic import BaseModel, Field -from typing import List, Literal - -from healthchain.fhir_resources.primitives import ( - stringModel, - idModel, - uriModel, - codeModel, - dateTimeModel, - booleanModel, - integerModel, -) -from healthchain.fhir_resources.generalpurpose import ( - Extension, - Identifier, - CodeableConcept, - Reference, - Period, - CodeableReference, - Narrative, - Range, - Ratio, - Quantity, - Meta, -) - - -# TODO: Implement RatioModel and TimingModel -class DosageDoseAndRate(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - type_field: CodeableConcept = Field( - default=None, - alias="type", - description="The kind of dose or rate specified, for example, ordered or calculated.", - ) - doseRange_field: Range = Field( - default=None, alias="doseRange", description="Amount of medication per dose." - ) - doseQuantity_field: Quantity = Field( - default=None, alias="doseQuantity", description="Amount of medication per dose." - ) - rateRatio_field: Ratio = Field( - default=None, - alias="rateRatio", - description="Amount of medication per unit of time.", - ) - rateRange_field: Range = Field( - default=None, - alias="rateRange", - description="Amount of medication per unit of time.", - ) - rateQuantity_field: Quantity = Field( - default=None, - alias="rateQuantity", - description="Amount of medication per unit of time.", - ) - - -class Dosage(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - sequence_field: integerModel = Field( - default=None, - alias="sequence", - description="Indicates the order in which the dosage instructions should be applied or interpreted.", - ) - text_field: stringModel = Field( - default=None, - alias="text", - description="Free text dosage instructions e.g. SIG.", - ) - additionalInstruction_field: List[CodeableConcept] = Field( - default=None, - alias="additionalInstruction", - description="Supplemental instructions to the patient on how to take the medication (e.g. with meals ortake half to one hour before food) or warnings for the patient about the medication (e.g. may cause drowsiness or avoid exposure of skin to direct sunlight or sunlamps).", - ) - patientInstruction_field: stringModel = Field( - default=None, - alias="patientInstruction", - description="Instructions in terms that are understood by the patient or consumer.", - ) - # timing_field: TimingModel = Field( - # default=None, - # alias="timing", - # description="When medication should be administered.", - # ) - asNeeded_field: booleanModel = Field( - default=None, - alias="asNeeded", - description="Indicates whether the Medication is only taken when needed within a specific dosing schedule (Boolean option).", - ) - asNeededFor_field: List[CodeableConcept] = Field( - default=None, - alias="asNeededFor", - description="Indicates whether the Medication is only taken based on a precondition for taking the Medication (CodeableConcept).", - ) - site_field: CodeableConcept = Field( - default=None, alias="site", description="Body site to administer to." - ) - route_field: CodeableConcept = Field( - default=None, alias="route", description="How drug should enter body." - ) - method_field: CodeableConcept = Field( - default=None, - alias="method", - description="Technique for administering medication.", - ) - doseAndRate_field: List[DosageDoseAndRate] = Field( - default=None, - alias="doseAndRate", - description="Depending on the resource,this is the amount of medication administered, to be administered or typical amount to be administered.", - ) - maxDosePerPeriod_field: List[Ratio] = Field( - default=None, - alias="maxDosePerPeriod", - description="Upper limit on medication per unit of time.", - ) - maxDosePerAdministration_field: Quantity = Field( - default=None, - alias="maxDosePerAdministration", - description="Upper limit on medication per administration.", - ) - maxDosePerLifetime_field: Quantity = Field( - default=None, - alias="maxDosePerLifetime", - description="Upper limit on medication per lifetime of the patient.", - ) - - -class Medication(BaseModel): - code_field: CodeableConcept = Field( - default=None, alias="code", description="Identifies the item being prescribed." - ) - - -class MedicationRequest(BaseModel): - resourceType: Literal["MedicationRequest"] = "MedicationRequest" - id_field: idModel = Field( - default=None, - alias="id", - description="The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.", - ) - meta_field: Meta = Field( - default=None, - alias="meta", - description="The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.", - ) - implicitRules_field: uriModel = Field( - default=None, - alias="implicitRules", - description="A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.", - ) - language_field: codeModel = Field( - default=None, - alias="language", - description="The base language in which the resource is written.", - ) - text_field: Narrative = Field( - default=None, - alias="text", - description="A human-readable narrative that contains a summary of the resource and can be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it clinically safe for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", - ) - contained_field: List[Medication] = Field( - default=None, - alias="contained", - description="These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, nor can they have their own independent transaction scope. This is allowed to be a Parameters resource if and only if it is referenced by a resource that provides context/meaning.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the resource. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the resource and that modifies the understanding of the element that contains it and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - identifier_field: List[Identifier] = Field( - default=None, - alias="identifier", - description="Identifiers associated with this medication request that are defined by business processes and/or used to refer to it when a direct URL reference to the resource itself is not appropriate. They are business identifiers assigned to this resource by the performer or other systems and remain constant as the resource is updated and propagates from server to server.", - ) - basedOn_field: List[Reference] = Field( - default=None, - alias="basedOn", - description="A plan or request that is fulfilled in whole or in part by this medication request.", - ) - priorPrescription_field: Reference = Field( - default=None, - alias="priorPrescription", - description="Reference to an order/prescription that is being replaced by this MedicationRequest.", - ) - groupIdentifier_field: Identifier = Field( - default=None, - alias="groupIdentifier", - description="A shared identifier common to multiple independent Request instances that were activated/authorized more or less simultaneously by a single author. The presence of the same identifier on each request ties those requests together and may have business ramifications in terms of reporting of results, billing, etc. E.g. a requisition number shared by a set of lab tests ordered together, or a prescription number shared by all meds ordered at one time.", - ) - status_field: codeModel = Field( - default=None, - alias="status", - description="A code specifying the current state of the order. Generally, this will be active or completed state.", - ) - statusReason_field: CodeableConcept = Field( - default=None, - alias="statusReason", - description="Captures the reason for the current state of the MedicationRequest.", - ) - statusChanged_field: dateTimeModel = Field( - default=None, - alias="statusChanged", - description="The date (and perhaps time) when the status was changed.", - ) - intent_field: codeModel = Field( - default=None, - alias="intent", - description="Whether the request is a proposal, plan, or an original order.", - ) - category_field: List[CodeableConcept] = Field( - default=None, - alias="category", - description="An arbitrary categorization or grouping of the medication request. It could be used for indicating where meds are intended to be administered, eg. in an inpatient setting or in a patient's home, or a legal category of the medication.", - ) - priority_field: codeModel = Field( - default=None, - alias="priority", - description="Indicates how quickly the Medication Request should be addressed with respect to other requests.", - ) - doNotPerform_field: booleanModel = Field( - default=None, - alias="doNotPerform", - description="If true, indicates that the provider is asking for the patient to either stop taking or to not start taking the specified medication. For example, the patient is taking an existing medication and the provider is changing their medication. They want to create two seperate requests: one to stop using the current medication and another to start the new medication.", - ) - medication_field: CodeableReference = Field( - default=None, - alias="medication", - description="Identifies the medication being requested. This is a link to a resource that represents the medication which may be the details of the medication or simply an attribute carrying a code that identifies the medication from a known list of medications.", - ) - subject_field: Reference = Field( - default=None, - alias="subject", - description="The individual or group for whom the medication has been requested.", - ) - informationSource_field: List[Reference] = Field( - default=None, - alias="informationSource", - description="The person or organization who provided the information about this request, if the source is someone other than the requestor. This is often used when the MedicationRequest is reported by another person.", - ) - encounter_field: Reference = Field( - default=None, - alias="encounter", - description="The Encounter during which this [x] was created or to which the creation of this record is tightly associated.", - ) - supportingInformation_field: List[Reference] = Field( - default=None, - alias="supportingInformation", - description="Information to support fulfilling (i.e. dispensing or administering) of the medication, for example, patient height and weight, a MedicationStatement for the patient).", - ) - authoredOn_field: dateTimeModel = Field( - default=None, - alias="authoredOn", - description="The date (and perhaps time) when the prescription was initially written or authored on.", - ) - requester_field: Reference = Field( - default=None, - alias="requester", - description="The individual, organization, or device that initiated the request and has responsibility for its activation.", - ) - reported_field: booleanModel = Field( - default=None, - alias="reported", - description="Indicates if this record was captured as a secondary 'reported' record rather than as an original primary source-of-truth record. It may also indicate the source of the report.", - ) - performerType_field: CodeableConcept = Field( - default=None, - alias="performerType", - description="Indicates the type of performer of the administration of the medication.", - ) - performer_field: List[Reference] = Field( - default=None, - alias="performer", - description="The specified desired performer of the medication treatment (e.g. the performer of the medication administration). For devices, this is the device that is intended to perform the administration of the medication. An IV Pump would be an example of a device that is performing the administration. Both the IV Pump and the practitioner that set the rate or bolus on the pump can be listed as performers.", - ) - device_field: List[CodeableReference] = Field( - default=None, - alias="device", - description="The intended type of device that is to be used for the administration of the medication (for example, PCA Pump).", - ) - recorder_field: Reference = Field( - default=None, - alias="recorder", - description="The person who entered the order on behalf of another individual for example in the case of a verbal or a telephone order.", - ) - reason_field: List[CodeableReference] = Field( - default=None, - alias="reason", - description="The reason or the indication for ordering or not ordering the medication.", - ) - courseOfTherapyType_field: CodeableConcept = Field( - default=None, - alias="courseOfTherapyType", - description="The description of the overall pattern of the administration of the medication to the patient.", - ) - insurance_field: List[Reference] = Field( - default=None, - alias="insurance", - description="Insurance plans, coverage extensions, pre-authorizations and/or pre-determinations that may be required for delivering the requested service.", - ) - # note_field: List[AnnotationModel] = Field(default=None, alias="note", description="Extra information about the prescription that could not be conveyed by the other attributes.") - # renderedDosageInstruction_field: markdownModel = Field(default=None, alias="renderedDosageInstruction", description="The full representation of the dose of the medication included in all dosage instructions. To be used when multiple dosage instructions are included to represent complex dosing such as increasing or tapering doses.") - effectiveDosePeriod_field: Period = Field( - default=None, - alias="effectiveDosePeriod", - description="The period over which the medication is to be taken. Where there are multiple dosageInstruction lines (for example, tapering doses), this is the earliest date and the latest end date of the dosageInstructions.", - ) - dosageInstruction_field: List[Dosage] = Field( - default=None, - alias="dosageInstruction", - description="Specific instructions for how the medication is to be used by the patient.", - ) - # dispenseRequest_field: MedicationRequest_DispenseRequestModel = Field(default=None, alias="dispenseRequest", description="Indicates the specific details for the dispense or medication supply part of a medication request (also known as a Medication Prescription or Medication Order). Note that this information is not always sent with the order. There may be in some settings (e.g. hospitals) institutional or system support for completing the dispense details in the pharmacy department.") - # substitution_field: MedicationRequest_SubstitutionModel = Field(default=None, alias="substitution", description="Indicates whether or not substitution can or should be part of the dispense. In some cases, substitution must happen, in other cases substitution must not happen. This block explains the prescriber's intent. If nothing is specified substitution may be done.") - eventHistory_field: List[Reference] = Field( - default=None, - alias="eventHistory", - description="Links to Provenance records for past versions of this resource or fulfilling request or event resources that identify key state transitions or updates that are likely to be relevant to a user looking at the current version of the resource.", - ) diff --git a/healthchain/fhir_resources/patient.py b/healthchain/fhir_resources/patient.py deleted file mode 100644 index 5d5c73ca..00000000 --- a/healthchain/fhir_resources/patient.py +++ /dev/null @@ -1,378 +0,0 @@ -from pydantic import Field, BaseModel -from typing import List, Literal - -from healthchain.fhir_resources.primitives import ( - idModel, - uriModel, - codeModel, - booleanModel, - stringModel, - positiveIntModel, - dateModel, -) -from healthchain.fhir_resources.generalpurpose import ( - Identifier, - Reference, - Extension, - Period, - CodeableConcept, - Meta, - Narrative, -) - - -class Address(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - use_field: codeModel = Field( - default=None, alias="use", description="The purpose of this address." - ) - type_field: codeModel = Field( - default=None, - alias="type", - description="Distinguishes between physical addresses (those you can visit) and mailing addresses (e.g. PO Boxes and care-of addresses). Most addresses are both.", - ) - text_field: stringModel = Field( - default=None, - alias="text", - description="Specifies the entire address as it should be displayed e.g. on a postal label. This may be provided instead of or as well as the specific parts.", - ) - line_field: List[stringModel] = Field( - default=None, - alias="line", - description="This component contains the house number, apartment number, street name, street direction, P.O. Box number, delivery hints, and similar address information.", - ) - city_field: stringModel = Field( - default=None, - alias="city", - description="The name of the city, town, suburb, village or other community or delivery center.", - ) - district_field: stringModel = Field( - default=None, - alias="district", - description="The name of the administrative area (county).", - ) - state_field: stringModel = Field( - default=None, - alias="state", - description="Sub-unit of a country with limited sovereignty in a federally organized country. A code may be used if codes are in common use (e.g. US 2 letter state codes).", - ) - postalCode_field: stringModel = Field( - default=None, - alias="postalCode", - description="A postal code designating a region defined by the postal service.", - ) - country_field: stringModel = Field( - default=None, - alias="country", - description="Country - a nation as commonly understood or generally accepted.", - ) - period_field: Period = Field( - default=None, - alias="period", - description="Time period when address was/is in use.", - ) - - -class ContactPoint(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - system_field: codeModel = Field( - default=None, - alias="system", - description="Telecommunications form for contact point - what communications system is required to make use of the contact.", - ) - value_field: stringModel = Field( - default=None, - alias="value", - description="The actual contact point details, in a form that is meaningful to the designated communication system (i.e. phone number or email address).", - ) - use_field: codeModel = Field( - default=None, - alias="use", - description="Identifies the purpose for the contact point.", - ) - rank_field: positiveIntModel = Field( - default=None, - alias="rank", - description="Specifies a preferred order in which to use a set of contacts. ContactPoints with lower rank values are more preferred than those with higher rank values.", - ) - period_field: Period = Field( - default=None, - alias="period", - description="Time period when the contact point was/is in use.", - ) - - -class HumanName(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - use_field: codeModel = Field( - default=None, alias="use", description="Identifies the purpose for this name." - ) - text_field: stringModel = Field( - default=None, - alias="text", - description="Specifies the entire name as it should be displayed e.g. on an application UI. This may be provided instead of or as well as the specific parts.", - ) - family_field: stringModel = Field( - default=None, - alias="family", - description="The part of a name that links to the genealogy. In some cultures (e.g. Eritrea) the family name of a son is the first name of his father.", - ) - given_field: List[stringModel] = Field( - default=None, alias="given", description="Given name." - ) - prefix_field: List[stringModel] = Field( - default=None, - alias="prefix", - description="Part of the name that is acquired as a title due to academic, legal, employment or nobility status, etc. and that appears at the start of the name.", - ) - suffix_field: List[stringModel] = Field( - default=None, - alias="suffix", - description="Part of the name that is acquired as a title due to academic, legal, employment or nobility status, etc. and that appears at the end of the name.", - ) - period_field: Period = Field( - default=None, - alias="period", - description="Indicates the period of time when this name was valid for the named person.", - ) - - -class PatientLink(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - other_field: Reference = Field( - default=None, - alias="other", - description="Link to a Patient or RelatedPerson resource that concerns the same actual individual.", - ) - type_field: codeModel = Field( - default=None, - alias="type", - description="The type of link between this patient resource and another patient resource.", - ) - - -class PatientContact(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - relationship_field: List[CodeableConcept] = Field( - default=None, - alias="relationship", - description="The nature of the relationship between the patient and the contact person.", - ) - name_field: HumanName = Field( - default=None, - alias="name", - description="A name associated with the contact person.", - ) - telecom_field: List[ContactPoint] = Field( - default=None, - alias="telecom", - description="A contact detail for the person, e.g. a telephone number or an email address.", - ) - address_field: Address = Field( - default=None, alias="address", description="Address for the contact person." - ) - gender_field: codeModel = Field( - default=None, - alias="gender", - description="Administrative Gender - the gender that the contact person is considered to have for administration and record keeping purposes.", - ) - organization_field: Reference = Field( - default=None, - alias="organization", - description="Organization on behalf of which the contact is acting or for which the contact is working.", - ) - period_field: Period = Field( - default=None, - alias="period", - description="The period during which this contact person or organization is valid to be contacted relating to this patient.", - ) - - -class PatientCommunication(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - language_field: CodeableConcept = Field( - default=None, - alias="language", - description="The ISO-639-1 alpha 2 code in lower case for the language, optionally followed by a hyphen and the ISO-3166-1 alpha 2 code for the region in upper case; e.g. en for English, or en-US for American English versus en-AU for Australian English.", - ) - preferred_field: booleanModel = Field( - default=None, - alias="preferred", - description="Indicates whether or not the patient prefers this language (over other languages he masters up a certain level).", - ) - - -class Patient(BaseModel): - resourceType: Literal["Patient"] = "Patient" - id_field: idModel = Field( - default=None, - alias="id", - description="The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.", - ) - meta_field: Meta = Field( - default=None, - alias="meta", - description="The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.", - ) - implicitRules_field: uriModel = Field( - default=None, - alias="implicitRules", - description="A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.", - ) - language_field: codeModel = Field( - default=None, - alias="language", - description="The base language in which the resource is written.", - ) - # NOTE: The text field has been switched to stringModel rather than NarrativeField for simplicity. - text_field: Narrative = Field( - default=None, - alias="text", - description="A human-readable narrative that contains a summary of the resource and can be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it clinically safe for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", - ) - # contained_field: List[ResourceListModel] = Field(default=None, alias="contained", description="These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, nor can they have their own independent transaction scope. This is allowed to be a Parameters resource if and only if it is referenced by a resource that provides context/meaning.") - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the resource. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the resource and that modifies the understanding of the element that contains it and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - identifier_field: List[Identifier] = Field( - default=None, - alias="identifier", - description="An identifier for this patient.", - ) - active_field: booleanModel = Field( - default=None, - alias="active", - description="Whether this patient record is in active use. ", - ) - name_field: List[HumanName] = Field( - default=None, - alias="name", - description="A name associated with the individual.", - ) - telecom_field: List[ContactPoint] = Field( - default=None, - alias="telecom", - description="A contact detail (e.g. a telephone number or an email address) by which the individual may be contacted.", - ) - gender_field: codeModel = Field( - default=None, - alias="gender", - description="Administrative Gender - the gender that the patient is considered to have for administration and record keeping purposes.", - ) - birthDate_field: dateModel = Field( - default=None, - alias="birthDate", - description="The date of birth for the individual.", - ) - address_field: List[Address] = Field( - default=None, - alias="address", - description="An address for the individual.", - ) - maritalStatus_field: CodeableConcept = Field( - default=None, - alias="maritalStatus", - description="This field contains a patient's most recent marital (civil) status.", - ) - # photo_field: List[AttachmentModel] = Field(default=None, alias="photo", description="Image of the patient.") - contact_field: List[PatientContact] = Field( - default=None, - alias="contact", - description="A contact party (e.g. guardian, partner, friend) for the patient.", - ) - communication_field: List[PatientCommunication] = Field( - default=None, - alias="communication", - description="A language which may be used to communicate with the patient about his or her health.", - ) - generalPractitioner_field: List[Reference] = Field( - default=None, - alias="generalPractitioner", - description="Patient's nominated care provider.", - ) - managingOrganization_field: Reference = Field( - default=None, - alias="managingOrganization", - description="Organization that is the custodian of the patient record.", - ) - link_field: List[PatientLink] = Field( - default=None, - alias="link", - description="Link to a Patient or RelatedPerson resource that concerns the same actual individual.", - ) diff --git a/healthchain/fhir_resources/practitioner.py b/healthchain/fhir_resources/practitioner.py deleted file mode 100644 index ca7ced08..00000000 --- a/healthchain/fhir_resources/practitioner.py +++ /dev/null @@ -1,177 +0,0 @@ -from pydantic import Field, BaseModel -from typing import List, Literal - -from healthchain.fhir_resources.primitives import ( - idModel, - uriModel, - codeModel, - booleanModel, - stringModel, - dateModel, -) -from healthchain.fhir_resources.generalpurpose import ( - Identifier, - Reference, - Extension, - Period, - CodeableConcept, - Meta, - Narrative, -) -from healthchain.fhir_resources.patient import ( - HumanName, - ContactPoint, - Address, -) - - -class PractitionerQualification(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - identifier_field: List[Identifier] = Field( - default=None, - alias="identifier", - description="An identifier that applies to this person's qualification.", - ) - code_field: CodeableConcept = Field( - default=None, - alias="code", - description="Coded representation of the qualification.", - ) - period_field: Period = Field( - default=None, - alias="period", - description="Period during which the qualification is valid.", - ) - issuer_field: Reference = Field( - default=None, - alias="issuer", - description="Organization that regulates and issues the qualification.", - ) - - -class PractitionerCommunication(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - language_field: CodeableConcept = Field( - default=None, - alias="language", - description="The ISO-639-1 alpha 2 code in lower case for the language, optionally followed by a hyphen and the ISO-3166-1 alpha 2 code for the region in upper case; e.g. en for English, or en-US for American English versus en-AU for Australian English.", - ) - preferred_field: booleanModel = Field( - default=None, - alias="preferred", - description="Indicates whether or not the person prefers this language (over other languages he masters up a certain level).", - ) - - -class Practitioner(BaseModel): - resourceType: Literal["Practitioner"] = "Practitioner" - id_field: idModel = Field( - default=None, - alias="id", - description="The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.", - ) - meta_field: Meta = Field( - default=None, - alias="meta", - description="The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.", - ) - implicitRules_field: uriModel = Field( - default=None, - alias="implicitRules", - description="A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.", - ) - language_field: codeModel = Field( - default=None, - alias="language", - description="The base language in which the resource is written.", - ) - text_field: Narrative = Field( - default=None, - alias="text", - description="A human-readable narrative that contains a summary of the resource and can be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it clinically safe for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", - ) - # contained_field: List[ResourceListModel] = Field(default=None, alias="contained", description="These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, nor can they have their own independent transaction scope. This is allowed to be a Parameters resource if and only if it is referenced by a resource that provides context/meaning.") - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the resource. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the resource and that modifies the understanding of the element that contains it and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - identifier_field: List[Identifier] = Field( - default=None, - alias="identifier", - description="An identifier that applies to this person in this role.", - ) - active_field: booleanModel = Field( - default=None, - alias="active", - description="Whether this practitioner's record is in active use.", - ) - name_field: List[HumanName] = Field( - default=None, - alias="name", - description="The name(s) associated with the practitioner.", - ) - telecom_field: List[ContactPoint] = Field( - default=None, - alias="telecom", - description="A contact detail for the practitioner, e.g. a telephone number or an email address.", - ) - gender_field: codeModel = Field( - default=None, - alias="gender", - description="Administrative Gender - the gender that the person is considered to have for administration and record keeping purposes.", - ) - birthDate_field: dateModel = Field( - default=None, - alias="birthDate", - description="The date of birth for the practitioner.", - ) - address_field: List[Address] = Field( - default=None, - alias="address", - description="Address(es) of the practitioner that are not role specific (typically home address). ", - ) - # photo_field: List[AttachmentModel] = Field(default=None, alias="photo", description="Image of the person.") - qualification_field: List[PractitionerQualification] = Field( - default=None, - alias="qualification", - description="The official qualifications, certifications, accreditations, training, licenses (and other types of educations/skills/capabilities) that authorize or otherwise pertain to the provision of care by the practitioner.", - ) - communication_field: List[PractitionerCommunication] = Field( - default=None, - alias="communication", - description="A language which may be used to communicate with the practitioner, often for correspondence/administrative purposes.", - ) diff --git a/healthchain/fhir_resources/primitives.py b/healthchain/fhir_resources/primitives.py deleted file mode 100644 index 22cacad5..00000000 --- a/healthchain/fhir_resources/primitives.py +++ /dev/null @@ -1,38 +0,0 @@ -from __future__ import annotations - -from pydantic import conint -from pydantic import constr - - -booleanModel = constr(pattern=r"^(true|false)$") -canonicalModel = constr(pattern=r"^\S*$") -codeModel = constr(pattern=r"^[^\s]+( [^\s]+)*$") -comparatorModel = constr(pattern="^(<|<=|>=|>)$") -dateModel = constr( - pattern=r"^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1]))?)?$" -) -dateTimeModel = constr( - pattern=r"^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\.[0-9]{1,9})?)?)?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)?)?)?$" -) -decimalModel = constr( - pattern=r"^-?(0|[1-9][0-9]{0,17})(\.[0-9]{1,17})?([eE][+-]?[0-9]{1,9}})?$" -) -idModel = constr(pattern=r"^[A-Za-z0-9\-\.]{1,64}$") -instantModel = constr( - pattern=r"^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\.[0-9]{1,9})?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00))$" -) -integerModel = constr(pattern=r"^[0]|[-+]?[1-9][0-9]*$") -integer64Model = constr(pattern=r"^[0]|[-+]?[1-9][0-9]*$") -markdownModel = constr(pattern=r"^^[\s\S]+$$") -oidModel = constr(pattern=r"^urn:oid:[0-2](\.(0|[1-9][0-9]*))+$") -positiveIntModel = conint(strict=True, gt=0) -stringModel = constr(pattern=r"^^[\s\S]+$$") -timeModel = constr( - pattern=r"^([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\.[0-9]{1,9})?$" -) -unsignedIntModel = constr(pattern=r"^[0]|([1-9][0-9]*)$") -uriModel = constr(pattern=r"^\S*$") -urlModel = constr(pattern=r"^\S*$") -uuidModel = constr( - pattern=r"^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$" -) diff --git a/healthchain/fhir_resources/procedure.py b/healthchain/fhir_resources/procedure.py deleted file mode 100644 index f05643e5..00000000 --- a/healthchain/fhir_resources/procedure.py +++ /dev/null @@ -1,289 +0,0 @@ -from pydantic import BaseModel, Field -from typing import List, Literal - -from healthchain.fhir_resources.primitives import ( - stringModel, - idModel, - uriModel, - codeModel, - dateTimeModel, - canonicalModel, -) -from healthchain.fhir_resources.generalpurpose import ( - Extension, - Identifier, - CodeableConcept, - Reference, - Period, - CodeableReference, - Narrative, - Age, - Range, - Meta, - Timing, -) - - -class ProcedurePerformer(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - function_field: CodeableConcept = Field( - default=None, - alias="function", - description="Distinguishes the type of involvement of the performer in the procedure. For example, surgeon, anaesthetist, endoscopist.", - ) - actor_field: Reference = Field( - default=None, - alias="actor", - description="Indicates who or what performed the procedure.", - ) - onBehalfOf_field: Reference = Field( - default=None, - alias="onBehalfOf", - description="The Organization the Patient, RelatedPerson, Device, CareTeam, and HealthcareService was acting on behalf of.", - ) - period_field: Period = Field( - default=None, - alias="period", - description="Time period during which the performer performed the procedure.", - ) - - -class ProcedureFocalDevice(BaseModel): - id_field: stringModel = Field( - default=None, - alias="id", - description="Unique id for the element within a resource (for internal references). This may be any string value that does not contain spaces.", - ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the element. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - action_field: CodeableConcept = Field( - default=None, - alias="action", - description="The kind of change that happened to the device during the procedure.", - ) - manipulated_field: Reference = Field( - default=None, - alias="manipulated", - description="The device that was manipulated (changed) during the procedure.", - ) - - -class Procedure(BaseModel): - resourceType: Literal["Procedure"] = "Procedure" - id_field: idModel = Field( - default=None, - alias="id", - description="The logical id of the resource, as used in the URL for the resource. Once assigned, this value never changes.", - ) - meta_field: Meta = Field( - default=None, - alias="meta", - description="The metadata about the resource. This is content that is maintained by the infrastructure. Changes to the content might not always be associated with version changes to the resource.", - ) - implicitRules_field: uriModel = Field( - default=None, - alias="implicitRules", - description="A reference to a set of rules that were followed when the resource was constructed, and which must be understood when processing the content. Often, this is a reference to an implementation guide that defines the special rules along with other profiles etc.", - ) - language_field: codeModel = Field( - default=None, - alias="language", - description="The base language in which the resource is written.", - ) - text_field: Narrative = Field( - default=None, - alias="text", - description="A human-readable narrative that contains a summary of the resource and can be used to represent the content of the resource to a human. The narrative need not encode all the structured data, but is required to contain sufficient detail to make it clinically safe for a human to just read the narrative. Resource definitions may define what content should be represented in the narrative to ensure clinical safety.", - ) - # contained_field: List[ResourceListModel] = Field( - # default=None, - # alias="contained", - # description="These resources do not have an independent existence apart from the resource that contains them - they cannot be identified independently, nor can they have their own independent transaction scope. This is allowed to be a Parameters resource if and only if it is referenced by a resource that provides context/meaning.", - # ) - extension_field: List[Extension] = Field( - default=None, - alias="extension", - description="May be used to represent additional information that is not part of the basic definition of the resource. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension.", - ) - modifierExtension_field: List[Extension] = Field( - default=None, - alias="modifierExtension", - description="May be used to represent additional information that is not part of the basic definition of the resource and that modifies the understanding of the element that contains it and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer is allowed to define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.", - ) - identifier_field: List[Identifier] = Field( - default=None, - alias="identifier", - description="Business identifiers assigned to this procedure by the performer or other systems which remain constant as the resource is updated and is propagated from server to server.", - ) - instantiatesCanonical_field: List[canonicalModel] = Field( - default=None, - alias="instantiatesCanonical", - description="The URL pointing to a FHIR-defined protocol, guideline, order set or other definition that is adhered to in whole or in part by this Procedure.", - ) - instantiatesUri_field: List[uriModel] = Field( - default=None, - alias="instantiatesUri", - description="The URL pointing to an externally maintained protocol, guideline, order set or other definition that is adhered to in whole or in part by this Procedure.", - ) - basedOn_field: List[Reference] = Field( - default=None, - alias="basedOn", - description="A reference to a resource that contains details of the request for this procedure.", - ) - partOf_field: List[Reference] = Field( - default=None, - alias="partOf", - description="A larger event of which this particular procedure is a component or step.", - ) - status_field: codeModel = Field( - default=None, - alias="status", - description="A code specifying the state of the procedure. Generally, this will be the in-progress or completed state.", - ) - statusReason_field: CodeableConcept = Field( - default=None, - alias="statusReason", - description="Captures the reason for the current state of the procedure.", - ) - category_field: List[CodeableConcept] = Field( - default=None, - alias="category", - description="A code that classifies the procedure for searching, sorting and display purposes (e.g. Surgical Procedure).", - ) - code_field: CodeableConcept = Field( - default=None, - alias="code", - description="The specific procedure that is performed. Use text if the exact nature of the procedure cannot be coded (e.g. Laparoscopic Appendectomy).", - ) - subject_field: Reference = Field( - default=None, - alias="subject", - description="On whom or on what the procedure was performed. This is usually an individual human, but can also be performed on animals, groups of humans or animals, organizations or practitioners (for licensing), locations or devices (for safety inspections or regulatory authorizations). If the actual focus of the procedure is different from the subject, the focus element specifies the actual focus of the procedure.", - ) - focus_field: Reference = Field( - default=None, - alias="focus", - description="Who is the target of the procedure when it is not the subject of record only. If focus is not present, then subject is the focus. If focus is present and the subject is one of the targets of the procedure, include subject as a focus as well. If focus is present and the subject is not included in focus, it implies that the procedure was only targeted on the focus. For example, when a caregiver is given education for a patient, the caregiver would be the focus and the procedure record is associated with the subject (e.g. patient). For example, use focus when recording the target of the education, training, or counseling is the parent or relative of a patient.", - ) - encounter_field: Reference = Field( - default=None, - alias="encounter", - description="The Encounter during which this Procedure was created or performed or to which the creation of this record is tightly associated.", - ) - occurrencePeriod_field: Period = Field( - default=None, - alias="occurrencePeriod", - description="Estimated or actual date, date-time, period, or age when the procedure did occur or is occurring. Allows a period to support complex procedures that span more than one date, and also allows for the length of the procedure to be captured.", - ) - occurrenceAge_field: Age = Field( - default=None, - alias="occurrenceAge", - description="Estimated or actual date, date-time, period, or age when the procedure did occur or is occurring. Allows a period to support complex procedures that span more than one date, and also allows for the length of the procedure to be captured.", - ) - occurrenceRange_field: Range = Field( - default=None, - alias="occurrenceRange", - description="Estimated or actual date, date-time, period, or age when the procedure did occur or is occurring. Allows a period to support complex procedures that span more than one date, and also allows for the length of the procedure to be captured.", - ) - occurrenceTiming_field: Timing = Field( - default=None, - alias="occurrenceTiming", - description="Estimated or actual date, date-time, period, or age when the procedure did occur or is occurring. Allows a period to support complex procedures that span more than one date, and also allows for the length of the procedure to be captured.", - ) - recorded_field: dateTimeModel = Field( - default=None, - alias="recorded", - description="The date the occurrence of the procedure was first captured in the record regardless of Procedure.status (potentially after the occurrence of the event).", - ) - recorder_field: Reference = Field( - default=None, - alias="recorder", - description="Individual who recorded the record and takes responsibility for its content.", - ) - reportedReference_field: Reference = Field( - default=None, - alias="reportedReference", - description="Indicates if this record was captured as a secondary 'reported' record rather than as an original primary source-of-truth record. It may also indicate the source of the report.", - ) - performer_field: List[ProcedurePerformer] = Field( - default=None, - alias="performer", - description="Indicates who or what performed the procedure and how they were involved.", - ) - location_field: Reference = Field( - default=None, - alias="location", - description="The location where the procedure actually happened. E.g. a newborn at home, a tracheostomy at a restaurant.", - ) - reason_field: List[CodeableReference] = Field( - default=None, - alias="reason", - description="The coded reason or reference why the procedure was performed. This may be a coded entity of some type, be present as text, or be a reference to one of several resources that justify the procedure.", - ) - bodySite_field: List[CodeableConcept] = Field( - default=None, - alias="bodySite", - description="Detailed and structured anatomical location information. Multiple locations are allowed - e.g. multiple punch biopsies of a lesion.", - ) - outcome_field: CodeableConcept = Field( - default=None, - alias="outcome", - description="The outcome of the procedure - did it resolve the reasons for the procedure being performed?", - ) - report_field: List[Reference] = Field( - default=None, - alias="report", - description="This could be a histology result, pathology report, surgical report, etc.", - ) - complication_field: List[CodeableReference] = Field( - default=None, - alias="complication", - description="Any complications that occurred during the procedure, or in the immediate post-performance period. These are generally tracked separately from the notes, which will typically describe the procedure itself rather than any 'post procedure' issues.", - ) - followUp_field: List[CodeableConcept] = Field( - default=None, - alias="followUp", - description="If the procedure required specific follow up - e.g. removal of sutures. The follow up may be represented as a simple note or could potentially be more complex, in which case the CarePlan resource can be used.", - ) - # note_field: List[AnnotationModel] = Field( - # default=None, - # alias="note", - # description="Any other notes and comments about the procedure.", - # ) - focalDevice_field: List[ProcedureFocalDevice] = Field( - default=None, - alias="focalDevice", - description="A device that is implanted, removed or otherwise manipulated (calibration, battery replacement, fitting a prosthesis, attaching a wound-vac, etc.) as a focal portion of the Procedure.", - ) - used_field: List[CodeableReference] = Field( - default=None, - alias="used", - description="Identifies medications, devices and any other substance used as part of the procedure.", - ) - supportingInfo_field: List[Reference] = Field( - default=None, - alias="supportingInfo", - description="Other resources from the patient record that may be relevant to the procedure. The information from these resources was either used to create the instance or is provided to help with its interpretation. This extension should not be used if more specific inline elements or extensions are available.", - ) diff --git a/healthchain/fhir_resources/resourceregistry.py b/healthchain/fhir_resources/resourceregistry.py deleted file mode 100644 index 87f70e38..00000000 --- a/healthchain/fhir_resources/resourceregistry.py +++ /dev/null @@ -1,167 +0,0 @@ -from enum import Enum - - -class ImplementedResourceRegistry(Enum): - Bundle: str = "Bundle" - Encounter: str = "Encounter" - MedicationRequest: str = "MedicationRequest" - NutritionOrder: str = "NutritionOrder" - Patient: str = "Patient" - Practitioner: str = "Practitioner" - Condition: str = "Condition" - Procedure: str = "Procedure" - DocumentReference: str = "DocumentReference" - - -class UnimplementedResourceRegistry(Enum): - Account: str = "Account" - ActivityDefinition: str = "ActivityDefinition" - ActorDefinition: str = "ActorDefinition" - AdministrableProductDefinition: str = "AdministrableProductDefinition" - AdverseEvent: str = "AdverseEvent" - AllergyIntolerance: str = "AllergyIntolerance" - Appointment: str = "Appointment" - AppointmentResponse: str = "AppointmentResponse" - ArtifactAssessment: str = "ArtifactAssessment" - AuditEvent: str = "AuditEvent" - Basic: str = "Basic" - Binary: str = "Binary" - BiologicallyDerivedProduct: str = "BiologicallyDerivedProduct" - BiologicallyDerivedProductDispense: str = "BiologicallyDerivedProductDispense" - BodyStructure: str = "BodyStructure" - CapabilityStatement: str = "CapabilityStatement" - CarePlan: str = "CarePlan" - CareTeam: str = "CareTeam" - ChargeItem: str = "ChargeItem" - ChargeItemDefinition: str = "ChargeItemDefinition" - Citation: str = "Citation" - Claim: str = "Claim" - ClaimResponse: str = "ClaimResponse" - ClinicalImpression: str = "ClinicalImpression" - ClinicalUseDefinition: str = "ClinicalUseDefinition" - CodeSystem: str = "CodeSystem" - Communication: str = "Communication" - CommunicationRequest: str = "CommunicationRequest" - CompartmentDefinition: str = "CompartmentDefinition" - Composition: str = "Composition" - ConceptMap: str = "ConceptMap" - ConditionDefinition: str = "ConditionDefinition" - Consent: str = "Consent" - Contract: str = "Contract" - Coverage: str = "Coverage" - CoverageEligibilityRequest: str = "CoverageEligibilityRequest" - CoverageEligibilityResponse: str = "CoverageEligibilityResponse" - DetectedIssue: str = "DetectedIssue" - Device: str = "Device" - DeviceAssociation: str = "DeviceAssociation" - DeviceDefinition: str = "DeviceDefinition" - DeviceDispense: str = "DeviceDispense" - DeviceMetric: str = "DeviceMetric" - DeviceRequest: str = "DeviceRequest" - DeviceUsage: str = "DeviceUsage" - DiagnosticReport: str = "DiagnosticReport" - Encounter: str = "Encounter" - EncounterHistory: str = "EncounterHistory" - Endpoint: str = "Endpoint" - EnrollmentRequest: str = "EnrollmentRequest" - EnrollmentResponse: str = "EnrollmentResponse" - EpisodeOfCare: str = "EpisodeOfCare" - EventDefinition: str = "EventDefinition" - Evidence: str = "Evidence" - EvidenceReport: str = "EvidenceReport" - EvidenceVariable: str = "EvidenceVariable" - ExampleScenario: str = "ExampleScenario" - ExplanationOfBenefit: str = "ExplanationOfBenefit" - FamilyMemberHistory: str = "FamilyMemberHistory" - Flag: str = "Flag" - FormularyItem: str = "FormularyItem" - GenomicStudy: str = "GenomicStudy" - Goal: str = "Goal" - GraphDefinition: str = "GraphDefinition" - Group: str = "Group" - GuidanceResponse: str = "GuidanceResponse" - HealthcareService: str = "HealthcareService" - ImagingSelection: str = "ImagingSelection" - ImagingStudy: str = "ImagingStudy" - Immunization: str = "Immunization" - ImmunizationEvaluation: str = "ImmunizationEvaluation" - ImmunizationRecommendation: str = "ImmunizationRecommendation" - ImplementationGuide: str = "ImplementationGuide" - Ingredient: str = "Ingredient" - InsurancePlan: str = "InsurancePlan" - InventoryItem: str = "InventoryItem" - InventoryReport: str = "InventoryReport" - Invoice: str = "Invoice" - Library: str = "Library" - Linkage: str = "Linkage" - List: str = "List" - Location: str = "Location" - ManufacturedItemDefinition: str = "ManufacturedItemDefinition" - Measure: str = "Measure" - MeasureReport: str = "MeasureReport" - Medication: str = "Medication" - MedicationAdministration: str = "MedicationAdministration" - MedicationDispense: str = "MedicationDispense" - MedicationKnowledge: str = "MedicationKnowledge" - MedicationStatement: str = "MedicationStatement" - MedicinalProductDefinition: str = "MedicinalProductDefinition" - MessageDefinition: str = "MessageDefinition" - MessageHeader: str = "MessageHeader" - MolecularSequence: str = "MolecularSequence" - NamingSystem: str = "NamingSystem" - NutritionIntake: str = "NutritionIntake" - NutritionProduct: str = "NutritionProduct" - Observation: str = "Observation" - ObservationDefinition: str = "ObservationDefinition" - OperationDefinition: str = "OperationDefinition" - OperationOutcome: str = "OperationOutcome" - Organization: str = "Organization" - OrganizationAffiliation: str = "OrganizationAffiliation" - PackagedProductDefinition: str = "PackagedProductDefinition" - Parameters: str = "Parameters" - PaymentNotice: str = "PaymentNotice" - PaymentReconciliation: str = "PaymentReconciliation" - Permission: str = "Permission" - Person: str = "Person" - PlanDefinition: str = "PlanDefinition" - PractitionerRole: str = "PractitionerRole" - Procedure: str = "Procedure" - Provenance: str = "Provenance" - Questionnaire: str = "Questionnaire" - QuestionnaireResponse: str = "QuestionnaireResponse" - RegulatedAuthorization: str = "RegulatedAuthorization" - RelatedPerson: str = "RelatedPerson" - RequestOrchestration: str = "RequestOrchestration" - Requirements: str = "Requirements" - ResearchStudy: str = "ResearchStudy" - ResearchSubject: str = "ResearchSubject" - RiskAssessment: str = "RiskAssessment" - Schedule: str = "Schedule" - SearchParameter: str = "SearchParameter" - ServiceRequest: str = "ServiceRequest" - Slot: str = "Slot" - Specimen: str = "Specimen" - SpecimenDefinition: str = "SpecimenDefinition" - StructureDefinition: str = "StructureDefinition" - StructureMap: str = "StructureMap" - Subscription: str = "Subscription" - SubscriptionStatus: str = "SubscriptionStatus" - SubscriptionTopic: str = "SubscriptionTopic" - Substance: str = "Substance" - SubstanceDefinition: str = "SubstanceDefinition" - SubstanceNucleicAcid: str = "SubstanceNucleicAcid" - SubstancePolymer: str = "SubstancePolymer" - SubstanceProtein: str = "SubstanceProtein" - SubstanceReferenceInformation: str = "SubstanceReferenceInformation" - SubstanceSourceMaterial: str = "SubstanceSourceMaterial" - SupplyDelivery: str = "SupplyDelivery" - SupplyRequest: str = "SupplyRequest" - Task: str = "Task" - TerminologyCapabilities: str = "TerminologyCapabilities" - TestPlan: str = "TestPlan" - TestReport: str = "TestReport" - TestScript: str = "TestScript" - Transport: str = "Transport" - ValueSet: str = "ValueSet" - VerificationResult: str = "VerificationResult" - VisionPrescription: str = "VisionPrescription" diff --git a/healthchain/models/data/cdsfhirdata.py b/healthchain/models/data/cdsfhirdata.py index e684c0de..b096e01a 100644 --- a/healthchain/models/data/cdsfhirdata.py +++ b/healthchain/models/data/cdsfhirdata.py @@ -3,7 +3,7 @@ from pydantic import BaseModel, Field from typing import Dict -from healthchain.fhir_resources.bundleresources import Bundle +from fhir.resources.bundle import Bundle class CdsFhirData(BaseModel): diff --git a/tests/conftest.py b/tests/conftest.py index fb52a09c..23565d21 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,7 +7,7 @@ from healthchain.base import BaseStrategy, BaseUseCase from healthchain.cda_parser.cdaannotator import CdaAnnotator -from healthchain.fhir_resources.bundleresources import Bundle, BundleEntry +from fhir.resources.bundle import Bundle, BundleEntry from healthchain.models import CDSRequest, CdsFhirData from healthchain.models.data.ccddata import CcdData from healthchain.models.data.concept import ( @@ -51,7 +51,9 @@ class synth_data: class MockDataGenerator: def __init__(self) -> None: - self.data = CdsFhirData(context={}, prefetch=Bundle(entry=[BundleEntry()])) + self.data = CdsFhirData( + context={}, prefetch=Bundle(entry=[BundleEntry()], type="document") + ) # self.data = synth_data(context={}, prefetch=MockBundle()) self.workflow = None diff --git a/tests/fhir_resources_unit_tests/test_fhir_resources_base.py b/tests/fhir_resources_unit_tests/test_fhir_resources_base.py deleted file mode 100644 index 8c3ab427..00000000 --- a/tests/fhir_resources_unit_tests/test_fhir_resources_base.py +++ /dev/null @@ -1,59 +0,0 @@ -import pytest - -from pydantic import BaseModel, ValidationError -from healthchain.fhir_resources.primitives import ( - booleanModel, - canonicalModel, - codeModel, -) - - -class booleanTestModel(BaseModel): - my_bool: booleanModel - - -def test_boolean_valid(): - data = {"my_bool": "true"} - result = booleanTestModel(**data) - assert result.my_bool == "true" - - -def test_boolean_invalid(): - data = {"my_bool": "invalid"} - with pytest.raises(ValidationError): - booleanTestModel(**data) - - -class canonicalTestModel(BaseModel): - my_canonical: canonicalModel - - -def test_canonical_valid(): - data = {"my_canonical": "https://example.com"} - result = canonicalTestModel(**data) - assert result.my_canonical == "https://example.com" - - -def test_canonical_invalid(): - data = {"my_canonical": "invalid url"} - with pytest.raises(ValidationError): - canonicalTestModel(**data) - - -class codeTestModel(BaseModel): - my_code: codeModel - - -def test_code_valid(): - data = {"my_code": "ABC123"} - result = codeTestModel(**data) - assert result.my_code == "ABC123" - - -def test_code_invalid(): - data = {"my_code": "invalid code"} - with pytest.raises(ValidationError): - codeTestModel(**data) - - -# TODO: Add tests for the remaining base resources diff --git a/tests/fhir_resources_unit_tests/test_fhir_resources_bundle.py b/tests/fhir_resources_unit_tests/test_fhir_resources_bundle.py deleted file mode 100644 index 8c46c0f0..00000000 --- a/tests/fhir_resources_unit_tests/test_fhir_resources_bundle.py +++ /dev/null @@ -1,15 +0,0 @@ -from healthchain.fhir_resources.bundleresources import BundleEntry, Bundle -from healthchain.data_generators import PatientGenerator, EncounterGenerator - - -def test_bundle_entry_model(): - patient_generator = PatientGenerator() - patient = patient_generator.generate() - encounter_generator = EncounterGenerator() - encounter = encounter_generator.generate() - - bundle_patient_entry = BundleEntry(resource=patient) - bundle_encounter_entry = BundleEntry(resource=encounter) - bundle = Bundle(entry=[bundle_patient_entry, bundle_encounter_entry]) - assert bundle.entry_field[0].resource_field == patient - assert bundle.entry_field[1].resource_field == encounter diff --git a/tests/fhir_resources_unit_tests/test_fhir_resources_patient.py b/tests/fhir_resources_unit_tests/test_fhir_resources_patient.py deleted file mode 100644 index e88ad3d5..00000000 --- a/tests/fhir_resources_unit_tests/test_fhir_resources_patient.py +++ /dev/null @@ -1,79 +0,0 @@ -import pytest -from healthchain.fhir_resources.patient import ( - Patient, - HumanName, - ContactPoint, - Address, -) - - -# TODO: Refactor pytest fixtures -def test_PatientModel(): - data = { - "resourceType": "Patient", - "name": [{"family": "Doe", "given": ["John"], "prefix": ["Mr."]}], - "birthDate": "1980-01-01", - "gender": "Male", - } - patient = Patient(**data) - patient = patient.model_dump(by_alias=True) - assert patient["resourceType"] == "Patient" - assert patient["name"][0]["given"] == ["John"] - assert patient["birthDate"] == "1980-01-01" - assert patient["gender"] == "Male" - - -def test_PatientModel_invalid(): - # Fails due to invalid date format - data = { - "resourceType": "Patient", - "name": [{"family": "Doe", "given": ["John"], "prefix": ["Mr."]}], - "birthDate": "1980-00-00", - } - with pytest.raises(ValueError): - Patient(**data) - - -def test_HumanNameModel(): - data = {"family": "Doe", "given": ["John"], "prefix": ["Mr."]} - name = HumanName(**data) - name = name.model_dump(by_alias=True) - assert name["family"] == "Doe" - assert name["given"] == ["John"] - - -def test_HumanNameModel_invalid(): - # Fails due to invalid data type (int instead of str) for given - data = {"family": "Doe", "given": [15], "prefix": ["Mr."]} - with pytest.raises(ValueError): - HumanName(**data) - - -def test_ContactPointModel(): - data = {"system": "phone", "value": "1234567890", "use": "home"} - contact = ContactPoint(**data) - contact = contact.model_dump(by_alias=True) - assert contact["system"] == "phone" - assert contact["value"] == "1234567890" - - -def test_AddressModel(): - data = { - "use": "home", - "type": "postal", - "text": "123 Main St", - "line": ["Apt 1"], - "city": "Anytown", - "district": "Any County", - "state": "NY", - "postalCode": "12345", - "country": "US", - } - address = Address(**data) - address = address.model_dump(by_alias=True) - assert address["use"] == "home" - assert address["line"] == ["Apt 1"] - assert address["city"] == "Anytown" - assert address["state"] == "NY" - assert address["postalCode"] == "12345" - assert address["country"] == "US" diff --git a/tests/fhir_resources_unit_tests/test_fhir_resources_practitioner.py b/tests/fhir_resources_unit_tests/test_fhir_resources_practitioner.py deleted file mode 100644 index 644a1d15..00000000 --- a/tests/fhir_resources_unit_tests/test_fhir_resources_practitioner.py +++ /dev/null @@ -1,45 +0,0 @@ -from healthchain.fhir_resources.practitioner import Practitioner - - -def test_PractitionerModel(): - data = { - "resourceType": "Practitioner", - "name": [{"family": "Doe", "given": ["John"], "prefix": ["Mr."]}], - "birthDate": "1980-01-01", - "qualification": [ - { - "code": { - "coding": [ - { - "system": "http://example.org", - "code": "12345", - "display": "Qualification 1", - } - ], - "text": "Qualification 1", - }, - "period": {"start": "2010-01-01", "end": "2015-01-01"}, - } - ], - "communication": [ - { - "language": { - "coding": [ - { - "system": "http://example.org", - "code": "en", - "display": "English", - } - ], - "text": "English", - } - } - ], - } - - practitioner = Practitioner(**data) - practitioner = practitioner.model_dump(by_alias=True) - assert practitioner["resourceType"] == "Practitioner" - assert practitioner["name"][0]["given"] == ["John"] - assert practitioner["birthDate"] == "1980-01-01" - assert practitioner["qualification"][0]["code"]["coding"][0]["code"] == "12345" diff --git a/tests/generators_tests/test_condition_generators.py b/tests/generators_tests/test_condition_generators.py index 3794ab2f..86185d02 100644 --- a/tests/generators_tests/test_condition_generators.py +++ b/tests/generators_tests/test_condition_generators.py @@ -46,10 +46,10 @@ def test_ConditionGenerator(): condition_model = ConditionGenerator.generate("Patient/456", "Encounter/789") value_set = [x.code for x in ConditionCodeSimple().value_set] value_set.extend([x.code for x in ConditionCodeComplex().value_set]) - assert condition_model.subject_field.reference_field == "Patient/456" - assert condition_model.encounter_field.reference_field == "Encounter/789" - assert condition_model.id_field is not None - assert condition_model.subject_field is not None - assert condition_model.encounter_field is not None - assert condition_model.code_field is not None - assert condition_model.code_field.coding_field[0].code_field in value_set + assert condition_model.subject.reference == "Patient/456" + assert condition_model.encounter.reference == "Encounter/789" + assert condition_model.id is not None + assert condition_model.subject is not None + assert condition_model.encounter is not None + assert condition_model.code is not None + assert condition_model.code.coding[0].code in value_set diff --git a/tests/generators_tests/test_encounter_generators.py b/tests/generators_tests/test_encounter_generators.py index 27a10081..18ee27f6 100644 --- a/tests/generators_tests/test_encounter_generators.py +++ b/tests/generators_tests/test_encounter_generators.py @@ -8,30 +8,29 @@ def test_ClassGenerator(): patient_class = ClassGenerator.generate() assert ( - patient_class.coding_field[0].system_field + patient_class.coding[0].system == "http://terminology.hl7.org/CodeSystem/v3-ActCode" ) - assert patient_class.coding_field[0].code_field in ("IMP", "AMB") - assert patient_class.coding_field[0].display_field in ("inpatient", "ambulatory") + assert patient_class.coding[0].code in ("IMP", "AMB") + assert patient_class.coding[0].display in ("inpatient", "ambulatory") def test_EncounterTypeGenerator(): encounter_type = EncounterTypeGenerator.generate() - assert encounter_type.coding_field[0].system_field == "http://snomed.info/sct" - assert encounter_type.coding_field[0].display_field in ("consultation", "emergency") + assert encounter_type.coding[0].system == "http://snomed.info/sct" + assert encounter_type.coding[0].display in ("consultation", "emergency") def test_EncounterModel(): encounter = EncounterGenerator.generate() - assert encounter.resourceType == "Encounter" - assert encounter.id_field is not None - assert encounter.status_field in ( + assert encounter.id is not None + assert encounter.status in ( "planned", "in-progress", "on-hold", "discharged", "cancelled", ) - assert encounter.subject_field.reference_field == "Patient/123" - assert encounter.subject_field.display_field == "Patient/123" + assert encounter.subject.reference == "Patient/123" + assert encounter.subject.display == "Patient/123" diff --git a/tests/generators_tests/test_medication_administration_generators.py b/tests/generators_tests/test_medication_administration_generators.py index e9c94d12..699bb442 100644 --- a/tests/generators_tests/test_medication_administration_generators.py +++ b/tests/generators_tests/test_medication_administration_generators.py @@ -6,11 +6,11 @@ def test_MedicationAdministrationDosageGenerator(): result = MedicationAdministrationDosageGenerator.generate() - assert result.text_field is not None + assert result.text is not None def test_MedicationAdministrationGenerator(): result = MedicationAdministrationGenerator.generate("Patient/123", "Encounter/123") - assert result.id_field is not None - assert result.status_field is not None - assert result.medication_field is not None + assert result.id is not None + assert result.status is not None + assert result.medication is not None diff --git a/tests/generators_tests/test_medication_request_generators.py b/tests/generators_tests/test_medication_request_generators.py index 4784c2cd..6fca11ae 100644 --- a/tests/generators_tests/test_medication_request_generators.py +++ b/tests/generators_tests/test_medication_request_generators.py @@ -18,9 +18,5 @@ def test_MedicationRequestGenerator(): medication_request = generator.generate() value_set = [x.code for x in MedicationRequestMedication().value_set] assert medication_request is not None - assert medication_request.resourceType == "MedicationRequest" - assert medication_request.id_field is not None - assert ( - medication_request.contained_field[0].code_field.coding_field[0].code_field - in value_set - ) + assert medication_request.id is not None + assert medication_request.contained[0].code.coding[0].code in value_set diff --git a/tests/generators_tests/test_patient_generators.py b/tests/generators_tests/test_patient_generators.py index 1b332868..7651b4f7 100644 --- a/tests/generators_tests/test_patient_generators.py +++ b/tests/generators_tests/test_patient_generators.py @@ -25,6 +25,5 @@ def test_patient_data_generator(): assert patient_data is not None # Assert that the patient data has the expected pydantic fields - assert patient_data.resourceType == "Patient" - assert patient_data.id_field is not None - assert patient_data.active_field is not None + assert patient_data.id is not None + assert patient_data.active is not None diff --git a/tests/generators_tests/test_practitioner_generators.py b/tests/generators_tests/test_practitioner_generators.py index 7dc4e72e..affaec61 100644 --- a/tests/generators_tests/test_practitioner_generators.py +++ b/tests/generators_tests/test_practitioner_generators.py @@ -16,24 +16,23 @@ def test_practitioner_data_generator(): assert practitioner_data is not None # Assert that the practitioner data has the expected pydantic fields - assert practitioner_data.resourceType == "Practitioner" - assert practitioner_data.id_field is not None - assert practitioner_data.active_field is not None - assert practitioner_data.name_field is not None - assert practitioner_data.qualification_field is not None - assert practitioner_data.communication_field is not None + assert practitioner_data.id is not None + assert practitioner_data.active is not None + assert practitioner_data.name is not None + assert practitioner_data.qualification is not None + assert practitioner_data.communication is not None # Assert that the qualification data has the expected pydantic fields - qualification_data = practitioner_data.qualification_field[0] - assert qualification_data.id_field is not None - assert qualification_data.code_field is not None - assert qualification_data.period_field is not None + qualification_data = practitioner_data.qualification[0] + assert qualification_data.id is not None + assert qualification_data.code is not None + assert qualification_data.period is not None # Assert that the communication data has the expected pydantic fields - communication_data = practitioner_data.communication_field[0] - assert communication_data.id_field is not None - assert communication_data.language_field is not None - assert communication_data.preferred_field is not None + communication_data = practitioner_data.communication[0] + assert communication_data.id is not None + assert communication_data.language is not None + assert communication_data.preferred is not None def test_practitioner_qualification_generator(): @@ -47,9 +46,9 @@ def test_practitioner_qualification_generator(): assert qualification is not None # Assert that the qualification has the expected pydantic fields - assert qualification.id_field is not None - assert qualification.code_field is not None - assert qualification.period_field is not None + assert qualification.id is not None + assert qualification.code is not None + assert qualification.period is not None def test_practitioner_communication_generator(): @@ -63,6 +62,6 @@ def test_practitioner_communication_generator(): assert communication is not None # Assert that the communication has the expected pydantic fields - assert communication.id_field is not None - assert communication.language_field is not None - assert communication.preferred_field is not None + assert communication.id is not None + assert communication.language is not None + assert communication.preferred is not None diff --git a/tests/generators_tests/test_procedure_generators.py b/tests/generators_tests/test_procedure_generators.py index e5916cad..526d18f8 100644 --- a/tests/generators_tests/test_procedure_generators.py +++ b/tests/generators_tests/test_procedure_generators.py @@ -11,7 +11,6 @@ def test_ProcedureGenerator(): procedure = ProcedureGenerator.generate( subject_reference="Patient/123", encounter_reference="Encounter/123" ) - assert procedure.resourceType == "Procedure" - assert procedure.subject_field.reference_field == "Patient/123" - assert procedure.encounter_field.reference_field == "Encounter/123" - assert procedure.code_field.coding_field[0].code_field in value_set + assert procedure.subject.reference == "Patient/123" + assert procedure.encounter.reference == "Encounter/123" + assert procedure.code.coding[0].code in value_set