Exemplo n.º 1
0
    def update(self):
        make_similar(self.old, self.new)
        self.deleted = h.diff(self.old, self.new.id)
        self.modified = h.intersection(self.old, self.new,
                                       "id").sort_values("id")
        added = h.diff(self.new, self.old.id)
        added[self.form_complete] = 1
        added["common_complete"] = 1
        make_similar(added, self.redcap_df)
        added = h.diff(added, self.redcap_df)
        self.added = added

        if added is not None and not added.empty:
            self.merged = self.redcap_df.append(added, sort=False)
        else:
            self.merged = self.redcap_df
Exemplo n.º 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)