Skip to content

Commit

Permalink
Allow input of multiple location types and physical types
Browse files Browse the repository at this point in the history
  • Loading branch information
TraciebelWairimu committed Feb 5, 2024
1 parent 9ff1780 commit 68241ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
8 changes: 4 additions & 4 deletions importer/csv/locations/locations_full.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name,status,method,version,id,parentName,parentID,type,physicalType
City1,active,update,1,ba787982-b973-4bd5-854e-eacbe161e297,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,jurisdiction,jurisdiction
Building1,active,update,1,0a04f1c2-de2a-4869-bab2-763d017e5316,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,building,building
City2,active,create,1,,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,jurisdiction,jurisdiction
name,status,method,version,id,parentName,parentID,type,typeCode,physicalType,physicalTypeCode
City1,active,update,1,ba787982-b973-4bd5-854e-eacbe161e297,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,jurisdiction,jdn,jurisdiction,jdn
Building1,active,update,1,0a04f1c2-de2a-4869-bab2-763d017e5316,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,building,bu,building,bu
City2,active,create,1,,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,jurisdiction,jdn,jurisdiction,jdn
39 changes: 11 additions & 28 deletions importer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,41 +225,23 @@ def location_extras(resource, payload_string):
payload_string = json.dumps(obj, indent=4)

try:
if resource[7] == "building":
payload_string = payload_string.replace("$t_code", "bu").replace(
"$t_display", "Building"
)
elif resource[7] == "jurisdiction":
payload_string = payload_string.replace("$t_code", "jdn").replace(
"$t_display", "Jurisdiction"
)
else:
logging.error("Unsupported location type provided for " + resource[0])
obj = json.loads(payload_string)
del obj["resource"]["type"]
payload_string = json.dumps(obj, indent=4)
if resource[7]:
payload_string = payload_string.replace("$t_display", resource[7])
if resource[8]:
payload_string = payload_string.replace("$t_code", resource[8])
except IndexError:
obj = json.loads(payload_string)
del obj["resource"]["type"]
payload_string = json.dumps(obj, indent=4)

try:
if resource[8] == "building":
payload_string = payload_string.replace("$pt_code", "bu").replace(
"$pt_display", "Building"
)
elif resource[8] == "jurisdiction":
payload_string = payload_string.replace("$pt_code", "jdn").replace(
"$pt_display", "Jurisdiction"
)
else:
logging.error("Unsupported location physical type provided for " + resource[0])
obj = json.loads(payload_string)
del obj["resource"]["type"]
payload_string = json.dumps(obj, indent=4)
if resource[9]:
payload_string = payload_string.replace("$pt_display", resource[9])
if resource[10]:
payload_string = payload_string.replace("$pt_code", resource[10])
except IndexError:
obj = json.loads(payload_string)
del obj["resource"]["type"]
del obj["resource"]["physicalType"]
payload_string = json.dumps(obj, indent=4)

return payload_string
Expand Down Expand Up @@ -869,8 +851,9 @@ def main(
json_payload = build_payload(
"locations", resource_list, "json_payloads/locations_payload.json"
)
handle_request("POST", json_payload, config.fhir_base_url)
# 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

0 comments on commit 68241ab

Please sign in to comment.