Skip to content

Commit

Permalink
Only update new fields
Browse files Browse the repository at this point in the history
  • Loading branch information
erikh360 committed May 30, 2024
1 parent b661975 commit 3104856
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ def test_update_clinics(self):
)

existing_clinic.refresh_from_db()
self.assertEqual(existing_clinic.name, "Test Clinic 1")
self.assertEqual(existing_clinic.location, "-33.54222+025.69077/")
self.assertEqual(existing_clinic.province, "ZA-EC")
self.assertEqual(existing_clinic.area_type, "Urban")
self.assertEqual(existing_clinic.unit_type, "Clinic")
self.assertEqual(existing_clinic.district, "Sarah Baartman DM")
Expand Down
12 changes: 4 additions & 8 deletions registrations/management/commands/update_clinics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ast
import csv

import pycountry
Expand Down Expand Up @@ -45,8 +44,10 @@ def get_province(self, row):
return PROVINCES[clean_name(row["OU2short"])]

def get_location(self, row):
lng, lat = ast.literal_eval(row["coordinates"])
return self.format_location(lat, lng)
if row["longitude"] and row["latitude"]:
lng = float(row["longitude"])
lat = float(row["latitude"])
return self.format_location(lat, lng)

def handle(self, *args, **options):
for csv_file in options["csv_file"]:
Expand All @@ -55,11 +56,6 @@ def handle(self, *args, **options):
for row in reader:
clinic = ClinicCode.objects.filter(uid=row["OU5uid"]).first()
if clinic:
clinic.code = row["OU5code"]
clinic.value = row["OU5code"]
clinic.name = row["organisationunitname"]
clinic.province = self.get_province(row)
clinic.location = self.get_location(row)
clinic.area_type = row["OrgUnitRuralUrban"]
clinic.unit_type = row["OrgUnitType"]
clinic.district = row["OU3short"]
Expand Down

0 comments on commit 3104856

Please sign in to comment.