fhir-sheets 2.1.1__tar.gz → 2.1.4__tar.gz

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.

Files changed (26) hide show
  1. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/PKG-INFO +2 -1
  2. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/pyproject.toml +2 -1
  3. fhir_sheets-2.1.4/src/fhir_sheets/cli/__init__.pyi +0 -0
  4. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/src/fhir_sheets/cli/main.py +10 -3
  5. fhir_sheets-2.1.4/src/fhir_sheets/cli/main.pyi +6 -0
  6. fhir_sheets-2.1.4/src/fhir_sheets/core/__init__.py +0 -0
  7. fhir_sheets-2.1.4/src/fhir_sheets/core/__init__.pyi +0 -0
  8. fhir_sheets-2.1.4/src/fhir_sheets/core/config/FhirSheetsConfiguration.py +12 -0
  9. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/src/fhir_sheets/core/conversion.py +87 -37
  10. fhir_sheets-2.1.4/src/fhir_sheets/core/conversion.pyi +22 -0
  11. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/src/fhir_sheets/core/fhir_formatting.py +8 -8
  12. fhir_sheets-2.1.4/src/fhir_sheets/core/fhir_formatting.pyi +13 -0
  13. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/src/fhir_sheets/core/read_input.py +5 -51
  14. fhir_sheets-2.1.4/src/fhir_sheets/core/read_input.pyi +8 -0
  15. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/src/fhir_sheets/core/special_values.py +12 -11
  16. fhir_sheets-2.1.4/src/fhir_sheets/core/special_values.pyi +52 -0
  17. fhir_sheets-2.1.4/src/fhir_sheets/core/util.pyi +0 -0
  18. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/LICENSE +0 -0
  19. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/README.md +0 -0
  20. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/src/fhir_sheets/__init__.py +0 -0
  21. /fhir_sheets-2.1.1/src/fhir_sheets/cli/__init__.py → /fhir_sheets-2.1.4/src/fhir_sheets/__init__.pyi +0 -0
  22. {fhir_sheets-2.1.1/src/fhir_sheets/core → fhir_sheets-2.1.4/src/fhir_sheets/cli}/__init__.py +0 -0
  23. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/src/fhir_sheets/core/model/cohort_data_entity.py +0 -0
  24. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/src/fhir_sheets/core/model/resource_definition_entity.py +0 -0
  25. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/src/fhir_sheets/core/model/resource_link_entity.py +0 -0
  26. {fhir_sheets-2.1.1 → fhir_sheets-2.1.4}/src/fhir_sheets/core/util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fhir-sheets
3
- Version: 2.1.1
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
@@ -14,6 +14,7 @@ Requires-Dist: jsonpath-ng (==1.6.1)
14
14
  Requires-Dist: openpyxl (==3.1.5)
15
15
  Requires-Dist: orjson (==3.10.7)
16
16
  Requires-Dist: ply (==3.11)
17
+ Requires-Dist: pytest_cov (==7.0.0)
17
18
  Description-Content-Type: text/markdown
18
19
 
19
20
  # FHIRSheets
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "fhir-sheets"
3
- version = "2.1.1"
3
+ version = "2.1.4"
4
4
  description = "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
  authors = ["Michael Riley <Michael.Riley@gtri.gatech.edu>"]
6
6
  packages = [{include = "fhir_sheets", from = "src"}]
@@ -14,6 +14,7 @@ jsonpath-ng = "1.6.1"
14
14
  openpyxl = "3.1.5"
15
15
  orjson = "3.10.7"
16
16
  ply = "3.11"
17
+ pytest_cov = "7.0.0"
17
18
 
18
19
  [build-system]
19
20
  requires = ["poetry-core"]
File without changes
@@ -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
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,22 +13,37 @@ 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
 
34
+ def create_singular_resource(singleton_entity_name: str, resource_definition_entities: List[ResourceDefinition], resource_link_entities: List[ResourceLink], cohort_data: CohortData, index = 0):
35
+ created_resources = {}
36
+ for resource_definition in resource_definition_entities:
37
+ entity_name = resource_definition.entity_name
38
+ #Create and collect fhir resources
39
+ fhir_resource = create_fhir_resource(resource_definition, cohort_data, index)
40
+ created_resources[entity_name] = fhir_resource
41
+ if entity_name == singleton_entity_name:
42
+ singleton_fhir_resource = fhir_resource
43
+ add_default_resource_links(created_resources, resource_link_entities)
44
+ create_resource_links(created_resources, resource_link_entities, preview_mode=True)
45
+ return singleton_fhir_resource
46
+
30
47
  #Initialize root bundle definition
