Пример #1
0
def generate_code_to_revert_modifications(df):
    for id_, group in modified.groupby('id'):
        redcap = group[group._merge == "redcap"].iloc[0]
        ksads = group[group._merge != "redcap"].iloc[0]

        cols = h.unequal_columns(group.iloc[:,:-1])
        print(f"\n    # {id_}", file=file)
        for col in cols:
            vr, vk = redcap[col], ksads[col]
            if isna(vr) and isna(vk):
                continue

            escaped_new = escape_value(ksads[col])
            escaped_permanent = escape_value(redcap[col])

            print(f'    modify(df, {id_}, "{col}", {escaped_new}, {escaped_permanent})', file=file)
Пример #2
0
    def show_modified(self):
        form, added, deleted, modified = self.form, self.added, self.deleted, self.modified

        def update(btn):
            self.added = (dups.loc[[
                dd.value for dd in selections
            ]].iloc[:, :-1].append(self.added, sort=False).drop_duplicates(
                ["patientid", "patienttype"]))

        btn = wg.Button(description="Submit changes")
        btn.on_click(update)

        dups = h.intersection(
            self.redcap_df,
            self.added,
            ["patientid", "patienttype"],
            sources=("current", "new"),
        ).reset_index(drop=True)
        selections = []
        output = []
        for id, group in dups.groupby("id"):
            cols = ["id", "patientid"] + h.unequal_columns(group)
            show = group[cols].set_index("_merge")
            sheet = ipysheet.sheet(ipysheet.from_dataframe(show))
            options = [(k, v) for v, k in group._merge.items()]

            dd = wg.Dropdown(
                options=options,
                value=options[0][1],
                description="Keep version:",
                disabled=False,
            )
            selections.append(dd)
            output.append(sheet)
            output.append(dd)

        if output:
            display(
                HTML(
                    "<H3>Should New Data Overwrite Old Data</H3><SMALL>Please select which version to keep.</SMALL>"
                ))
            for x in output:
                display(x)
            display(btn)