Ejemplo n.º 1
0
        public static CaseEntry GetCaseEntryLatestVersion(string caseNumber)
        {
            List <CaseEntry> cases = GetListCaseEntry(caseNumber);
            DateTime         latestDateTimeModified = (from latestTimeModified in cases
                                                       orderby latestTimeModified.DateTimeModifiedObject descending
                                                       select latestTimeModified.DateTimeModifiedObject).FirstOrDefault();
            CaseEntry latestCaseEntry = new CaseEntry();

            if (latestDateTimeModified != null)
            {
                latestCaseEntry = (from p in cases.ToList <CaseEntry>()
                                   where p.DateTimeModifiedObject.Equals(latestDateTimeModified)
                                   select p).FirstOrDefault();
            }
            return(latestCaseEntry);
        }
Ejemplo n.º 2
0
        public static void InsertNewCaseEntry(CaseEntry ce, CaselyUserData caselyUserData)
        {
            using (var cn = new SQLiteConnection(DbConnectionString)) {
                cn.Open();
                cn.EnableExtensions(true);
                cn.LoadExtension("SQLite.Interop.dll", "sqlite3_fts5_init"); // this line is required to enable full text search support

                var sql = @"INSERT INTO casely_user_data (case_number, service)
                             VALUES (@CaseNumber, @Service);";
                cn.Execute(sql, caselyUserData);
                sql = @"INSERT INTO case_entry (author_id, case_number, date_modified,
                                                time_modified, tumor_synoptic, comment, result, material, history, interpretation, gross, microscopic)
                            VALUES (@AuthorID, @CaseNumber,@DateModifiedString,@TimeModifiedString,@TumorSynoptic, @Comment, @Result, @Material, @History, 
                                    @Interpretation, @Gross, @Microscopic);";
                cn.Execute(sql, ce);
            }
        }
