Skip to content

Commit 21e074b

Browse files
authored
Merge pull request #9 from beda-software/bugfix-selective-uri-convert
feat: update logic to convert uri to references
2 parents 90b0fb7 + 76dc6a4 commit 21e074b

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

fhirsnake/utils.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
import re
33

4+
URN_UUID_CONTAINING_KEYS = ["reference", "uri", "fullUrl"]
5+
46

57
def 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

fhirsnake/watch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff 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(

0 commit comments

Comments
 (0)