fhir-sheets 2.1.3__py3-none-any.whl → 2.1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fhir-sheets might be problematic. Click here for more details.

File without changes
File without changes
fhir_sheets/cli/main.py CHANGED
@@ -1,3 +1,4 @@
1
+ from ..core.config.FhirSheetsConfiguration import FhirSheetsConfiguration
1
2
  from ..core import read_input
2
3
  from ..core import conversion
3
4
 
@@ -18,7 +19,7 @@ def find_sets(d, path=""):
18
19
  elif isinstance(d, set):
19
20
  print(f"Set found at path: {path}")
20
21
 
21
- def main(input_file, output_folder):
22
+ def main(input_file, output_folder, config=FhirSheetsConfiguration({})):
22
23
  # Step 1: Read the input file using read_input module
23
24
 
24
25
  # Check if the output folder exists, and create it if not
@@ -34,7 +35,7 @@ def main(input_file, output_folder):
34
35
  # Construct the file path for each JSON file
35
36
  file_path = output_folder_path / f"{i}.json"
36
37
  #Create a bundle
37
- fhir_bundle = conversion.create_transaction_bundle(resource_definition_entities, resource_link_entities, cohort_data, i)
38
+ fhir_bundle = conversion.create_transaction_bundle(resource_definition_entities, resource_link_entities, cohort_data, i, config)
38
39
  # Step 3: Write the processed data to the output file
39
40
  find_sets(fhir_bundle)
40
41
  json_string = orjson.dumps(fhir_bundle)
@@ -55,8 +56,14 @@ if __name__ == "__main__":
55
56
  # Define the output file argument
56
57
  parser.add_argument('--output_folder', type=str, help="Path to save the output files", default="output/")
57
58
 
59
+ # Config object arguments
60
+ parser.add_argument('--preview_mode', type=str, help="Configuration option to generate resources as 'preview mode' references will reference the entity name. Will primarily be used to render a singular resource for preview.", default=False)
61
+
62
+ # Define the output file argument
63
+ parser.add_argument('--medications_as_reference', type=str, help="Configuration option to create medication references. You may still provide medicationCodeableConcept, but a post process will convert the codeableconcepts to medication resources", default=False)
58
64
  # Parse the arguments
59
65
  args = parser.parse_args()
60
66
 
61
67
  # Call the main function with the provided arguments
62
- main(args.input_file, args.output_folder)
68
+ config = FhirSheetsConfiguration(vars(args))
69
+ main(args.input_file, args.output_folder, config)
@@ -0,0 +1,6 @@
1
+ from ..core import conversion as conversion, read_input as read_input
2
+ from ..core.config.FhirSheetsConfiguration import FhirSheetsConfiguration as FhirSheetsConfiguration
3
+ from pprint import pprint as pprint
4
+
5
+ def find_sets(d, path: str = '') -> None: ...
6
+ def main(input_file, output_folder, config) -> None: ...
File without changes
@@ -0,0 +1,12 @@
1
+ from typing import Any, Dict
2
+
3
+
4
+ class FhirSheetsConfiguration():
5
+ def __init__(self, data: Dict[str, Any]):
6
+ self.preview_mode = data.get('preview_mode', False)
7
+ self.medications_as_reference = data.get('medications_as_reference', False)
8
+
9
+ def __repr__(self) -> str:
10
+ return (f"FhirSheetsConfiguration("
11
+ f"preview_mode={self.preview_mode}, "
12
+ f"medications_as_reference={self.medications_as_reference})")
@@ -3,6 +3,8 @@ import uuid
3
3
  from jsonpath_ng.jsonpath import Fields, Slice, Where
4
4
  from jsonpath_ng.ext import parse as parse_ext
5
5
 
6
+ from .config.FhirSheetsConfiguration import FhirSheetsConfiguration
7
+
6
8
  from .model.cohort_data_entity import CohortData, CohortData
7
9
  from .model.resource_definition_entity import ResourceDefinition
8
10
  from .model.resource_link_entity import ResourceLink
@@ -11,20 +13,22 @@ from . import special_values
11
13
 
12
14
  #Main top level function
13
15
  #Creates a full transaction bundle for a patient at index
