示例#1
0
def update_groups(conn):
    cur_select = conn.cursor()

    cur_select.execute("SELECT id, mfl_name FROM common_orgunitgroupsmapping")

    for id, mfl_name in cur_select.fetchall():
        mfl_name = "MFL-" + mfl_name
        print("Processing " + mfl_name + "...")

        response = get_org_unit_group_ids(mfl_name)
        cur_update = conn.cursor()
        cur_update.execute("UPDATE common_orgunitgroupsmapping SET " +
                           "dhis_name = '" +
                           str(response["dhis_name"].replace("'", "''")) +
                           "', " + "dhis_id = '" + str(response["dhis_id"]) +
                           "', "
                           "group_set_ids = '" +
                           str(response["group_set_ids"]).replace("'", "''") +
                           "', "
                           "group_code = '" + str(response["group_code"]) +
                           "' " + "WHERE id = '" + str(id) + "'")
        conn.commit()
        print("Updated " + mfl_name + "\n\n_________________________\n\n")
        cur_update.close()

    cur_select.close()
    print("Done.")
示例#2
0
def copy_facility_regulating_body():
    cur_select = conn.cursor()

    cur_select.execute("SELECT name, id FROM facilities_regulatingbody")

    for name, _id in cur_select.fetchall():
        cur_insert = conn.cursor()
        name = str(name).replace("'", "''")
        cur_insert.execute(
            "INSERT INTO common_orgunitgroupsmapping (mfl_name, created, updated) "
            + " VALUES ('" + str(name) + "', '" +
            str(datetime.datetime.now()) + "', '" +
            str(datetime.datetime.now()) + "')")
        print("Inserted Facility Regulating Body - " + str(name))
        # print(str(cur_insert), str(cur_select))
        conn.commit()
        cur_insert.close()

    cur_select.close()
示例#3
0
def copy_facility_keph_levels():
    cur_select = conn.cursor()

    cur_select.execute(
        "SELECT DISTINCT ON (name) name, id FROM facilities_kephlevel")

    for name, _id in cur_select.fetchall():
        cur_insert = conn.cursor()
        name = str(name).replace("'", "''")
        cur_insert.execute(
            "INSERT INTO common_orgunitgroupsmapping (mfl_name, created, updated) "
            + " VALUES ('" + "KEPH " + str(name) + "', '" +
            str(datetime.datetime.now()) + "', '" +
            str(datetime.datetime.now()) + "')")
        print("Inserted KEPH Level - " + str(name))
        # print(str(cur_insert), str(cur_select))
        conn.commit()
        cur_insert.close()

    cur_select.close()
示例#4
0
def copy_facility_type():
    cur_select = conn.cursor()

    cur_select.execute(
        "SELECT DISTINCT ON (sub_division) sub_division, id FROM facilities_facilitytype WHERE sub_division IS NOT NULL"
    )

    for sub_division, _id in cur_select.fetchall():
        cur_insert = conn.cursor()
        sub_division = str(sub_division).replace("'", "''")
        cur_insert.execute(
            "INSERT INTO common_orgunitgroupsmapping (mfl_name, created, updated) "
            + " VALUES ('" + str(sub_division) + "', '" +
            str(datetime.datetime.now()) + "', '" +
            str(datetime.datetime.now()) + "')")
        print("Inserted Facility Type - " + str(sub_division))
        # print(str(cur_insert), str(cur_select))
        conn.commit()
        cur_insert.close()

    cur_select.close()