def assign_orgunits_to_program(self, credentials): api = Api(credentials.url, credentials.login, credentials.password) program_id = "eBAyeGv0exc" orgunits = api.get("organisationUnits", params={"fields": "id", "paging": "false"}).json()["organisationUnits"] program = api.get("programs/" + program_id, params={"fields": ":all"}).json() program["organisationUnits"] = orgunits api.put("programs/" + program_id, program)
def main(): args = parse_args() setup_logger() api = Api(server=args.server, username=args.username, password=args.password) p = { 'paging': False, 'filter': 'name:like:HNQIS', 'fields': 'id,name' } programs = api.get('programs', params=p) print("event_date,program,name,event,_OverallScore,0CS-100,diff") fix_them = [] csparams = { 'filter': ['shortName:like:.0CS-100', 'name:!ilike:_DEL'], 'paging': False, 'fields': 'id' } root_compscores = [x['id'] for x in api.get('dataElements', params=csparams).json()['dataElements']] for p in programs['programs']: params = { 'program': p['id'], 'skipPaging': True, 'fields': '[*]' } events = api.get('events', params=params).json() for event in events['events']: if analyze_event(p, event, root_compscores): fix_them.append(event) if fix_them and args.fix_values: logger.info(u"Fixing those events and resetting _Order Forward...") for i, e in enumerate(fix_them, 1): fixed = fix_event(e, root_compscores) logger.info(u"[{}/{}] Pushing event {}...".format(i, len(fix_them), e['event'])) api.put('events/{}'.format(e['event']), data=fixed) else: logger.warn(u"Not fixing events")
def main(): args = parse_args() setup_logger() api = Api(server=args.server, username=args.username, password=args.password) if not is_valid_uid(args.attribute_uid): logger.error("Attribute {} is not a valid UID".format(args.attribute_uid)) data = list(load_csv(args.source_csv)) validate_csv(data) attr_get = {'fields': 'id,name,{}Attribute'.format(args.object_type[:-1])} attr = api.get('attributes/{}'.format(args.attribute_uid), params=attr_get).json() if attr['{}Attribute'.format(args.object_type[:-1])] is False: logger.error("Attribute {} is not assigned to type {}".format(args.attribute_uid, args.object_type[:-1])) logger.info( "[{}] - Updating Attribute Values for Attribute \033[1m{}\033[0m for \033[1m{}\033[0m \033[1m{}\033[0m...".format( args.server, args.attribute_uid, len(data), args.object_type)) try: time.sleep(3) except KeyboardInterrupt: logger.warn("\033[1m{}\033[0m".format("Aborted!")) pass for i, obj in enumerate(data, 1): obj_uid = obj.get('key') attribute_value = obj.get('value') params_get = {'fields': ':owner'} obj_old = api.get('{}/{}'.format(args.object_type, obj_uid), params=params_get).json() obj_updated = create_or_update_attributevalues(obj=obj_old, attribute_uid=args.attribute_uid, attribute_value=attribute_value) api.put('{}/{}'.format(args.object_type, obj_uid), params=None, data=obj_updated) logger.info(u"{}/{} - Updated AttributeValue: {} - {}: {}".format(i, len(data), attribute_value, args.object_type[:-1], obj_uid))