///<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); }
///<summary>Attempts to open the document using the default program. If not using AtoZfolder saves a local temp file and opens it.</summary> public static void OpenDoc(long docNum) { Document docCur = Documents.GetByNum(docNum); if (docCur.DocNum == 0) { return; } Patient patCur = Patients.GetPat(docCur.PatNum); if (patCur == null) { return; } string docPath; if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ) { docPath = ImageStore.GetFilePath(docCur, ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath())); } else if (PrefC.AtoZfolderUsed == DataStorageType.InDatabase) { //Some programs require a file on disk and cannot open in memory files. Save to temp file from DB. docPath = PrefC.GetRandomTempFile(ImageStore.GetExtension(docCur)); File.WriteAllBytes(docPath, Convert.FromBase64String(docCur.RawBase64)); } else //Cloud storage //Download file to temp directory { OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.Download(ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath()) , docCur.FileName); docPath = PrefC.GetRandomTempFile(ImageStore.GetExtension(docCur)); if (ODBuild.IsWeb()) { ThinfinityUtils.HandleFile(docPath); return; } File.WriteAllBytes(docPath, state.FileContent); } Process.Start(docPath); }
//Checks to see if the document exists in the correct location, or checks DB for stored content. public static bool DocExists(long docNum) { Document docCur = Documents.GetByNum(docNum); if (docCur.DocNum == 0) { return(false); } Patient patCur = Patients.GetPat(docCur.PatNum); if (patCur == null) { return(false); } if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ) { return(File.Exists(ImageStore.GetFilePath(docCur, ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath())))); } else if (CloudStorage.IsCloudStorage) { return(CloudStorage.FileExists(ODFileUtils.CombinePaths(ImageStore.GetPatientFolder(patCur, ImageStore.GetPreferredAtoZpath()), docCur.FileName, '/'))); } return(!string.IsNullOrEmpty(docCur.RawBase64)); }