///<summary>Deletes the passed in list of statements. Checks for permission before deleting the stored image in ODI folder. Can force to delete the ///stored image without the permission check. Will always delete the statement object. Throws UE.</summary> public static void DeleteStatements(List <Statement> listStatements, bool forceImageDelete = false) { if (listStatements.IsNullOrEmpty()) { return; } if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), listStatements, forceImageDelete); return; } foreach (Statement stmt in listStatements) { //Per Nathan the image should not be deleted if the user does not have the Image Delete permission. The statement can still be deleted. if (stmt.DocNum != 0 && (forceImageDelete || Security.IsAuthorized(Permissions.ImageDelete, stmt.DateSent, true))) { //deleted the pdf Patient pat = Patients.GetPat(stmt.PatNum); string patFolder = ImageStore.GetPatientFolder(pat, ImageStore.GetPreferredAtoZpath()); List <Document> listdocs = new List <Document>(); listdocs.Add(Documents.GetByNum(stmt.DocNum, true)); ImageStore.DeleteDocuments(listdocs, patFolder); //May throw if document is in use. } Delete(stmt); } }
///<summary>Cascading delete that deletes all MedLab, MedLabResult, MedLabSpecimen, and MedLabFacAttach. ///Also deletes any embedded PDFs that are linked to by the MedLabResults. ///The MedLabs and all associated results, specimens, and FacAttaches referenced by the MedLabNums in listExcludeMedLabNums will not be deleted. ///Used for deleting old entries and keeping new ones. The list may be empty and then all will be deleted.</summary> public static int DeleteLabsAndResults(MedLab medLab, List <long> listExcludeMedLabNums = null) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { return(Meth.GetInt(MethodBase.GetCurrentMethod(), medLab, listExcludeMedLabNums)); } List <MedLab> listLabsOld = MedLabs.GetForPatAndSpecimen(medLab.PatNum, medLab.SpecimenID, medLab.SpecimenIDFiller); //patNum could be 0 if (listExcludeMedLabNums != null) { listLabsOld = listLabsOld.FindAll(x => !listExcludeMedLabNums.Contains(x.MedLabNum)); } if (listLabsOld.Count < 1) { return(0); } int failedCount = 0; List <long> listLabNumsOld = listLabsOld.Select(x => x.MedLabNum).ToList(); List <MedLabResult> listResultsOld = listLabsOld.SelectMany(x => x.ListMedLabResults).ToList(); //sends one query to the db per MedLab MedLabFacAttaches.DeleteAllForLabsOrResults(listLabNumsOld, listResultsOld.Select(x => x.MedLabResultNum).ToList()); MedLabSpecimens.DeleteAllForLabs(listLabNumsOld); //MedLabSpecimens have a FK to MedLabNum MedLabResults.DeleteAllForMedLabs(listLabNumsOld); //MedLabResults have a FK to MedLabNum MedLabs.DeleteAll(listLabNumsOld); foreach (Document doc in Documents.GetByNums(listResultsOld.Select(x => x.DocNum).ToList())) { Patient docPat = Patients.GetPat(doc.PatNum); if (docPat == null) { Documents.Delete(doc); continue; } try { ImageStore.DeleteDocuments(new List <Document> { doc }, ImageStore.GetPatientFolder(docPat, ImageStore.GetPreferredAtoZpath())); } catch (Exception ex) { ex.DoNothing(); //To avoid a warning message. The ex is needed to ensure all exceptions are caught. failedCount++; } } return(failedCount); }