Skip to content

Commit

Permalink
remove fhir resources
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkells committed Jan 22, 2025
1 parent c4e5ea2 commit cc6efa9
Show file tree
Hide file tree
Showing 35 changed files with 164 additions and 3,768 deletions.
64 changes: 20 additions & 44 deletions healthchain/data_generators/basegenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -68,122 +46,120 @@ 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
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):
Expand All @@ -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)],
)
]
)
Expand Down
6 changes: 3 additions & 3 deletions healthchain/data_generators/cdsdatagenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
10 changes: 0 additions & 10 deletions healthchain/data_generators/conditiongenerators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
45 changes: 18 additions & 27 deletions healthchain/data_generators/encountergenerators.py
Original file line number Diff line number Diff line change
@@ -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,
)


Expand Down Expand Up @@ -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=(
Expand All @@ -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()],
Expand Down
20 changes: 4 additions & 16 deletions healthchain/data_generators/medicationadministrationgenerators.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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")
),
Expand Down
19 changes: 4 additions & 15 deletions healthchain/data_generators/medicationrequestgenerators.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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")
),
Expand Down
Loading

0 comments on commit cc6efa9

Please sign in to comment.