Skip to content

Commit

Permalink
Changed the first argument of push_facility_updates_to_dhis2 method t…
Browse files Browse the repository at this point in the history
…o parent_id and modified the log messages
  • Loading branch information
ertush committed Jul 24, 2024
1 parent fc827aa commit c4ab289
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions facilities/models/facility_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ def push_facility_metadata(self, metadata_payload, facility_uid):
# }
# )

def push_facility_updates_to_dhis2(self, org_unit_id, facility_updates_payload):
def push_facility_updates_to_dhis2(self, parent_id, facility_updates_payload):
r = requests.put(

settings.DHIS_ENDPOINT + "api/organisationUnits/"+org_unit_id[0],
settings.DHIS_ENDPOINT + "api/organisationUnits/" + parent_id,

auth=(settings.DHIS_USERNAME, settings.DHIS_PASSWORD),
headers={
Expand All @@ -302,7 +302,7 @@ def push_facility_updates_to_dhis2(self, org_unit_id, facility_updates_payload):


print("Update Facility Response", r.url, r.status_code, r.json())
LOGGER.info('[>>>>>>>>>>>>>] Org_unit_id: {} \n payload: {} \n response: {}'.format(org_unit_id, facility_updates_payload, r.json()))
LOGGER.info('[DEBUG]: parent_id: {} \n [DEBUG]: payload: {} \n [DEBUG]: response: {}'.format(parent_id, facility_updates_payload, r.json()))


if r.json()["status"] != "OK":
Expand All @@ -317,7 +317,7 @@ def push_facility_updates_to_dhis2(self, org_unit_id, facility_updates_payload):

raise ValidationError(
{
"Error!": ["Unable to push facility updates to KHIS. Created a new facility {}".format(r.text())]
"Error!": ["Unable to push facility updates to KHIS. Created a new facility {}".format(r)]
}
)
else:
Expand Down Expand Up @@ -719,7 +719,7 @@ def _ensure_a_user_is_linked_to_just_one_regulator(self):
else:
msg = "The user {0} was successfully linked to the regulator {1}"\
"".format(self.user.id, self.regulatory_body.id)
LOGGER.info(msg)
LOGGER.info("[DEBUG]: {}".format(msg))

def make_user_national_user(self):
self.user.is_national = True
Expand Down Expand Up @@ -1861,7 +1861,7 @@ def _dump_updates(self, origi_model):
return json.dumps(data)
else:
message = "The facility was not scheduled for update"
LOGGER.info(message)
LOGGER.info("[DEBUG]: {}".format(message))

def index_facility_material_view(self):
"""
Expand Down Expand Up @@ -2284,7 +2284,7 @@ def push_facility_updates(self):
self.dhis2_api_auth.get_oauth2_token()

dhis2_parent_id = self.dhis2_api_auth.get_parent_id(self.facility.ward.code)
dhis2_org_unit_id = self.dhis2_api_auth.get_org_unit_id(self.facility.code)
# dhis2_org_unit_id = self.dhis2_api_auth.get_org_unit_id(self.facility.code)

coordinates = self.dhis2_api_auth.format_coordinates(
re.search(r'\((.*?)\)', str(FacilityCoordinates.objects.values('coordinates')
Expand All @@ -2309,7 +2309,7 @@ def push_facility_updates(self):
#
print("New Facility Push Payload => ", new_facility_updates_payload)

self.dhis2_api_auth.push_facility_updates_to_dhis2(dhis2_org_unit_id, new_facility_updates_payload)
self.dhis2_api_auth.push_facility_updates_to_dhis2(dhis2_parent_id, new_facility_updates_payload)

def clean(self, *args, **kwargs):
self.validate_only_one_update_at_a_time()
Expand Down

0 comments on commit c4ab289

Please sign in to comment.