Skip to content

Commit

Permalink
Merge pull request #2707 from ohcnetwork/sainak/fix-lb-names-while-lo…
Browse files Browse the repository at this point in the history
…ading

Add org type suffix to names while loading csv
  • Loading branch information
vigneshhari authored Jan 5, 2025
2 parents f7c5bf7 + ffd6889 commit e55e7bc
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions care/emr/management/commands/load_govt_organization_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,20 @@ def rows_to_dict(self, rows: list[RowObj]) -> OrgDict:
return data

def create_ward(self, state, parent, ward_number, ward_name):
name = f"{ward_number}: {ward_name}"
metadata = {
"country": self.country,
"govt_org_type": "ward",
"govt_org_id": ward_number,
}
ward_obj, created = Organization.objects.filter(
name__iexact=ward_name,
name__iexact=name,
parent=parent,
org_type="govt",
metadata=metadata,
).get_or_create(
defaults={
"name": ward_name,
"name": name,
"root_org": state,
"parent": parent,
"org_type": "govt",
Expand All @@ -191,7 +192,7 @@ def create_ward(self, state, parent, ward_number, ward_name):
)
logger.debug(
"Ward: %s, Created: %s, Ward ID: %s",
ward_name,
name,
created,
ward_obj.id,
)
Expand Down Expand Up @@ -252,6 +253,8 @@ def create_organization(self, data: OrgDict):
for local_body, local_body_types in local_bodies.items():
for local_body_type, children in local_body_types.items():
# children can be either ward or grama_panchayat
lg_type = local_body_type.replace("_", " ").title()
lb_name = f"{local_body} {lg_type}"
metadata = {
"country": self.country,
"govt_org_type": local_body_type,
Expand All @@ -262,13 +265,13 @@ def create_organization(self, data: OrgDict):
metadata["govt_org_children_type"] = "ward"

local_body_obj, created = Organization.objects.filter(
name__iexact=local_body,
name__iexact=lb_name,
parent=district_obj,
org_type="govt",
metadata=metadata,
).get_or_create(
defaults={
"name": local_body,
"name": lb_name,
"root_org": state_obj,
"parent": district_obj,
"org_type": "govt",
Expand All @@ -290,15 +293,16 @@ def create_organization(self, data: OrgDict):
"govt_org_type": "grama_panchayat",
"govt_org_children_type": "ward",
}
gp_name = f"{grama_panchayat} Grama Panchayat"
grama_panchayat_obj, created = (
Organization.objects.filter(
name__iexact=grama_panchayat,
name__iexact=gp_name,
parent=local_body_obj,
org_type="govt",
metadata=metadata,
).get_or_create(
defaults={
"name": grama_panchayat,
"name": gp_name,
"root_org": state_obj,
"parent": local_body_obj,
"org_type": "govt",
Expand All @@ -310,7 +314,7 @@ def create_organization(self, data: OrgDict):
)
logger.debug(
"Block Panchayat: %s, Created: %s, Block Panchayat ID: %s",
grama_panchayat,
gp_name,
created,
grama_panchayat_obj.id,
)
Expand Down

0 comments on commit e55e7bc

Please sign in to comment.