def fetch_org_units(): """ Synchronize DHIS2 Organization Units with local data. This data is used to fulfill the first requirement of `DHIS2 Integration`_: Allow mobile users in CommCareHQ to be associated with a particular DHIS2 Organisation Unit, so that when they create cases their new cases can be associated with that area or facility. .. _DHIS2 Integration: https://www.dropbox.com/s/8djk1vh797t6cmt/WV Sri Lanka Detailed Requirements.docx """ for settings in Dhis2Settings.all_enabled(): logger.info('DHIS2: Fetching org units for domain "%s" with "%s"', settings.domain, settings.dhis2['host']) dhis2_api = Dhis2Api(settings.dhis2['host'], settings.dhis2['username'], settings.dhis2['password'], settings.dhis2['top_org_unit_name']) Dhis2OrgUnit.objects = FixtureManager(Dhis2OrgUnit, settings.domain, ORG_UNIT_FIXTURES) our_org_units = {ou.id: ou for ou in Dhis2OrgUnit.objects.all()} their_org_units = {} # Add new org units for ou in dhis2_api.gen_org_units(): their_org_units[ou['id']] = ou if ou['id'] not in our_org_units: logger.info('DHIS2: Adding org unit "%s"', ou['name']) org_unit = Dhis2OrgUnit(id=ou['id'], name=ou['name'], parent_id=dhis2_api.get_org_unit_parent_id(ou['id'])) org_unit.save() # Delete former org units for id_, ou in our_org_units.iteritems(): if id_ not in their_org_units: logger.info('DHIS2: Deleting org unit "%s"', ou.name) ou.delete()
def fetch_cases(): """ Import new child cases from DHIS2 for nutrition tracking """ for settings in Dhis2Settings.all_enabled(): logger.info('DHIS2: Fetching cases for domain "%s" from "%s"', settings.domain, settings.dhis2['host']) children = get_children_only_theirs(settings) pull_child_entities(settings, children)
def fetch_cases(): """ Import new child cases from DHIS2 for nutrition tracking """ for settings in Dhis2Settings.all_enabled(): logger.info('DHIS2: Fetching cases for domain "%s" from "%s"', settings.domain, settings.dhis2['host']) children = get_children_only_theirs(settings) pull_child_entities(settings, children)
def fetch_org_units(): """ Synchronize DHIS2 Organization Units with local data. This data is used to fulfill the first requirement of `DHIS2 Integration`_: Allow mobile users in CommCareHQ to be associated with a particular DHIS2 Organisation Unit, so that when they create cases their new cases can be associated with that area or facility. .. _DHIS2 Integration: https://www.dropbox.com/s/8djk1vh797t6cmt/WV Sri Lanka Detailed Requirements.docx """ for settings in Dhis2Settings.all_enabled(): logger.info('DHIS2: Fetching org units for domain "%s" with "%s"', settings.domain, settings.dhis2['host']) dhis2_api = Dhis2Api(settings.dhis2['host'], settings.dhis2['username'], settings.dhis2['password'], settings.dhis2['top_org_unit_name']) Dhis2OrgUnit.objects = FixtureManager(Dhis2OrgUnit, settings.domain, ORG_UNIT_FIXTURES) our_org_units = {ou.id: ou for ou in Dhis2OrgUnit.objects.all()} their_org_units = {} # Add new org units for ou in dhis2_api.gen_org_units(): their_org_units[ou['id']] = ou if ou['id'] not in our_org_units: logger.info('DHIS2: Adding org unit "%s"', ou['name']) org_unit = Dhis2OrgUnit( id=ou['id'], name=ou['name'], parent_id=dhis2_api.get_org_unit_parent_id(ou['id'])) org_unit.save() # Delete former org units for id_, ou in our_org_units.iteritems(): if id_ not in their_org_units: logger.info('DHIS2: Deleting org unit "%s"', ou.name) ou.delete()