Ejemplo n.º 3
0
        RichTextBox rtx = new RichTextBox(); // this is used for rich text conversion. Is a global variable so we only create one instance of it.

        public List <CaseEntry> importSoftPathCSVData(string pathToSoftData)
        {
            List <CaseEntry>       caseEntries  = new List <CaseEntry>();
            List <SoftSignoutData> listSoftData = new List <SoftSignoutData>();

            // Extract the CSV data that was export from SoftPath.
            try {
                using (var stream = File.Open(pathToSoftData, FileMode.Open, FileAccess.Read)) {
                    using (var reader = ExcelReaderFactory.CreateReader(stream)) {
                        var result = reader.AsDataSet(new ExcelDataSetConfiguration()
                        {
                            UseColumnDataType  = true,
                            ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration()
                            {
                                UseHeaderRow = true
                            }
                        });
                        var table = result.Tables[0];
                        foreach (DataRow r in table.Rows)
                        {
                            string          frmCaseNum = r["FORMATTEDORDERNUMBER"].ToString() ?? string.Empty;
                            SoftSignoutData sft        = new SoftSignoutData()
                            {
                                CaseNum = frmCaseNum,
                                RegistrationDateTime = r["ORDERREGISTRATIONDATE"].ToString() ?? string.Empty,
                                EnteredDateTime      = DateTime.Parse(r["ENTEREDDATE"].ToString() ?? string.Empty),
                                ResidentID           = r["USERID"].ToString() ?? string.Empty,

                                ResidentInterpretationText = RichTextToPlainText(r["USERINTERPRETATION"].ToString() ?? string.Empty),
                                ResidentResultText         = RichTextToPlainText(r["USERGROSSANDMICRO"].ToString() ?? string.Empty),
                                ResidentCommentText        = RichTextToPlainText(r["USERCOMMENT"].ToString() ?? string.Empty),
                                ResidentSynopticText       = RichTextToPlainText(r["USERSYNOPTIC"].ToString() ?? string.Empty),

                                AttendingInterpretationText = RichTextToPlainText(r["FINALDIAGNOSISRICHTEXT"].ToString() ?? string.Empty),
                                AttendingResultText         = RichTextToPlainText(r["FINALGROSSANDMICRORICHTEXT"].ToString() ?? string.Empty),
                                AttendingCommentText        = RichTextToPlainText(r["FINALCOMMENTRICHTEXT"].ToString() ?? string.Empty),
                                AttendingSynopticText       = RichTextToPlainText(r["FINALSYNOPTICRICHTEXT"].ToString() ?? string.Empty),
                                AttendingID = r["SIGNOUTPATHOLOGIST"].ToString() ?? string.Empty
                            };
                            listSoftData.Add(sft);
                        }
                    }
                }
            } catch (Exception ex) {
                throw new Exception("Cannot open file" + ex.Message);
            }

            // get all the distinct case numbers that were in the softpath export data
            var distCaseNums = listSoftData.GroupBy(x => x.CaseNum).Select(y => y.First()).Distinct().Select(x => x.CaseNum);

            foreach (var c in distCaseNums)
            {
                // get the entries for the current case
                var entriesCurrentCase = listSoftData.Where(x => x.CaseNum == c).OrderBy(f => f.EnteredDateTime);

                // Each row of the softpath data contains the attending final report, therefore we only need one version
                // We have to use the last version so that when we adjust the time, the date is correct (i.e a report that was modified on multiple days by the resident)
                var lastReportVersion = entriesCurrentCase.Last();
                // Get the attending version of the report
                CaseEntry attendCE = new CaseEntry()
                {
                    DateTimeModifiedObject = lastReportVersion.EnteredDateTime.AddHours(1), // make the attending report added later than the resident report
                    CaseNumber             = lastReportVersion.CaseNum,
                    Interpretation         = lastReportVersion.AttendingInterpretationText,
                    Comment       = lastReportVersion.AttendingCommentText,
                    TumorSynoptic = lastReportVersion.AttendingSynopticText,
                    Result        = lastReportVersion.AttendingResultText,
                    AuthorID      = lastReportVersion.AttendingID
                };

                // Iterate through each version of the resident report
                List <CaseEntry> residentVersions = new List <CaseEntry>(); // This variable temporarily stores list of resident report versions
                foreach (var curReportVersion in entriesCurrentCase)
                {
                    CaseEntry resCE = new CaseEntry()
                    {
                        DateTimeModifiedObject = curReportVersion.EnteredDateTime,
                        CaseNumber             = curReportVersion.CaseNum,
                        Interpretation         = curReportVersion.ResidentInterpretationText,
                        Result        = curReportVersion.ResidentResultText,
                        Comment       = curReportVersion.ResidentCommentText,
                        TumorSynoptic = curReportVersion.ResidentSynopticText,
                        AuthorID      = curReportVersion.ResidentID
                    };
                    residentVersions.Add(resCE);
                }
                // Each version of the resident report only stores fields that were changed.
                // For example, if only the interpretation was changed and the report save, than result, comment, tumor synoptic will be blank
                // This for loop fixes that problem by 'updating' even non-saved fields
                for (int i = 1; i < residentVersions.Count; i++)
                {
                    if (residentVersions[i - 1].Interpretation != "" && residentVersions[i].Interpretation == "")
                    {
                        residentVersions[i].Interpretation = residentVersions[i - 1].Interpretation;
                    }
                    if (residentVersions[i - 1].Result != "" && residentVersions[i].Result == "")
                    {
                        residentVersions[i].Result = residentVersions[i - 1].Result;
                    }
                    if (residentVersions[i - 1].Comment != "" && residentVersions[i].Comment == "")
                    {
                        residentVersions[i].Comment = residentVersions[i - 1].Comment;
                    }
                    if (residentVersions[i - 1].TumorSynoptic != "" && residentVersions[i].TumorSynoptic == "")
                    {
                        residentVersions[i].TumorSynoptic = residentVersions[i - 1].TumorSynoptic;
                    }
                }
                caseEntries.AddRange(residentVersions);
                caseEntries.Add(attendCE); // Add attending report after resident version to keep it sorted for debugging
            }
            return(caseEntries);
        }