From 596a82743819c2ad5d498b103856921bf4c6e695 Mon Sep 17 00:00:00 2001 From: TraciebelWairimu Date: Mon, 29 Jan 2024 16:09:46 +0300 Subject: [PATCH 1/5] Change Physical_Type to type in locations_payload.json structure --- importer/json_payloads/locations_payload.json | 20 ++++++++++--------- importer/main.py | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/importer/json_payloads/locations_payload.json b/importer/json_payloads/locations_payload.json index 393726f5..edc37cd2 100644 --- a/importer/json_payloads/locations_payload.json +++ b/importer/json_payloads/locations_payload.json @@ -19,14 +19,16 @@ "reference": "Location/$parentID", "display": "$parentName" }, - "physicalType": { - "coding": [ - { - "system": "http://terminology.hl7.org/CodeSystem/location-physical-type", - "code": "$pt_code", - "display": "$pt_display" - } - ] - } + "type": [ + { + "coding": [ + { + "system": "http://terminology.hl7.org/CodeSystem/location-physical-type", + "code": "$pt_code", + "display": "$pt_display" + } + ] + } + ] } } diff --git a/importer/main.py b/importer/main.py index 26d9a0d7..b5ab872c 100644 --- a/importer/main.py +++ b/importer/main.py @@ -236,11 +236,11 @@ def location_extras(resource, payload_string): else: logging.error("Unsupported location type provided for " + resource[0]) obj = json.loads(payload_string) - del obj["resource"]["physicalType"] + del obj["resource"]["type"] payload_string = json.dumps(obj, indent=4) except IndexError: obj = json.loads(payload_string) - del obj["resource"]["physicalType"] + del obj["resource"]["type"] payload_string = json.dumps(obj, indent=4) return payload_string From 68241ab92a1c7d8668979a433208129d618fa4df Mon Sep 17 00:00:00 2001 From: TraciebelWairimu Date: Mon, 5 Feb 2024 09:55:55 +0300 Subject: [PATCH 2/5] Allow input of multiple location types and physical types --- importer/csv/locations/locations_full.csv | 8 ++--- importer/main.py | 39 +++++++---------------- 2 files changed, 15 insertions(+), 32 deletions(-) diff --git a/importer/csv/locations/locations_full.csv b/importer/csv/locations/locations_full.csv index 3e934be3..bf9ab5c8 100644 --- a/importer/csv/locations/locations_full.csv +++ b/importer/csv/locations/locations_full.csv @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/importer/main.py b/importer/main.py index 4b925b27..8a8e15c3 100644 --- a/importer/main.py +++ b/importer/main.py @@ -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 @@ -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( From b71035c9b04c08d9ca4957f3742dc6b1bffa2327 Mon Sep 17 00:00:00 2001 From: TraciebelWairimu Date: Mon, 5 Feb 2024 17:49:13 +0300 Subject: [PATCH 3/5] Avoid to pass location types and physicalType variables incase of empty cell --- importer/main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/importer/main.py b/importer/main.py index 8a8e15c3..b502a91e 100644 --- a/importer/main.py +++ b/importer/main.py @@ -225,20 +225,28 @@ def location_extras(resource, payload_string): payload_string = json.dumps(obj, indent=4) try: - if resource[7]: + if len(resource[7].strip()) > 0: payload_string = payload_string.replace("$t_display", resource[7]) - if resource[8]: + if len(resource[8].strip()) > 0: payload_string = payload_string.replace("$t_code", resource[8]) + else: + obj = json.loads(payload_string) + del obj["resource"]["type"] + payload_string = json.dumps(obj, indent=4) except IndexError: obj = json.loads(payload_string) del obj["resource"]["type"] payload_string = json.dumps(obj, indent=4) try: - if resource[9]: + if len(resource[9].strip()) > 0: payload_string = payload_string.replace("$pt_display", resource[9]) - if resource[10]: + if len(resource[10].strip()) > 0: payload_string = payload_string.replace("$pt_code", resource[10]) + else: + obj = json.loads(payload_string) + del obj["resource"]["physicalType"] + payload_string = json.dumps(obj, indent=4) except IndexError: obj = json.loads(payload_string) del obj["resource"]["physicalType"] From a7dd3d096d98ab2ba260b74cf2e1f8b1b10a22c0 Mon Sep 17 00:00:00 2001 From: TraciebelWairimu Date: Thu, 8 Feb 2024 15:42:07 +0300 Subject: [PATCH 4/5] Allow input of multiple physicalTypes and types --- importer/csv/locations/locations_full.csv | 8 +++--- importer/main.py | 33 +++++++---------------- importer/test_main.py | 8 +++--- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/importer/csv/locations/locations_full.csv b/importer/csv/locations/locations_full.csv index b24bf583..c810742c 100644 --- a/importer/csv/locations/locations_full.csv +++ b/importer/csv/locations/locations_full.csv @@ -1,4 +1,4 @@ -name,status,method,id,parentName,parentID,type,physicalType -City1,active,update,ba787982-b973-4bd5-854e-eacbe161e297,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,jurisdiction,jurisdiction -Building1,active,update,0a04f1c2-de2a-4869-bab2-763d017e5316,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,building,building -City2,active,create,,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,jurisdiction,jurisdiction \ No newline at end of file +name,status,method,id,parentName,parentID,type,typeCode,physicalType,physicalTypeCode +City1,active,update,ba787982-b973-4bd5-854e-eacbe161e297,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,site,si,ward,wa +Building1,active,update,0a04f1c2-de2a-4869-bab2-763d017e5316,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,building,bu,building,bu +City2,active,create,,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,jurisdiction,jdn,jurisdiction,jdn \ No newline at end of file diff --git a/importer/main.py b/importer/main.py index 082ae51d..839ebad4 100644 --- a/importer/main.py +++ b/importer/main.py @@ -215,7 +215,7 @@ def organization_extras(resource, payload_string): # custom extras for locations def location_extras(resource, payload_string): - name, *_, parentName, parentID, type, physicalType = resource + name, *_, parentName, parentID, type, typeCode, physicalType, physicalTypeCode = resource try: if parentName: payload_string = payload_string.replace("$parentName", parentName).replace( @@ -231,16 +231,11 @@ def location_extras(resource, payload_string): payload_string = json.dumps(obj, indent=4) try: - if type == "building": - payload_string = payload_string.replace("$t_code", "bu").replace( - "$t_display", "Building" - ) - elif type == "jurisdiction": - payload_string = payload_string.replace("$t_code", "jdn").replace( - "$t_display", "Jurisdiction" - ) + if len(type.strip()) > 0: + payload_string = payload_string.replace("$t_display", type) + if len(typeCode.strip()) > 0: + payload_string = payload_string.replace("$t_code", typeCode) else: - logging.error("Unsupported location type provided for " + name) obj = json.loads(payload_string) del obj["resource"]["type"] payload_string = json.dumps(obj, indent=4) @@ -250,18 +245,11 @@ def location_extras(resource, payload_string): payload_string = json.dumps(obj, indent=4) try: - if physicalType == "building": - payload_string = payload_string.replace("$pt_code", "bu").replace( - "$pt_display", "Building" - ) - elif physicalType == "jurisdiction": - payload_string = payload_string.replace("$pt_code", "jdn").replace( - "$pt_display", "Jurisdiction" - ) + if len(physicalType.strip()) > 0: + payload_string = payload_string.replace("$pt_display", physicalType) + if len(physicalTypeCode.strip()) > 0: + payload_string = payload_string.replace("$pt_code", physicalTypeCode) else: - logging.error( - "Unsupported location physical type provided for " + name - ) obj = json.loads(payload_string) del obj["resource"]["physicalType"] payload_string = json.dumps(obj, indent=4) @@ -879,9 +867,8 @@ 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( diff --git a/importer/test_main.py b/importer/test_main.py index d6d43522..746e8ebe 100644 --- a/importer/test_main.py +++ b/importer/test_main.py @@ -79,8 +79,8 @@ def test_build_payload_locations(self): "system": { "const": "http://terminology.hl7.org/CodeSystem/location-type" }, - "code": {"const": "jdn"}, - "display": {"const": "Jurisdiction"}, + "code": {"const": "si"}, + "display": {"const": "site"}, }, }, } @@ -98,8 +98,8 @@ def test_build_payload_locations(self): "system": { "const": "http://terminology.hl7.org/CodeSystem/location-physical-type" }, - "code": {"const": "jdn"}, - "display": {"const": "Jurisdiction"}, + "code": {"const": "wa"}, + "display": {"const": "ward"}, }, }, } From 7ad0eec78805732547301d119b5202dbc2f89857 Mon Sep 17 00:00:00 2001 From: TraciebelWairimu Date: Thu, 8 Feb 2024 17:01:50 +0300 Subject: [PATCH 5/5] Update Create locations in bulk documentation --- importer/README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/importer/README.md b/importer/README.md index 9952c42c..46438c8b 100644 --- a/importer/README.md +++ b/importer/README.md @@ -62,11 +62,10 @@ The coverage report `coverage.html` will be at the working directory - The first two columns __name__ and __status__ is the minimum required - [locations_full](/importer/csv/locations/locations_full.csv) shows more options available - The third column is the request method, can be either create or update. Default is set to create -- The fourth column is the version. Default is set to 1 for creation, needs to be set when updating -- The fifth column is the id, which is required when updating -- The sixth and seventh columns are parentName and parentID,respectively -- The eighth column is the type, it can be either jurisdication or building -- The ninth column is the physicalType,it can be either jurisdication or building +- The fourth column is the id, which is required when updating +- The fifth and sixth columns are parentName and parentID,respectively +- The seventh and eighth columns are the location's type and typeCode, respectively +- The ninth and tenth columns are the location's physicalType and physicalTypeCode, respectively ### 2. Create users in bulk - Run `python3 main.py --csv_file csv/users.csv --resource_type users --log_level info` @@ -75,13 +74,13 @@ The coverage report `coverage.html` will be at the working directory - The fifth column `id` is optional. If populated with a uuid, it will be used as the Practitioner uuid when creating the Practitioner resource. If left empty, a random uuid will be generated - The sixth column is the `userType`, this needs to be set to either `Practitioner` or `Supervisor` - The seventh column is `enableUser` which defaults to True if not set -- The eigth and nineth column are details about the users Keycloak Group and are required for proper assignment +- The eighth and ninth column are details about the users Keycloak Group and are required for proper assignment - The last two columns are the `ApplicationID` and `password` ### 3. Create organizations in bulk - Run `python3 main.py --csv_file csv/organizations/organizations_min.csv --resource_type organizations --log_level info` - See example csv [here](/importer/csv/organizations/organizations_min.csv) -- The first column __name__ is the only one reqired +- The first column __name__ is the only one required - [organizations_full](/importer/csv/organizations/organizations_full.csv) shows more options available - The third column is the request method, can be either create or update. Default is set to create - The fourth column is the id, which is required when updating @@ -90,7 +89,7 @@ The coverage report `coverage.html` will be at the working directory ### 4. Create care teams in bulk - Run `python3 main.py --csv_file csv/careteams/careteam_min.csv --resource_type careTeams --log_level info` - See example csv [here](/importer/csv/careteams/careteam_min.csv) -- The first column __name__ is the only one reqired +- The first column __name__ is the only one required - If the status is not set it will default to __active__ - [careteam_full](/importer/csv/careteams/careteam_full.csv) shows more options available - The third column is the request method, can be either create or update. Default is set to create