Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

121 multiple location types #128

Merged
merged 13 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions importer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand All @@ -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
Expand Down
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,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
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
32 changes: 11 additions & 21 deletions importer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,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(
Expand All @@ -247,16 +247,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)
Expand All @@ -266,22 +261,17 @@ 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:
Wambere marked this conversation as resolved.
Show resolved Hide resolved
logging.error("Unsupported location physical type provided for " + name)
obj = json.loads(payload_string)
del obj["resource"]["type"]
del obj["resource"]["physicalType"]
payload_string = json.dumps(obj, indent=4)
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
8 changes: 4 additions & 4 deletions importer/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
}
Expand All @@ -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"},
},
},
}
Expand Down
Loading