File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import os
22import re
33
4+ URN_UUID_CONTAINING_KEYS = ["reference" , "uri" , "fullUrl" ]
5+
46
57def substitute_env_vars (obj ):
68 if isinstance (obj , dict ):
@@ -27,11 +29,22 @@ def convert_uri_to_reference(uri: str) -> str:
2729 return uri
2830
2931
30- def replace_urn_uuid_with_reference (obj ):
32+ def replace_urn_uuid_with_reference (obj , path = None ):
33+ if path is None :
34+ path = []
35+
3136 if isinstance (obj , str ):
32- return convert_uri_to_reference (obj )
37+ if obj .startswith ("urn:uuid:" ) and path [- 1 ] in URN_UUID_CONTAINING_KEYS :
38+ return convert_uri_to_reference (obj )
39+ return obj
3340 elif isinstance (obj , dict ):
34- return {k : replace_urn_uuid_with_reference (v ) for k , v in obj .items ()}
41+ return {
42+ key : replace_urn_uuid_with_reference (value , path + [key ])
43+ for key , value in obj .items ()
44+ }
3545 elif isinstance (obj , list ):
36- return [replace_urn_uuid_with_reference (item ) for item in obj ]
46+ return [
47+ replace_urn_uuid_with_reference (item , path + [index ])
48+ for index , item in enumerate (obj )
49+ ]
3750 return obj
Original file line number Diff line number Diff line change @@ -65,7 +65,10 @@ def process_file(self, file_path):
6565 resource_id = resource ["id" ]
6666 url = f"{ self .external_fhir_server_url } /{ resource_type } /{ resource_id } "
6767
68- resource = replace_urn_uuid_with_reference (resource )
68+ try :
69+ resource = replace_urn_uuid_with_reference (resource )
70+ except Exception as exc :
71+ logging .exception ("Failed to convert uris to references: {exc}" )
6972
7073 try :
7174 response = requests .put (
You can’t perform that action at this time.
0 commit comments