14
- def create_transaction_bundle(resource_definition_entities: List[ResourceDefinition], resource_link_entities: List[ResourceLink], cohort_data: CohortData, index = 0):
16
+ def create_transaction_bundle(resource_definition_entities: List[ResourceDefinition], resource_link_entities: List[ResourceLink], cohort_data: CohortData, index = 0, config: FhirSheetsConfiguration = FhirSheetsConfiguration({})):
15
17
  root_bundle = initialize_bundle()
16
18
  created_resources = {}
17
19
  for resource_definition in resource_definition_entities:
18
20
  entity_name = resource_definition.entity_name
19
21
  #Create and collect fhir resources
20
- fhir_resource = create_fhir_resource(resource_definition, cohort_data, index)
22
+ fhir_resource = create_fhir_resource(resource_definition, cohort_data, index, config)
21
23
  created_resources[entity_name] = fhir_resource
22
24
  #Link resources after creation
23
25
  add_default_resource_links(created_resources, resource_link_entities)
24
- create_resource_links(created_resources, resource_link_entities)
26
+ create_resource_links(created_resources, resource_link_entities, config.preview_mode)
25
27
  #Construct into fhir bundle
26
28
  for fhir_resource in created_resources.values():
27
29
  add_resource_to_transaction_bundle(root_bundle, fhir_resource)
30
+ if config.medications_as_reference:
31
+ post_process_create_medication_references(root_bundle)
28
32
  return root_bundle
29
33
 
30
34
  def create_singular_resource(singleton_entity_name: str, resource_definition_entities: List[ResourceDefinition], resource_link_entities: List[ResourceLink], cohort_data: CohortData, index = 0):
@@ -73,7 +77,7 @@ def initialize_resource(resource_definition):
73
77
  return initial_resource
74
78
 
75
79
  # Creates a fhir-json structure from a resource definition entity and the patient_data_sheet
76
- def create_fhir_resource(resource_definition: ResourceDefinition, cohort_data: CohortData, index = 0):
80
+ def create_fhir_resource(resource_definition: ResourceDefinition, cohort_data: CohortData, index: int = 0, config: FhirSheetsConfiguration = None):
77
81
  resource_dict = initialize_resource(resource_definition)
78
82
  #Get field entries for this entity
