Skip to content

Commit

Permalink
Merge pull request #1292 from BLSQ/IA-2750-update-default-org-unit-types
Browse files Browse the repository at this point in the history
IA-2750: Update default Org unit types
  • Loading branch information
butofleury authored May 8, 2024
2 parents 722405e + 325684a commit 8eb8b2a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
Binary file modified setuper/data/small_sample.gpkg
Binary file not shown.
4 changes: 3 additions & 1 deletion setuper/data_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ def setup_instances(account_name, iaso_client):
print("-- Setting up a form")
project_id = iaso_client.get("/api/projects/")["projects"][0]["id"]
org_unit_types = iaso_client.get("/api/v2/orgunittypes/")["orgUnitTypes"]
org_unit_type_ids = [out["id"] for out in org_unit_types if out["name"] != "Formation sanitaire"]
org_unit_type_ids = [
out["id"] for out in org_unit_types if out["name"] != "Health facility/Formation sanitaire - HF"
]

# create a form
data = {
Expand Down
8 changes: 6 additions & 2 deletions setuper/default_healthFacility_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ def setup_health_facility_level_default_form(account_name, iaso_client):
print("-- Setting up a default form for Health Facility level")
project_id = iaso_client.get("/api/projects/")["projects"][0]["id"]
org_unit_types = iaso_client.get("/api/v2/orgunittypes/")["orgUnitTypes"]
health_facility_type = [out for out in org_unit_types if out["name"] == "Formation sanitaire"][0]
health_facility_type = [out for out in org_unit_types if out["name"] == "Health facility/Formation sanitaire - HF"][
0
]

org_unit_type_id = [out["id"] for out in org_unit_types if out["name"] == "Formation sanitaire"]
org_unit_type_id = [
out["id"] for out in org_unit_types if out["name"] == "Health facility/Formation sanitaire - HF"
]

sample_data = {
"id": None,
Expand Down
2 changes: 1 addition & 1 deletion setuper/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def setup_entities(account_name, iaso_client):
project_id = iaso_client.get("/api/projects/")["projects"][0]["id"]
org_unit_types = iaso_client.get("/api/v2/orgunittypes/")["orgUnitTypes"]

hf_out = [out for out in org_unit_types if out["name"] == "Formation sanitaire"][0]
hf_out = [out for out in org_unit_types if out["name"] == "Health facility/Formation sanitaire - HF"][0]

print("-- Setting up reference form")

Expand Down
17 changes: 8 additions & 9 deletions setuper/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ def setup_registry(account_name, iaso_client):
project_id = iaso_client.get("/api/projects/")["projects"][0]["id"]
org_unit_types = iaso_client.get("/api/v2/orgunittypes/")["orgUnitTypes"]

commune_out = [out for out in org_unit_types if out["name"] == "Commune"][0]

org_unit_type_ids = [out["id"] for out in org_unit_types]
health_area_type = [out for out in org_unit_types if out["name"] == "Health area/Aire de santé - AREA"][0]
health_area_type_id = health_area_type["id"]

# create a form
data = {
"id": None,
"name": "Registry - Population Commune",
"name": "Registry - Population Health area",
"short_name": "",
"depth": None,
"org_unit_type_ids": [commune_out["id"]],
"org_unit_type_ids": [health_area_type_id],
"project_ids": [project_id],
"single_per_period": False,
"periods_before_allowed": 1,
Expand All @@ -42,19 +41,19 @@ def setup_registry(account_name, iaso_client):

form_version = iaso_client.post("/api/formversions/", files=form_files, data=data)

ou_type = iaso_client.get(f"/api/v2/orgunittypes/{commune_out['id']}/")
ou_type = iaso_client.get(f"/api/v2/orgunittypes/{health_area_type_id}/")
ou_type["reference_forms_ids"] = [form["id"]]
ou_type["allow_creating_sub_unit_type_ids"] = [p["id"] for p in ou_type["allow_creating_sub_unit_types"]]
ou_type["sub_unit_type_ids"] = [p["id"] for p in ou_type["sub_unit_types"]]
ou_type["project_ids"] = [p["id"] for p in ou_type["projects"]]
resp = iaso_client.put(f"/api/v2/orgunittypes/{commune_out['id']}/", json=ou_type)
resp = iaso_client.put(f"/api/v2/orgunittypes/{health_area_type_id}/", json=ou_type)
print(resp)
ou_type = iaso_client.get(f"/api/v2/orgunittypes/{commune_out['id']}/")
ou_type = iaso_client.get(f"/api/v2/orgunittypes/{health_area_type_id}/")
print(ou_type)

# fetch orgunit ids
limit = 20
orgunits = iaso_client.get("/api/orgunits/", params={"limit": limit, "orgUnitTypeId": commune_out["id"]})[
orgunits = iaso_client.get("/api/orgunits/", params={"limit": limit, "orgUnitTypeId": health_area_type_id})[
"orgunits"
]
print(orgunits)
Expand Down

0 comments on commit 8eb8b2a

Please sign in to comment.