diff --git a/contrib/util/dupecheck/mergerecords.php b/contrib/util/dupecheck/mergerecords.php new file mode 100644 index 00000000000..dad7a71b187 --- /dev/null +++ b/contrib/util/dupecheck/mergerecords.php @@ -0,0 +1,146 @@ + + + + + +"; + + UpdateTable("batchcom", "patient_id", $otherPID, $masterPID); + UpdateTable("immunizations", "patient_id", $otherPID, $masterPID); + UpdateTable("prescriptions", "patient_id", $otherPID, $masterPID); + UpdateTable("claims", "patient_id", $otherPID, $masterPID); + + UpdateTable("ar_activity", "pid", $otherPID, $masterPID); + UpdateTable("billing", "pid", $otherPID, $masterPID); + UpdateTable("drug_sales", "pid", $otherPID, $masterPID); + UpdateTable("issue_encounter", "pid", $otherPID, $masterPID); + UpdateTable("lists", "pid", $otherPID, $masterPID); + UpdateTable("payments", "pid", $otherPID, $masterPID); + UpdateTable("pnotes", "pid", $otherPID, $masterPID); + UpdateTable("transactions", "pid", $otherPID, $masterPID); + + UpdateTable("chart_tracker", "ct_pid", $otherPID, $masterPID); + UpdateTable("openemr_postcalendar_events", "pc_pid", $otherPID, $masterPID); + UpdateTable("documents", "foreign_id", $otherPID, $masterPID); + + // update all the forms* tables + $sqlstmt = "show tables like 'form%'"; + $qResults = mysql_query($sqlstmt, $oemrdb); + while ($row = mysql_fetch_assoc($qResults)) { + UpdateTable($row['Tables_in_'.$sqlconf["dbase"].' (form%)'], "pid", $otherPID, $masterPID); + } + + // How to handle the data that should be unique to each patient: + // Demographics, Employment, Insurance, and History ?? + // + //UpdateTable("patient_data", "pid", $otherID, $$parameters['masterid']); + //UpdateTable("employer_data", "pid", $otherPID, $masterPID); + //UpdateTable("history_data", "pid", $otherPID, $masterPID); + //UpdateTable("insurance_data", "pid", $otherPID, $masterPID); + + // alter the patient's last name to indicate they have been merged into another record + $newlname = "~~~MERGED~~~".$orow['lname']; + $sqlstmt = "update patient_data set lname='".$newlname."' where pid='".$otherPID."'"; + if ($commitchanges == true) $qResults = mysql_query($sqlstmt, $oemrdb); + echo "
  • Altered last name of PID ".$otherPID." to '".$newlname."'
  • "; + + // add patient notes regarding the merged data + $notetext = "All related patient data has been merged into patient record PID# ".$masterPID; + echo "
  • Added note about the merge to the PID ".$otherPID."
  • "; + if ($commitchanges == true) addPnote($otherPID, $notetext); + + $notetext = "All related patient data has been merged from patient record PID# ".$otherPID; + echo "
  • Added note about the merge to the Master PID ".$masterPID."
  • "; + if ($commitchanges == true) addPnote($masterPID, $notetext); + + // add a log entry regarding the merged data + if ($commitchanges == true) newEvent("data_merge", $_SESSION['authUser'], "Default", "Merged PID ".$otherPID." data into master PID ".$masterPID); + echo "
  • Added entry to log
  • "; + + echo "

    "; +} // end of otherID loop + +function UpdateTable($tablename, $pid_col, $oldvalue, $newvalue) { + global $commitchanges, $oemrdb; + + $sqlstmt = "select count(*) as numrows from ".$tablename." where ".$pid_col."='".$oldvalue."'"; + $qResults = mysql_query($sqlstmt, $oemrdb); + + if ($qResults) { + $row = mysql_fetch_assoc($qResults); + if ($row['numrows'] > 0) { + $sqlstmt = "update ".$tablename." set ".$pid_col."='".$newvalue."' where ".$pid_col."='".$oldvalue."'"; + if ($commitchanges == true) { + $qResults = mysql_query($sqlstmt, $oemrdb); + } + $rowsupdated = mysql_affected_rows($oemrdb); + echo "
  • "; + echo "".$tablename.": ".$rowsupdated." row(s) updated
    "; + echo "
  • "; + } + } + + +} + +?> + + +Nothing has been changed yet. What you see above are the changes that will be made if you choose to commit them.
    +Do you wish to commit these changes to the database? +
    + + +"; +} +?> + + +
    + +Close this window + + + + + + +