diff --git a/healthchain/data_generators/cdsdatagenerator.py b/healthchain/data_generators/cdsdatagenerator.py index 07ff218..b3d1340 100644 --- a/healthchain/data_generators/cdsdatagenerator.py +++ b/healthchain/data_generators/cdsdatagenerator.py @@ -75,6 +75,7 @@ def generate( constraints: Optional[list] = None, free_text_path: Optional[str] = None, column_name: Optional[str] = None, + random_seed: Optional[int] = None, ) -> BaseModel: """ Generates CDS data based on the current workflow, constraints, and optional free text data. @@ -83,6 +84,7 @@ def generate( constraints (Optional[list]): A list of constraints to apply to the data generation. free_text_path (Optional[str]): The path to a CSV file containing free text data. column_name (Optional[str]): The column name in the CSV file to use for free text data. + random_seed (Optional[int]): The random seed to use for reproducible data generation. Returns: BaseModel: The generated CDS FHIR data. @@ -95,7 +97,9 @@ def generate( for resource in self.mappings[self.workflow]: generator_name = resource["generator"] generator = self.fetch_generator(generator_name) - result = generator.generate(constraints=constraints) + result = generator.generate( + constraints=constraints, random_seed=random_seed + ) results.append(BundleEntry(resource=result)) diff --git a/healthchain/data_generators/conditiongenerators.py b/healthchain/data_generators/conditiongenerators.py index cef3fa8..924c367 100644 --- a/healthchain/data_generators/conditiongenerators.py +++ b/healthchain/data_generators/conditiongenerators.py @@ -147,7 +147,9 @@ def generate( subject_reference: Optional[str] = None, encounter_reference: Optional[str] = None, constraints: Optional[list] = None, + random_seed: Optional[int] = None, ): + Faker.seed(random_seed) subject_reference = subject_reference or "Patient/123" encounter_reference = encounter_reference or "Encounter/123" code = generator_registry.get("SnomedCodeGenerator").generate( diff --git a/healthchain/data_generators/encountergenerators.py b/healthchain/data_generators/encountergenerators.py index 1f1b3e4..c9c6681 100644 --- a/healthchain/data_generators/encountergenerators.py +++ b/healthchain/data_generators/encountergenerators.py @@ -143,14 +143,16 @@ class EncounterGenerator(BaseGenerator): A generator class for creating FHIR Encounter resources. Methods: - generate(constraints: Optional[list] = None) -> Encounter: - Generates a FHIR Encounter resource with optional constraints. + generate(constraints: Optional[list] = None, random_seed: Optional[int] = None) -> Encounter: + Generates a FHIR Encounter resource with optional constraints and random_seed. """ @staticmethod def generate( constraints: Optional[list] = None, + random_seed: Optional[int] = None, ) -> Encounter: + Faker.seed(random_seed) patient_reference = "Patient/123" return Encounter( resourceType="Encounter", diff --git a/healthchain/data_generators/medicationrequestgenerators.py b/healthchain/data_generators/medicationrequestgenerators.py index 979efca..3b1f2ab 100644 --- a/healthchain/data_generators/medicationrequestgenerators.py +++ b/healthchain/data_generators/medicationrequestgenerators.py @@ -46,7 +46,9 @@ class MedicationRequestGenerator(BaseGenerator): @staticmethod def generate( constraints: Optional[list] = None, + random_seed: Optional[int] = None, ): + Faker.seed(random_seed) subject_reference = "Patient/123" encounter_reference = "Encounter/123" contained_medication = Medication( diff --git a/healthchain/data_generators/patientgenerators.py b/healthchain/data_generators/patientgenerators.py index a09ba30..7076ed3 100644 --- a/healthchain/data_generators/patientgenerators.py +++ b/healthchain/data_generators/patientgenerators.py @@ -116,7 +116,11 @@ def generate(): @register_generator class PatientGenerator(BaseGenerator): @staticmethod - def generate(constraints: Optional[list] = None): + def generate( + constraints: Optional[list] = None, + random_seed: Optional[int] = None, + ) -> Patient: + Faker.seed(random_seed) return Patient( resourceType="Patient", id=generator_registry.get("IdGenerator").generate(), diff --git a/healthchain/data_generators/proceduregenerators.py b/healthchain/data_generators/proceduregenerators.py index eb51ef6..d2a4426 100644 --- a/healthchain/data_generators/proceduregenerators.py +++ b/healthchain/data_generators/proceduregenerators.py @@ -42,7 +42,9 @@ def generate( subject_reference: Optional[str] = None, encounter_reference: Optional[str] = None, constraints: Optional[list] = None, + random_seed: Optional[int] = None, ): + Faker.seed(random_seed) subject_reference = subject_reference or "Patient/123" encounter_reference = encounter_reference or "Encounter/123" code = generator_registry.get("ProcedureSnomedCodeGenerator").generate(