31
48
  def initialize_bundle():
32
49
  root_bundle = {}
@@ -60,7 +77,7 @@ def initialize_resource(resource_definition):
60
77
  return initial_resource
61
78
 
62
79
  # Creates a fhir-json structure from a resource definition entity and the patient_data_sheet
63
- 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):
64
81
  resource_dict = initialize_resource(resource_definition)
65
82
  #Get field entries for this entity
66
83
  header_entries_for_resourcename = [
@@ -150,12 +167,21 @@ def add_default_resource_links(created_resources: dict, resource_link_entities:
150
167
  return
151
168
 
152
169
 
153
- #Create resource references/links with created entities
154
- def create_resource_links(created_resources, resource_link_entites):
170
+ #List function to create resource references/links with created entities
171
+ def create_resource_links(created_resources, resource_link_entites, preview_mode = False):
172
+ #TODO: Build resource links
173
+ print("Building resource links")
174
+ for resource_link_entity in resource_link_entites:
175
+ create_resource_link(created_resources, resource_link_entity, preview_mode)
176
+ return
177
+
178
+ #Singular function to create a resource link.
179
+ def create_resource_link(created_resources, resource_link_entity, preview_mode = False):
180
+ # template scaffolding
155
181
  reference_json_block = {
156
182
  "reference" : "$value"
157
183
  }
158
-
184
+ #Special reference handling blocks, in the form of (origin_resource, destination_resource, reference_path)
159
185
  arrayType_references = [
160
186
  ('diagnosticreport', 'specimen', 'specimen'),
161
187
  ('diagnosticreport', 'practitioner', 'performer'),
@@ -165,35 +191,36 @@ def create_resource_links(created_resources, resource_link_entites):
165
191
  ('diagnosticreport', 'observation', 'result'),
166
192
  ('diagnosticreport', 'imagingStudy', 'imagingStudy'),
167
193
  ]
168
- #TODO: Build resource links
169
- print("Building resource links")
170
- for resource_link_entity in resource_link_entites:
171
- try:
172
- origin_resource = created_resources[resource_link_entity.origin_resource]
173
- except KeyError:
174
- print(f"WARNING: In ResourceLinks tab, found a Origin Resource of : {resource_link_entity.origin_resource} but no such entity found in PatientData")
175
- continue
176
- try:
177
- destination_resource = created_resources[resource_link_entity.destination_resource]
178
- except KeyError:
179
- print(f"WARNING: In ResourceLinks tab, found a Desitnation Resource of : {resource_link_entity.destination_resource} but no such entity found in PatientData")
180
- continue
181
- destination_resource_type = created_resources[resource_link_entity.destination_resource]['resourceType']
182
- destination_resource_id = created_resources[resource_link_entity.destination_resource]['id']
183
- link_tuple = (created_resources[resource_link_entity.origin_resource]['resourceType'].strip().lower(),
184
- created_resources[resource_link_entity.destination_resource]['resourceType'].strip().lower(),
185
- resource_link_entity.reference_path.strip().lower())
186
- if link_tuple in arrayType_references:
187
- if resource_link_entity.reference_path.strip().lower() not in origin_resource:
188
- origin_resource[resource_link_entity.reference_path.strip().lower()] = []
189
- new_reference = reference_json_block.copy()
190
- new_reference['reference'] = destination_resource_type + "/" + destination_resource_id
191
- origin_resource[resource_link_entity.reference_path.strip().lower()].append(new_reference)
192
- else:
193
- origin_resource[resource_link_entity.reference_path.strip().lower()] = reference_json_block.copy()
194
- origin_resource[resource_link_entity.reference_path.strip().lower()]["reference"] = destination_resource_type + "/" + destination_resource_id
194
+ #Find the origin and destination resource from the link
195
+ try:
196
+ origin_resource = created_resources[resource_link_entity.origin_resource]
197
+ except KeyError:
198
+ print(f"WARNING: In ResourceLinks tab, found a Origin Resource of : {resource_link_entity.origin_resource} but no such entity found in PatientData")
199
+ return
200
+ try:
201
+ destination_resource = created_resources[resource_link_entity.destination_resource]
202
+ except KeyError:
203
+ print(f"WARNING: In ResourceLinks tab, found a Desitnation Resource of : {resource_link_entity.destination_resource} but no such entity found in PatientData")
204
+ return
205
+ #Estable the value of the refence
206
+ if preview_mode:
207
+ reference_value = destination_resource['resourceType'] + "/" + resource_link_entity.destination_resource
208
+ else:
209
+ reference_value = destination_resource['resourceType'] + "/" + destination_resource['id']
210
+ link_tuple = (origin_resource['resourceType'].strip().lower(),
211
+ destination_resource['resourceType'].strip().lower(),
212
+ resource_link_entity.reference_path.strip().lower())
213
+ if link_tuple in arrayType_references:
214
+ if resource_link_entity.reference_path.strip().lower() not in origin_resource:
215
+ origin_resource[resource_link_entity.reference_path.strip().lower()] = []
216
+ new_reference = reference_json_block.copy()
217
+ new_reference['reference'] = reference_value
218
+ origin_resource[resource_link_entity.reference_path.strip().lower()].append(new_reference)
219
+ else:
220
+ origin_resource[resource_link_entity.reference_path.strip().lower()] = reference_json_block.copy()
221
+ origin_resource[resource_link_entity.reference_path.strip().lower()]["reference"] = reference_value
195
222
  return
196
-
223
+
197
224
  def add_resource_to_transaction_bundle(root_bundle, fhir_resource):
198
225
  entry = {}
199
226
  entry['fullUrl'] = "urn:uuid:"+fhir_resource['id']
@@ -235,7 +262,7 @@ def build_structure(current_struct: Dict, json_path: str, resource_definition: R
235
262
  #SPECIAL HANDLING CLAUSE
236
263
  matching_handler = next((handler for handler in special_values.custom_handlers if (json_path.startswith(handler) or json_path == handler)), None)
237
264
  if matching_handler is not None:
238
- return special_values.custom_handlers[matching_handler].assign_value(json_path, resource_definition, current_struct, parts[-1], value)
265
+ return special_values.custom_handlers[matching_handler].assign_value(json_path, resource_definition, dataType, current_struct, parts[-1], value)
239
266
  #Ignore dollar sign ($) and drill farther down
240
267
  if part == '$' or part == resource_definition.resource_type.strip():
241
268
  #Ignore the dollar sign and the resourcetype
@@ -331,4 +358,27 @@ def build_structure(current_struct: Dict, json_path: str, resource_definition: R
331
358
  def build_structure_recurse(current_struct, json_path, resource_definition, dataType, parts, value, previous_parts, part):
332
359
  previous_parts.append(part)
333
360
  return_struct = build_structure(current_struct, json_path, resource_definition, dataType, parts[1:], value, previous_parts)
334
- 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): ...
@@ -33,7 +33,7 @@ def process_sheet_resource_definitions(sheet):
33
33
  headers = [cell.value for cell in next(sheet.iter_rows(min_row=1, max_row=1))] # Get headers
34
34
 
35
35
  for row in sheet.iter_rows(min_row=3, values_only=True):
36
- row_data = dict(zip(headers, row)) # Create a dictionary for each row
36
+ row_data = dict((h, r) for h, r in zip(headers, row) if h is not None) # Create a dictionary for each row
37
37
  if all(cell is None or cell == "" for cell in row_data.values()):
38
38
  continue
39
39
  # Split 'Profile(s)' column into a list of URLs
@@ -41,7 +41,7 @@ def process_sheet_resource_definitions(sheet):
41
41
  row_data["Profile(s)"] = [url.strip() for url in row_data["Profile(s)"].split(",")]
42
42
  resource_definition_entities.append(ResourceDefinition(row_data))
43
43
  resource_definitions.append(row_data)
44
-
44
+ print(f"Resource Definitions\n----------{resource_definitions}")
45
45
  return resource_definition_entities
46
46
 
47
47
  # Function to process the specific sheet with 'OriginResource', 'ReferencePath', and 'DestinationResource'
@@ -55,57 +55,9 @@ def process_sheet_resource_links(sheet):
55
55
  continue
56
56
  resource_links.append(row_data)
57
57
  resource_link_entities.append(ResourceLink(row_data))
58
-
58
+ print(f"Resource Links\n----------{resource_links}")
59
59
  return resource_link_entities
60
60
 
61
- # Function to process the "PatientData" sheet
62
- def process_sheet_patient_data(sheet, resource_definition_entities):
63
- # Initialize the dictionary to store the processed data
64
- patient_data = {}
65
- cohort_data = CohortData()
66
- # Extract the data from the first 6 rows (Entity To Query, JsonPath, etc.)
67
- for col in sheet.iter_cols(min_row=1, max_row=6, min_col=3, values_only=True): # Start from 3rd column
68
- if all(entry is None for entry in col):
69
- continue
70
- entity_name = col[0] # The entity name comes from the first row (Entity To Query)
71
- field_name = col[5] #The "Data Element" comes from the fifth row
72
- if (entity_name is None or entity_name == "") and (field_name is not None and field_name != ""):
73
- print(f"WARNING: - Reading Patient Data Issue - {field_name} - 'Entity To Query' cell missing for column labelled '{field_name}', please provide entity name from the ResourceDefinitions tab.")
74
-
75
- if entity_name not in [entry.entity_name for entry in resource_definition_entities]:
76
- print(f"WARNING: - Reading Patient Data Issue - {field_name} - 'Entity To Query' cell has entity named '{entity_name}', however, the ResourceDefinition tab has no matching resource. Please provide a corresponding entry in the ResourceDefinition tab.")
77
- # Create structure for this entity if not already present
78
- if entity_name not in patient_data:
79
- patient_data[entity_name] = {}
80
- cohort_data.insert_entity(entity_name, EntityData({}))
81
-
82
- # Add jsonpath, valuesets, and initialize an empty list for 'values'
83
- if field_name not in patient_data[entity_name]:
84
- field_data = {
85
- "jsonpath": col[1], # JsonPath from the second row
86
- "valueType": col[2], # Value Type from the third row
87
- "valuesets": col[3], # Value Set from the fourth row
88
- "values": [] # Initialize empty list for actual values
89
- }
90
- patient_data[entity_name][field_name] = field_data
91
- cohort_data.entities[entity_name].insert(field_name, FieldEntry(field_data))
92
-
93
- # Now process the rows starting from the 6th row (the actual data entries)
94
- num_entries = 0
95
- for row in sheet.iter_rows(min_row=7, values_only=True): # Start from row 6 for actual data
96
- if all(cell is None for cell in row):
97
- continue
98
- num_entries = num_entries + 1
99
- entity_name = row[0] # The entity name comes from the first column of each row
100
- for i, value in enumerate(row[2:], start=1): # Iterate through the values in the columns
101
- entity_name = sheet.cell(row=1, column=i + 2).value
102
- field_name = sheet.cell(row=6, column=i + 2).value # Get the Data Element for this column
103
- if entity_name in patient_data and field_name in patient_data[entity_name]:
104
- # Append the actual data values to the 'values' array
105
- cohort_data.entities[entity_name].fields[field_name].values.append(value)
106
- cohort_data.num_entries = num_entries
107
- return cohort_data
108
-
109
61
  # Function to process the "PatientData" sheet for the Revised CohortData
110
62
  def process_sheet_patient_data_revised(sheet, resource_definition_entities):
111
63
  headers = []
@@ -141,5 +93,7 @@ def process_sheet_patient_data_revised(sheet, resource_definition_entities):
141
93
  patients.extend([{}] * needed_count)
142
94
  for patient_dict, value in zip(patients, values):
143
95
  patient_dict[(entity_name, field_name)] = value
96
+ print(f"Headers\n----------{headers}")
97
+ print(f"Patients\n----------{patients}")
144
98
  cohort_data = CohortData(headers=headers, patients=patients)
145
99
  return cohort_data
@@ -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): ...
@@ -7,7 +7,7 @@ from abc import ABC, abstractmethod
7
7
  class AbstractCustomValueHandler(ABC):
8
8
 
9
9
  @abstractmethod
10
- def assign_value(self, json_path, resource_definition, final_struct, key, value):
10
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value):
11
11
  pass
12
12
 
13
13
  class PatientRaceExtensionValueHandler(AbstractCustomValueHandler):
@@ -67,7 +67,7 @@ class PatientRaceExtensionValueHandler(AbstractCustomValueHandler):
67
67
  "url" : "http://hl7.org/fhir/us/core/StructureDefinition/us-core-race"
68
68
  }
