2020
2121ContextType = TypeVar ("ContextType" )
2222
23+ START_ROW = 4
24+
25+
26+ # NOTE(IMPORTANT): These mappings should align with templates and serializer fields.
27+ # Also make sure to update export.py if there are changes here in the headers.
28+
29+
30+ BASE_HEADER_MAP = {
31+ "Date of Update" : "date_of_data" ,
32+ "Local Unit Name (En)" : "english_branch_name" ,
33+ "Local Unit Name (Local)" : "local_branch_name" ,
34+ "Visibility" : "visibility" ,
35+ "Coverage" : "level" ,
36+ "Sub-type" : "subtype" ,
37+ "Focal Person (En)" : "focal_person_en" ,
38+ "Source (En)" : "source_en" ,
39+ "Source (Local)" : "source_loc" ,
40+ "Focal Person (Local)" : "focal_person_loc" ,
41+ "Address (Local)" : "address_loc" ,
42+ "Address (En)" : "address_en" ,
43+ "Locality (Local)" : "city_loc" ,
44+ "Locality (En)" : "city_en" ,
45+ "Local Unit Post Code" : "postcode" ,
46+ "Local Unit Email" : "email" ,
47+ "Local Unit Phone Number" : "phone" ,
48+ "Local Unit Website" : "link" ,
49+ "Latitude" : "latitude" ,
50+ "Longitude" : "longitude" ,
51+ }
52+
53+ HEALTH_HEADER_MAP = {
54+ ** BASE_HEADER_MAP ,
55+ ** {
56+ "Focal Person Name (En)" : "focal_person_en" ,
57+ "Focal Person Name (Local)" : "focal_person_loc" ,
58+ "Focal Person Email" : "focal_point_email" ,
59+ "Focal Person Phone Number" : "focal_point_phone_number" ,
60+ "Focal Person Position" : "focal_point_position" ,
61+ "Health Facility Type" : "health_facility_type" ,
62+ "Other Facility Type" : "other_facility_type" ,
63+ "Affiliation" : "affiliation" ,
64+ "Other Affiliation" : "other_affiliation" ,
65+ "Functionality" : "functionality" ,
66+ "Primary Health Care Center" : "primary_health_care_center" ,
67+ "Specialities" : "speciality" ,
68+ "Hospital Type" : "hospital_type" ,
69+ "Teaching Hospital" : "is_teaching_hospital" ,
70+ "In-patient Capacity" : "is_in_patient_capacity" ,
71+ "Isolation Rooms" : "is_isolation_rooms_wards" ,
72+ "Number of Isolation Beds" : "number_of_isolation_rooms" ,
73+ "Warehousing" : "is_warehousing" ,
74+ "Cold Chain" : "is_cold_chain" ,
75+ "Other Medical Heal" : "other_medical_heal" ,
76+ "Maximum Bed Capacity" : "maximum_capacity" ,
77+ "General Medical Services" : "general_medical_services" ,
78+ "Specialized Medical Services (beyond primary level)" : "specialized_medical_beyond_primary_level" ,
79+ "Blood Services" : "blood_services" ,
80+ "Other Services" : "other_services" ,
81+ "Total Number of Human Resources" : "total_number_of_human_resource" ,
82+ "General Practitioners" : "general_practitioner" ,
83+ "Resident Doctors" : "residents_doctor" ,
84+ "Specialists" : "specialist" ,
85+ "Nurses" : "nurse" ,
86+ "Nursing Aids" : "nursing_aid" ,
87+ "Dentists" : "dentist" ,
88+ "Midwife" : "midwife" ,
89+ "Pharmacists" : "pharmacists" ,
90+ "Other Profiles" : "other_profiles" ,
91+ "Other Training Facility" : "other_training_facilities" ,
92+ "Professional Training Facilities" : "professional_training_facilities" ,
93+ "Ambulance Type A" : "ambulance_type_a" ,
94+ "Ambulance Type B" : "ambulance_type_b" ,
95+ "Ambulance Type C" : "ambulance_type_c" ,
96+ },
97+ }
98+
2399
24100class BulkUploadError (Exception ):
25101 """Custom exception for bulk upload errors."""
@@ -137,7 +213,7 @@ def delete_existing_local_unit(self):
137213 def _validate_type (self , fieldnames ) -> None :
138214 pass
139215
140- def is_excel_data_empty (self , sheet , data_start_row = 4 ):
216+ def is_excel_data_empty (self , sheet , data_start_row = START_ROW ):
141217 """Check if file is empty or not"""
142218 for row in sheet .iter_rows (values_only = True , min_row = data_start_row ):
143219 if any (cell is not None for cell in row ):
@@ -238,7 +314,7 @@ def _finalize_failure(self) -> None:
238314 self .bulk_upload .status = LocalUnitBulkUpload .Status .FAILED
239315 self .bulk_upload .save (update_fields = ["success_count" , "failed_count" , "status" , "error_file" ])
240316
241- logger .info (f"[BulkUpload:{ self .bulk_upload .pk } ] FAILED : " f"{ self .success_count } succeeded , { self .failed_count } failed ." )
317+ logger .info (f"[BulkUpload:{ self .bulk_upload .pk } ] SUMMARY : " f"{ self .success_count } SUCCESS , { self .failed_count } FAILED ." )
242318
243319
244320@dataclass (frozen = True )
@@ -250,28 +326,7 @@ class LocalUnitUploadContext:
250326
251327
252328class BaseBulkUploadLocalUnit (BaseBulkUpload [LocalUnitUploadContext ]):
253- HEADER_MAP = {
254- "Date of Update" : "date_of_data" ,
255- "Local Unit Name (En)" : "english_branch_name" ,
256- "Local Unit Name (Local)" : "local_branch_name" ,
257- "Visibility" : "visibility" ,
258- "Coverage" : "level" ,
259- "Sub-type" : "subtype" ,
260- "Focal Person (En)" : "focal_person_en" ,
261- "Source (En)" : "source_en" ,
262- "Source (Local)" : "source_loc" ,
263- "Focal Person (Local)" : "focal_person_loc" ,
264- "Address (Local)" : "address_loc" ,
265- "Address (En)" : "address_en" ,
266- "Locality (Local)" : "city_loc" ,
267- "Locality (En)" : "city_en" ,
268- "Local Unit Post Code" : "postcode" ,
269- "Local Unit Email" : "email" ,
270- "Local Unit Phone Number" : "phone" ,
271- "Local Unit Website" : "link" ,
272- "Latitude" : "latitude" ,
273- "Longitude" : "longitude" ,
274- }
329+ HEADER_MAP = BASE_HEADER_MAP
275330
276331 def __init__ (self , bulk_upload : LocalUnitBulkUpload ):
277332 from local_units .serializers import LocalUnitBulkUploadDetailSerializer
@@ -315,48 +370,8 @@ def _validate_type(self, fieldnames: list[str]) -> None:
315370
316371class BulkUploadHealthData (BaseBulkUpload [LocalUnitUploadContext ]):
317372 # Local Unit headers + Health Data headers
318- HEADER_MAP = {
319- ** BaseBulkUploadLocalUnit .HEADER_MAP ,
320- ** {
321- "Focal Person Email" : "focal_point_email" ,
322- "Focal Person Phone Number" : "focal_point_phone_number" ,
323- "Focal Person Position" : "focal_point_position" ,
324- "Health Facility Type" : "health_facility_type" ,
325- "Other Facility Type" : "other_facility_type" ,
326- "Affiliation" : "affiliation" ,
327- "Other Affiliation" : "other_affiliation" ,
328- "Functionality" : "functionality" ,
329- "Primary Health Care Center" : "primary_health_care_center" ,
330- "Specialities" : "speciality" ,
331- "Hospital Type" : "hospital_type" ,
332- "Teaching Hospital" : "is_teaching_hospital" ,
333- "In-patient Capacity" : "is_in_patient_capacity" ,
334- "Isolation Rooms" : "is_isolation_rooms_wards" ,
335- "Number of Isolation Beds" : "number_of_isolation_rooms" ,
336- "Warehousing" : "is_warehousing" ,
337- "Cold Chain" : "is_cold_chain" ,
338- "Maximum Bed Capacity" : "maximum_capacity" ,
339- "General Medical Services" : "general_medical_services" ,
340- "Specialized Medical Services (beyond primary level)" : "specialized_medical_beyond_primary_level" ,
341- "Blood Services" : "blood_services" ,
342- "Other Services" : "other_services" ,
343- "Total Number of Human Resources" : "total_number_of_human_resource" ,
344- "General Practitioners" : "general_practitioner" ,
345- "Resident Doctors" : "residents_doctor" ,
346- "Specialists" : "specialist" ,
347- "Nurses" : "nurse" ,
348- "Nursing Aids" : "nursing_aid" ,
349- "Dentists" : "dentist" ,
350- "Midwife" : "midwife" ,
351- "Pharmacists" : "pharmacists" ,
352- "Other Profiles" : "other_profiles" ,
353- "Other Training Facility" : "other_training_facilities" ,
354- "Professional Training Facilities" : "professional_training_facilities" ,
355- "Ambulance Type A" : "ambulance_type_a" ,
356- "Ambulance Type B" : "ambulance_type_b" ,
357- "Ambulance Type C" : "ambulance_type_c" ,
358- },
359- }
373+
374+ HEADER_MAP = HEALTH_HEADER_MAP
360375
361376 def __init__ (self , bulk_upload : LocalUnitBulkUpload ):
362377 from local_units .serializers import LocalUnitBulkUploadDetailSerializer
0 commit comments