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

Add optional geometry to location #166

Merged
merged 1 commit into from
Mar 8, 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
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,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
name,status,method,id,parentName,parentID,type,typeCode,physicalType,physicalTypeCode,longitude,latitude
City1,active,update,ba787982-b973-4bd5-854e-eacbe161e297,test location-1,18fcbc2e-4240-4a84-a270-7a444523d7b6,site,si,ward,wa,36.81,-1.28
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,,
4 changes: 4 additions & 0 deletions importer/json_payloads/locations_payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"display": "$pt_display"
}
]
},
"position": {
"longitude": "$longitude",
"latitude": "$latitude"
}
}
}
Expand Down
18 changes: 17 additions & 1 deletion importer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,15 @@ def organization_extras(resource, payload_string):
# custom extras for locations
def location_extras(resource, payload_string):
try:
name, *_, parentName, parentID, type, typeCode, physicalType, physicalTypeCode = resource
name, *_, parentName, parentID, type, typeCode, physicalType, physicalTypeCode, longitude, latitude = resource
except ValueError:
parentName = "parentName"
type = "type"
typeCode = "typeCode"
physicalType = "physicalType"
physicalTypeCode = "physicalTypeCode"
longitude = "longitude"


try:
if parentName and parentName != "parentName":
Expand Down Expand Up @@ -308,6 +310,20 @@ def location_extras(resource, payload_string):
del obj["resource"]["physicalType"]
payload_string = json.dumps(obj, indent=4)

try:
if longitude and longitude != "longitude":
payload_string = payload_string.replace('"$longitude"', longitude).replace(
'"$latitude"', latitude)
else:
obj = json.loads(payload_string)
del obj["resource"]["position"]
payload_string = json.dumps(obj, indent=4)
except IndexError:
obj = json.loads(payload_string)
del obj["resource"]["position"]
payload_string = json.dumps(obj, indent=4)


return payload_string


Expand Down
8 changes: 8 additions & 0 deletions importer/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ def test_build_payload_locations(self, mock_get_resource):
}
},
},
"position": {
"type": "object",
"properties": {
"longitude": {"const": 36.81},
"latitude": {"const": -1.28}
}
}
},
"required": [
"resourceType",
Expand All @@ -195,6 +202,7 @@ def test_build_payload_locations(self, mock_get_resource):
"partOf",
"type",
"physicalType",
"position",
],
}
validate(payload_obj["entry"][0]["resource"], resource_schema)
Expand Down
Loading