69
69
  #Create an ombcategory and detailed section of race extension
70
- def assign_value(self, json_path, resource_definition, final_struct, key, value):
70
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value):
71
71
  #Retrieve the race extension if it exists; make it if it does not.
72
72
  if 'extension' not in final_struct:
73
73
  final_struct['extension'] = []
@@ -128,7 +128,7 @@ class PatientEthnicityExtensionValueHandler(AbstractCustomValueHandler):
128
128
  "url" : "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity"
129
129
  }
130
130
  #Create an ombcategory and detailed section of ethnicitiy extension
131
- def assign_value(self, json_path, resource_definition, final_struct, key, value):
131
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value):
132
132
  #Retrieve the ethncitiy extension if it exists; make it if it does not.
133
133
  if 'extension' not in final_struct:
134
134
  final_struct['extension'] = []
@@ -154,7 +154,7 @@ class PatientBirthSexExtensionValueHandler(AbstractCustomValueHandler):
154
154
  "valueCode" : "$value"
155
155
  }
156
156
  #Assigna birthsex extension
157
- def assign_value(self, json_path, resource_definition, final_struct, key, value):
157
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value):
158
158
  #Retrieve the birthsex extension if it exists; make it if it does not.
159
159
  if 'extension' not in final_struct:
160
160
  final_struct['extension'] = []