79
83
  header_entries_for_resourcename = [
@@ -354,4 +358,27 @@ def build_structure(current_struct: Dict, json_path: str, resource_definition: R
354
358
  def build_structure_recurse(current_struct, json_path, resource_definition, dataType, parts, value, previous_parts, part):
355
359
  previous_parts.append(part)
356
360
  return_struct = build_structure(current_struct, json_path, resource_definition, dataType, parts[1:], value, previous_parts)
357
- return return_struct
361
+ return return_struct
362
+
363
+ #Post-process function to add medication reference in specific references
364
+ def post_process_create_medication_references( root_bundle: dict):
365
+ medication_resources = [resource['resource'] for resource in root_bundle['entry'] if resource['resource']['resourceType'] == "Medication"]
366
+ medication_request_resources = [resource['resource'] for resource in root_bundle['entry'] if resource['resource']['resourceType'] == "MedicationRequest"]
367
+ for medication_request_resource in medication_request_resources:
368
+ #Get candidates
369
+ medication_candidates = [resource for resource in medication_resources if resource['code'] == medication_request_resource['medicationCodeableConcept']]
370
+ if not medication_candidates: #If no candidates, create, else get the first candidate
371
+ medication_target = target_medication = createMedicationResource(root_bundle, medication_request_resource['medicationCodeableConcept'])
372
+ medication_resources.append(target_medication)
373
+ else:
374
+ target_medication = medication_candidates[0]
375
+
376
+ del(medication_request_resource['medicationCodeableConcept'])
377
+ medication_request_resource['medicationReference'] = target_medication['resourceType'] + "/" + target_medication['id']
378
+ return
379
+
380
+ def createMedicationResource(root_bundle, medicationCodeableConcept):
381
+ target_medication = initialize_resource(ResourceDefinition({'ResourceType': 'Medication'}))
382
+ target_medication['code'] = medicationCodeableConcept
383
+ add_resource_to_transaction_bundle(root_bundle, target_medication)
384
+ return target_medication
@@ -0,0 +1,22 @@
1
+ from . import fhir_formatting as fhir_formatting, special_values as special_values
2
+ from .config.FhirSheetsConfiguration import FhirSheetsConfiguration as FhirSheetsConfiguration
3
+ from .model.cohort_data_entity import CohortData as CohortData
4
+ from .model.resource_definition_entity import ResourceDefinition as ResourceDefinition
5
+ from .model.resource_link_entity import ResourceLink as ResourceLink
6
+ from jsonpath_ng.jsonpath import Fields as Fields, Slice as Slice, Where as Where
7
+ from typing import Any
8
+
9
+ def create_transaction_bundle(resource_definition_entities: list[ResourceDefinition], resource_link_entities: list[ResourceLink], cohort_data: CohortData, index: int = 0, config: FhirSheetsConfiguration = ...): ...
10
+ def create_singular_resource(singleton_entity_name: str, resource_definition_entities: list[ResourceDefinition], resource_link_entities: list[ResourceLink], cohort_data: CohortData, index: int = 0): ...
11
+ def initialize_bundle(): ...
12
+ def initialize_resource(resource_definition): ...
13
+ def create_fhir_resource(resource_definition: ResourceDefinition, cohort_data: CohortData, index: int = 0, config: FhirSheetsConfiguration = None): ...
14
+ def add_default_resource_links(created_resources: dict, resource_link_entities: list[ResourceLink]): ...
15
+ def create_resource_links(created_resources, resource_link_entites, preview_mode: bool = False) -> None: ...
16
+ def create_resource_link(created_resources, resource_link_entity, preview_mode: bool = False) -> None: ...
17
+ def add_resource_to_transaction_bundle(root_bundle, fhir_resource): ...
18
+ def create_structure_from_jsonpath(root_struct: dict, json_path: str, resource_definition: ResourceDefinition, dataType: str, value: Any): ...
19
+ def build_structure(current_struct: dict, json_path: str, resource_definition: ResourceDefinition, dataType: str, parts: list[str], value: Any, previous_parts: list[str]): ...
20
+ def build_structure_recurse(current_struct, json_path, resource_definition, dataType, parts, value, previous_parts, part): ...
21
+ def post_process_create_medication_references(root_bundle: dict): ...
22
+ def createMedicationResource(root_bundle, medicationCodeableConcept): ...
@@ -3,14 +3,14 @@ from datetime import datetime, time, timezone
3
3
 
4
4
  #Dictionary of regexes
5
5
  type_regexes = {
6
- 'code': '[^\s]+( [^\s]+)*',
7
- 'decimal': '-?(0|[1-9][0-9]{0,17})(\.[0-9]{1,17})?([eE][+-]?[0-9]{1,9}})?',
8
- 'id': '[A-Za-z0-9\-\.]{1,64}',
9
- 'integer': '[0]|[-+]?[1-9][0-9]*',
10
- 'oid': 'urn:oid:[0-2](\.(0|[1-9][0-9]*))+',
11
- 'positiveInt': '[1-9][0-9]*',
12
- 'unsignedInt':'[0]|([1-9][0-9]*)',
13
- 'uuid':'urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
6
+ 'code': r'[^\s]+( [^\s]+)*',
7
+ 'decimal': r'-?(0|[1-9][0-9]{0,17})(\.[0-9]{1,17})?([eE][+-]?[0-9]{1,9}})?',
8
+ 'id': r'[A-Za-z0-9\-\.]{1,64}',
9
+ 'integer': r'[0]|[-+]?[1-9][0-9]*',
10
+ 'oid': r'urn:oid:[0-2](\.(0|[1-9][0-9]*))+',
11
+ 'positiveInt': r'[1-9][0-9]*',
12
+ 'unsignedInt': r'[0]|([1-9][0-9]*)',
13
+ 'uuid': r'urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
14
14
  }
15
15
  # Assign final_struct[key] to value; with formatting given the valueType
16
16
  def assign_value(final_struct, key, value, valueType):
@@ -0,0 +1,13 @@
1
+ from _typeshed import Incomplete
2
+
3
+ type_regexes: Incomplete
4
+
5
+ def assign_value(final_struct, key, value, valueType): ...
6
+ def parse_iso8601_date(input_string): ...
7
+ def parse_iso8601_datetime(input_string): ...
8
+ def parse_iso8601_instant(input_string): ...
9
+ def parse_iso8601_time(input_string): ...
10
+ def parse_flexible_address(address): ...
11
+ def caret_delimited_string_to_codeableconcept(caret_delimited_str): ...
12
+ def caret_delimited_string_to_coding(caret_delimited_str): ...
13
+ def string_to_quantity(quantity_str): ...
@@ -0,0 +1,8 @@
1
+ from .model.cohort_data_entity import CohortData as CohortData
2
+ from .model.resource_definition_entity import ResourceDefinition as ResourceDefinition
3
+ from .model.resource_link_entity import ResourceLink as ResourceLink
4
+
5
+ def read_xlsx_and_process(file_path): ...
6
+ def process_sheet_resource_definitions(sheet): ...
7
+ def process_sheet_resource_links(sheet): ...
8
+ def process_sheet_patient_data_revised(sheet, resource_definition_entities): ...
@@ -0,0 +1,52 @@
1
+ import abc
2
+ from . import conversion as conversion
3
+ from _typeshed import Incomplete
4
+ from abc import ABC, abstractmethod
5
+
6
+ class AbstractCustomValueHandler(ABC, metaclass=abc.ABCMeta):
7
+ @abstractmethod
8
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value): ...
9
+
10
+ class PatientRaceExtensionValueHandler(AbstractCustomValueHandler):
11
+ omb_categories: Incomplete
12
+ initial_race_json: Incomplete
13
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value): ...
14
+
15
+ class PatientEthnicityExtensionValueHandler(AbstractCustomValueHandler):
16
+ omb_categories: Incomplete
17
+ initial_ethnicity_json: Incomplete
18
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value): ...
19
+
20
+ class PatientBirthSexExtensionValueHandler(AbstractCustomValueHandler):
21
+ birth_sex_block: Incomplete
22
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value) -> None: ...
23
+
24
+ class PatientMRNIdentifierValueHandler(AbstractCustomValueHandler):
25
+ patient_mrn_block: Incomplete
26
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value) -> None: ...
27
+
28
+ class PatientSSNIdentifierValueHandler(AbstractCustomValueHandler):
29
+ patient_mrn_block: Incomplete
30
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value) -> None: ...
31
+
32
+ class OrganizationIdentiferNPIValueHandler(AbstractCustomValueHandler):
33
+ npi_identifier_block: Incomplete
34
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value) -> None: ...
35
+
36
+ class OrganizationIdentiferCLIAValueHandler(AbstractCustomValueHandler):
37
+ clia_identifier_block: Incomplete
38
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value) -> None: ...
39
+
40
+ class PractitionerIdentiferNPIValueHandler(AbstractCustomValueHandler):
41
+ npi_identifier_block: Incomplete
42
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value) -> None: ...
43
+
44
+ class ObservationComponentHandler(AbstractCustomValueHandler):
45
+ pulse_oximetry_oxygen_flow_rate: Incomplete
46
+ pulse_oximetry_oxygen_concentration: Incomplete
47
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value): ...
48
+
49
+ def utilFindExtensionWithURL(extension_block, url): ...
50
+ def findComponentWithCoding(components, code): ...
51
+
52
+ custom_handlers: Incomplete
File without changes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fhir-sheets
3
- Version: 2.1.3
3
+ Version: 2.1.4
4
4
  Summary: FhirSheets is a command-line tool that reads an Excel file in FHIR cohort format and generates FHIR bundle JSON files from it. Each row in the template Excel file is used to create an individual JSON file, outputting them to a specified folder.
