/// <summary>When a patient leaves a superfamily, this copies the superfamily level popups to be in both places. Takes pat leaving, and new superfamily. If newSuperFamily is 0, superfamily popups will not be copied from the old superfamily.</summary> public static void CopyForMovingSuperFamily(Patient pat, long newSuperFamily) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), pat); return; } //Get a list of all popups for the super family string command = "SELECT * FROM popup " + "WHERE PopupLevel = " + POut.Int((int)EnumPopupLevel.SuperFamily) + " " + "AND PatNum IN (SELECT PatNum FROM patient WHERE SuperFamily = " + POut.Long(pat.SuperFamily) + ")"; List <Popup> SuperFamilyPopups = Crud.PopupCrud.SelectMany(command); Popup popup; for (int i = 0; i < SuperFamilyPopups.Count; i++) { popup = SuperFamilyPopups[i].Copy(); if (popup.PatNum == pat.PatNum) //if popup is on the patient who's leaving, copy to superfamily head of old superfamily. { popup.PatNum = pat.SuperFamily; if (newSuperFamily == 0) //If they are not going to a superfamily, delete the popup { Popups.DeleteObject(SuperFamilyPopups[i]); } } else //if popup is on some other super family member, then copy to this patient. { if (newSuperFamily != 0) //Only if they are moving to a superfamily. { popup.PatNum = pat.PatNum; } } Popups.Insert(popup); //changes the PK } }
/// <summary>Copies all family level popups when a family member leaves a family. Copies from other family members to patient, and from patient to guarantor.</summary> public static void CopyForMovingFamilyMember(Patient pat) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), pat); return; } //Get a list of all popups for the family string command = "SELECT * FROM popup " + "WHERE PopupLevel = " + POut.Int((int)EnumPopupLevel.Family) + " " + "AND PatNum IN (SELECT PatNum FROM patient WHERE Guarantor = " + POut.Long(pat.Guarantor) + ")"; List <Popup> FamilyPopups = Crud.PopupCrud.SelectMany(command); Popup popup; for (int i = 0; i < FamilyPopups.Count; i++) { popup = FamilyPopups[i].Copy(); if (popup.PatNum == pat.PatNum) //if popup is on the patient who's leaving, copy to guarantor of old family. { popup.PatNum = pat.Guarantor; } else //if popup is on some other family member, then copy to this patient. { popup.PatNum = pat.PatNum; } Popups.Insert(popup); //changes the PK } }
/// <summary>When a patient leaves a superfamily, this copies the superfamily level popups to be in both places. Takes pat leaving, and new superfamily. If newSuperFamily is 0, superfamily popups will not be copied from the old superfamily.</summary> public static void CopyForMovingSuperFamily(Patient pat, long newSuperFamily) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), pat, newSuperFamily); return; } //Get a list of all popups for the super family string command = "SELECT * FROM popup " + "WHERE PopupLevel = " + POut.Int((int)EnumPopupLevel.SuperFamily) + " " + "AND PatNum IN (SELECT PatNum FROM patient WHERE SuperFamily = " + POut.Long(pat.SuperFamily) + ")" + "AND PopupNumArchive = 0 "; //This includes all the archived ones as well List <Popup> SuperFamilyPopups = Crud.PopupCrud.SelectMany(command); Popup popupCur; for (int i = 0; i < SuperFamilyPopups.Count; i++) { popupCur = SuperFamilyPopups[i].Copy(); if (popupCur.PatNum == pat.PatNum) //if popup is on the patient who's leaving, copy to superfamily head of old superfamily. { popupCur.PatNum = pat.SuperFamily; if (newSuperFamily == 0) //If they are not going to a superfamily, set popup to family level { string commandUpdateFam = "UPDATE popup " + "SET PopupLevel = " + POut.Int((int)EnumPopupLevel.Family) + " " + "WHERE PopupNum = " + POut.Long(popupCur.PopupNum); Db.NonQ(commandUpdateFam); } } else //if popup is on some other super family member, then copy to this patient. { popupCur.PatNum = pat.PatNum; if (newSuperFamily == 0) //If they are not going to a superfamily, set popup to family level { popupCur.PopupLevel = EnumPopupLevel.Family; } } DateTime oldDate = popupCur.DateTimeEntry; long newPk = Popups.Insert(popupCur); //changes the PK //Update the DateTimeEntry on the copy to correctly reflect when the original popup was created. EditPopupDate(oldDate, newPk); //Now we need to copy all of the archives of the original popup to point to the copy. List <Popup> archivePopups = GetArchivesForPopup(SuperFamilyPopups[i].PopupNum); Popup popupArchive; for (int j = 0; j < archivePopups.Count; j++) { popupArchive = archivePopups[j].Copy(); popupArchive.PopupNumArchive = newPk; DateTime oldArchiveDate = popupArchive.DateTimeEntry; long newArchivePk = Popups.Insert(popupArchive); //changes the PK EditPopupDate(oldArchiveDate, newArchivePk); } } }
/// <summary>Copies all family level popups when a family member leaves a family. Copies from other family members to patient, and from patient to guarantor.</summary> public static void CopyForMovingFamilyMember(Patient pat) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), pat); return; } //Get a list of all popups for the family string command = "SELECT * FROM popup " + "WHERE PopupLevel = " + POut.Int((int)EnumPopupLevel.Family) + " " + "AND PatNum IN (SELECT PatNum FROM patient WHERE Guarantor = " + POut.Long(pat.Guarantor) + ")" + "AND PopupNumArchive = 0 "; List <Popup> FamilyPopups = Crud.PopupCrud.SelectMany(command); Popup popupCur; for (int i = 0; i < FamilyPopups.Count; i++) { popupCur = FamilyPopups[i].Copy(); if (popupCur.PatNum == pat.PatNum) //if popup is on the patient who's leaving, copy to guarantor of old family. { popupCur.PatNum = pat.Guarantor; } else //if popup is on some other family member, then copy to this patient. { popupCur.PatNum = pat.PatNum; } DateTime oldDate = popupCur.DateTimeEntry; long newPk = Popups.Insert(popupCur); //changes the PK EditPopupDate(oldDate, newPk); List <Popup> archivePopups = GetArchivesForPopup(FamilyPopups[i].PopupNum); Popup popupArchive; for (int j = 0; j < archivePopups.Count; j++) { popupArchive = archivePopups[j].Copy(); if (popupArchive.PatNum == pat.PatNum) //if popup is on the patient who's leaving, copy to guarantor of old family. { popupArchive.PatNum = pat.Guarantor; } else //if popup is on some other family member, then copy to this patient. { popupArchive.PatNum = pat.PatNum; } popupArchive.PopupNumArchive = newPk; DateTime oldArchiveDate = popupArchive.DateTimeEntry; long newArchivePk = Popups.Insert(popupArchive); //changes the PK EditPopupDate(oldArchiveDate, newArchivePk); } } }