@@ -182,7 +182,7 @@ class PatientMRNIdentifierValueHandler(AbstractCustomValueHandler):
182
182
  "value" : "$value"
183
183
  }
184
184
  #Assign a MRN identifier
185
- def assign_value(self, json_path, resource_definition, final_struct, key, value):
185
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value):
186
186
  #Retrieve the MRN identifier if it exists; make it if it does not.
187
187
  target_identifier = self.patient_mrn_block
188
188
  new_identifier = True
@@ -215,7 +215,7 @@ class PatientSSNIdentifierValueHandler(AbstractCustomValueHandler):
215
215
  "value" : "$value"
216
216
  }
217
217
  #Assign a MRN identifier
218
- def assign_value(self, json_path, resource_definition, final_struct, key, value):
218
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value):
219
219
  #Retrieve the MRN identifier if it exists; make it if it does not.
220
220
  target_identifier = self.patient_mrn_block
221
221
  new_identifier = True
@@ -238,7 +238,7 @@ class OrganizationIdentiferNPIValueHandler(AbstractCustomValueHandler):
238
238
  "value" : "$value"
239
239
  }
240
240
  #Assigna birthsex extension
241
- def assign_value(self, json_path, resource_definition, final_struct, key, value):
241
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value):
242
242
  #Retrieve the birthsex extension if it exists; make it if it does not.