5
5
  License-File: LICENSE
6
6
  Author: Michael Riley
@@ -0,0 +1,26 @@
1
+ fhir_sheets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ fhir_sheets/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ fhir_sheets/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ fhir_sheets/cli/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ fhir_sheets/cli/main.py,sha256=zpCieUZUyC1JVVGo8eV4slaTxjHPhsJDUYpX3Pq-BaY,3417
6
+ fhir_sheets/cli/main.pyi,sha256=9bGkkzW5u2Clbt6DQJ7HAYH1YfYguT4DlnomgX-vFkg,311
7
+ fhir_sheets/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ fhir_sheets/core/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ fhir_sheets/core/config/FhirSheetsConfiguration.py,sha256=YFXfNaA5hpFPwp9wBeNogo7u2VR11-KO5uBY-Ckh8QY,465
10
+ fhir_sheets/core/conversion.py,sha256=JmI62neonuPH0EbKed3i7tiUnT67l0ykSRLbKasfe-Q,22413
11
+ fhir_sheets/core/conversion.pyi,sha256=YfPZjxsqcLf4pgS_2-R1mTlucBnV2kmGqwIlOOIvt0A,2135
12
+ fhir_sheets/core/fhir_formatting.py,sha256=16IJtSm8ZZ4WNwnLHZXdePIbCA7wPz57ynUSuRpI1pA,13021
13
+ fhir_sheets/core/fhir_formatting.pyi,sha256=JVju6WwzG7H9iI-5MO5Q0V-8-dNoWVxCzWLCFUW3cl4,512
14
+ fhir_sheets/core/model/cohort_data_entity.py,sha256=tRfHxuZdXvSk-OerPpbCBEfJJAo6f1L-If-p0ltC51Q,1382
15
+ fhir_sheets/core/model/resource_definition_entity.py,sha256=1yRzNWwewCSle_6u8CBW_l7nGg1aQDVIJCprKKdv_MU,746
16
+ fhir_sheets/core/model/resource_link_entity.py,sha256=-iCzGaKJt5ZISTSwBVmEuLIKzgRtbL_I7JRpoEc89h0,812
17
+ fhir_sheets/core/read_input.py,sha256=QSk-TzXRX9tmJZ3Qa3qQJxGQa3PwBrN93KlHKN8DpJA,5229
18
+ fhir_sheets/core/read_input.pyi,sha256=AU7XNMyqslTv183-fKQDZtUURvNEdvLdfpj9DPWZFbg,439
19
+ fhir_sheets/core/special_values.py,sha256=WpwHpf1BHs5SerXi4x9WjjkiR1tIQL8CuGlZ0iEB_2A,15575
20
+ fhir_sheets/core/special_values.pyi,sha256=fs3bm8QdzohNLQ_9roX79pYhuUDEJv_2NNzta3jFAJk,2472
21
+ fhir_sheets/core/util.py,sha256=gudEPi_xTDC9YHqUlGEkn_tA26HbhNjuqGgjtuOEINk,9
22
+ fhir_sheets/core/util.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
+ fhir_sheets-2.1.4.dist-info/METADATA,sha256=ZzOYeqcWaKKigoYgaMRc_PbnCik8I1_DLvfXceNEnFQ,2947
24
+ fhir_sheets-2.1.4.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
25
+ fhir_sheets-2.1.4.dist-info/licenses/LICENSE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
26
+ fhir_sheets-2.1.4.dist-info/RECORD,,
@@ -1,16 +0,0 @@
1
- fhir_sheets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- fhir_sheets/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- fhir_sheets/cli/main.py,sha256=0ctZTB30KwIHpjYyJgrEdJorDbn5WQIQuclIwHvp4Js,2650
4
- fhir_sheets/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- fhir_sheets/core/conversion.py,sha256=dCoB3tktiSibl8tp5_IyCV_ACO04GdrUcU9yztPgqAk,20463
6
- fhir_sheets/core/fhir_formatting.py,sha256=eNM38Cp7TEdND1fIKhp2HTwzGYDqgWtr13A1qRT06cY,13011
7
- fhir_sheets/core/model/cohort_data_entity.py,sha256=tRfHxuZdXvSk-OerPpbCBEfJJAo6f1L-If-p0ltC51Q,1382
8
- fhir_sheets/core/model/resource_definition_entity.py,sha256=1yRzNWwewCSle_6u8CBW_l7nGg1aQDVIJCprKKdv_MU,746
9
- fhir_sheets/core/model/resource_link_entity.py,sha256=-iCzGaKJt5ZISTSwBVmEuLIKzgRtbL_I7JRpoEc89h0,812
10
- fhir_sheets/core/read_input.py,sha256=QSk-TzXRX9tmJZ3Qa3qQJxGQa3PwBrN93KlHKN8DpJA,5229
11
- fhir_sheets/core/special_values.py,sha256=WpwHpf1BHs5SerXi4x9WjjkiR1tIQL8CuGlZ0iEB_2A,15575
12
- fhir_sheets/core/util.py,sha256=gudEPi_xTDC9YHqUlGEkn_tA26HbhNjuqGgjtuOEINk,9
13
- fhir_sheets-2.1.3.dist-info/METADATA,sha256=Rt7DoOg5Xewtfxe86IhW3z1qK-dPL3tECjp_9kRSjgI,2947
14
- fhir_sheets-2.1.3.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
15
- fhir_sheets-2.1.3.dist-info/licenses/LICENSE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
16
- fhir_sheets-2.1.3.dist-info/RECORD,,