Skip to content

Commit

Permalink
Minimize mocked data in test and fix admin level code
Browse files Browse the repository at this point in the history
  • Loading branch information
TraciebelWairimu committed Mar 27, 2024
1 parent 00a5aff commit 684b130
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
15 changes: 11 additions & 4 deletions importer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,21 @@ def location_extras(resource, payload_string):
payload_string = payload_string.replace("$adminLevelCode", admin_level)
else:
obj = json.loads(payload_string)
del obj["resource"]["type"]
obj_type = obj["resource"]["type"]
current_system = "administrative-level"
index = identify_coding_object_index(obj_type, current_system)
del obj["resource"]["type"][index]
payload_string = json.dumps(obj, indent=4)
except IndexError:
if locationAdminLevel in resource:
admin_level = check_parent_admin_level(locationParentId)
payload_string = payload_string.replace("$adminLevelCode", admin_level)
else:
obj = json.loads(payload_string)
del obj["resource"]["type"]
obj_type = obj["resource"]["type"]
current_system = "administrative-level"
index = identify_coding_object_index(obj_type, current_system)
del obj["resource"]["type"][index]
payload_string = json.dumps(obj, indent=4)

try:
Expand Down Expand Up @@ -1230,8 +1236,9 @@ def main(
json_payload = build_payload(
"locations", resource_list, "json_payloads/locations_payload.json"
)
final_response = handle_request("POST", json_payload, config.fhir_base_url)
logging.info("Processing complete!")
# final_response = handle_request("POST", json_payload, config.fhir_base_url)
# logging.info("Processing complete!")
logging.info(json_payload)
elif resource_type == "organizations":
logging.info("Processing organizations")
json_payload = build_payload(
Expand Down
20 changes: 1 addition & 19 deletions importer/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,6 @@ def test_check_parent_admin_level(self, mock_get_base_url, mock_handle_request):
mocked_response_text = {
"resourceType": "Location",
"id": "18fcbc2e-4240-4a84-a270-7a444523d7b6",
"meta": {
"versionId": "5",
"lastUpdated": "2024-03-18T13:16:34.908+00:00",
"source": "#08aff535b61baf19"
},
"identifier": [
{
"use": "official",
Expand All @@ -287,20 +282,7 @@ def test_check_parent_admin_level(self, mock_get_base_url, mock_handle_request):
}
]
}
],
"physicalType": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/location-physical-type",
"code": "jdn",
"display": "jurisdiction"
}
]
},
"partOf": {
"reference": "Location/105164",
"display": "test location"
}
]
}
string_mocked_response_text = json.dumps(mocked_response_text)
mock_handle_request.return_value = (string_mocked_response_text, 200)
Expand Down

0 comments on commit 684b130

Please sign in to comment.