243
243
  if 'identifier' not in final_struct:
244
244
  final_struct['identifier'] = []
@@ -255,7 +255,7 @@ class OrganizationIdentiferCLIAValueHandler(AbstractCustomValueHandler):
255
255
  "value" : "$value"
256
256
  }
257
257
  #Assign a birthsex extension
258
- def assign_value(self, json_path, resource_definition, final_struct, key, value):
258
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value):
259
259
  #Retrieve the birthsex extension if it exists; make it if it does not.
260
260
  if 'identifier' not in final_struct:
261
261
  final_struct['identifier'] = []
@@ -272,7 +272,7 @@ class PractitionerIdentiferNPIValueHandler(AbstractCustomValueHandler):
272
272
  "value" : "$value"
273
273
  }
274
274
  #Assigna birthsex extension
275
- def assign_value(self, json_path, resource_definition, final_struct, key, value):
275
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value):
276
276
  #Retrieve the birthsex extension if it exists; make it if it does not.
277
277
  if 'identifier' not in final_struct:
278
278
  final_struct['identifier'] = []
@@ -309,7 +309,7 @@ class ObservationComponentHandler(AbstractCustomValueHandler):
309
309
  }
310
310
  }
311
311
  #Find the appropriate component for the observaiton; then call build_structure again to continue the drill down
312
- def assign_value(self, json_path, resource_definition, final_struct, key, value):
312
+ def assign_value(self, json_path, resource_definition, dataType, final_struct, key, value):
313
313
  #Check to make sure the component part exists
314
314
  if 'component' not in final_struct:
315
315
  final_struct['component'] = []
@@ -330,7 +330,8 @@ class ObservationComponentHandler(AbstractCustomValueHandler):
330
330
  if target_component is self.pulse_oximetry_oxygen_concentration:
331
331
  components.append(target_component)
332
332
  #Recurse back down into
333
- return conversion.build_structure(target_component, '.'.join(parts[2:]), resource_definition, parts[2:], value, parts[:2])
333
+ # current_struct: Dict, json_path: str, resource_definition: ResourceDefinition, dataType: str, parts: List[str], value: Any, previous_parts: List[str]
334
+ return conversion.build_structure(target_component, '.'.join(parts[2:]), resource_definition, dataType, parts[2:], value, parts[:2])
334
335
  pass
335
336
 
336
337
  def utilFindExtensionWithURL(extension_block, url):
@@ -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
File without changes
File without changes