Пример #1
0
        public TaggedChemHemRptArrays getChemHemReportsRdv(string fromDate, string toDate, int nrpts)
        {
            TaggedChemHemRptArrays result = new TaggedChemHemRptArrays();

            if (!mySession.ConnectionSet.IsAuthorized)
            {
                result.fault = new FaultTO("Connections not ready for operation", "Need to login?");
            }
            else if (fromDate == "")
            {
                result.fault = new FaultTO("Missing fromDate");
            }
            else if (toDate == "")
            {
                result.fault = new FaultTO("Missing toDate");
            }
            if (result.fault != null)
            {
                return(result);
            }

            try
            {
                IndexedHashtable t = ChemHemReport.getChemHemReports(mySession.ConnectionSet, fromDate, toDate, nrpts);
                result = new TaggedChemHemRptArrays(t);
            }
            catch (Exception e)
            {
                result.fault = new FaultTO(e);
            }
            return(result);
        }
Пример #2
0
        internal IList <LabResult> toLabReportsVPR(string xml, ref ChemHemReport rpt)
        {
            IList <LabResult> rpts = new List <LabResult>();
            int numRecs            = 0;

            using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
            {
                while (reader.Read())
                {
                    if (numRecs > 0)
                    {
                        while (!reader.EOF && rpts.Count < numRecs)
                        {
                            rpts.Add(readLab(reader, ref rpt));
                        }
                    }

                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (String.Equals(reader.Name, "labs", StringComparison.CurrentCultureIgnoreCase))
                        {
                            if (reader.AttributeCount > 0)
                            {
                                string count = reader.GetAttribute("total");
                                if (!Int32.TryParse(reader.Value, out numRecs))
                                {
                                    throw new XmlException("Unexpected format - could not determine number of results\r\n" + xml);
                                }
                            }
                        }

                        break;

                    case XmlNodeType.EndElement:
                        if (String.Equals(reader.Name, "labs", StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }
                        if (String.Equals(reader.Name, "results", StringComparison.CurrentCultureIgnoreCase))
                        {
                            return(rpts);
                        }
                        break;

                    //case XmlNodeType.Comment:
                    //    break;
                    //case XmlNodeType.Document:
                    //    break;
                    //case XmlNodeType.Text:
                    //    break;
                    default:
                        break;
                    }
                }
            }

            return(rpts);
        }
Пример #3
0
 public TaggedChemHemRptArray(string tag, ChemHemReport mdo)
 {
     this.tag = tag;
     if (mdo == null)
     {
         this.count = 0;
         return;
     }
     this.rpts    = new ChemHemRpt[1];
     this.rpts[0] = new ChemHemRpt(mdo);
     this.count   = 1;
 }
Пример #4
0
        public TaggedChemHemRptArray getChemHemReportsByReportDateFromSite(
            string pwd, string sitecode, string mpiPid, string fromDate, string toDate)
        {
            TaggedChemHemRptArray result = new TaggedChemHemRptArray();

            if (String.IsNullOrEmpty(sitecode))
            {
                result.fault = new FaultTO("Missing sitecode");
            }
            else if (mpiPid == "")
            {
                result.fault = new FaultTO("Missing mpiPid");
            }
            else if (fromDate == "")
            {
                result.fault = new FaultTO("Missing fromDate");
            }
            if (result.fault != null)
            {
                return(result);
            }

            if (toDate == "")
            {
                toDate = DateTime.Now.ToString("yyyyMMdd");
            }

            AccountLib acctLib = new AccountLib(mySession);

            try
            {
                // Visit as DoD user...
                SiteArray sites = acctLib.patientVisit(pwd, sitecode, mpiPid, false);
                if (sites.fault != null)
                {
                    result.fault = sites.fault;
                    return(result);
                }

                // Get the labs...
                ChemHemReport[] rpts = ChemHemReport.getChemHemReports(mySession.ConnectionSet.getConnection(sitecode), fromDate, toDate);
                result = new TaggedChemHemRptArray(sitecode, rpts);
            }
            catch (Exception e)
            {
                result.fault = new FaultTO(e.Message);
            }
            finally
            {
                mySession.close();
            }
            return(result);
        }
Пример #5
0
        public IList <ChemHemReport> getChemHemReportsVPR(string fromDate, string toDate)
        {
            VistaClinicalDao clinicalDao = new VistaClinicalDao(this.cxn);
            string           results     = clinicalDao.getNhinData("lab");
            ChemHemReport    rpt         = new ChemHemReport();

            (toLabReportsVPR(results, ref rpt)).CopyTo(rpt.Results, 0);
            return(new List <ChemHemReport>()
            {
                rpt
            });
        }
Пример #6
0
 public TaggedChemHemRptArrays(IndexedHashtable t)
 {
     if (t.Count == 0)
     {
         return;
     }
     arrays = new TaggedChemHemRptArray[t.Count];
     for (int i = 0; i < t.Count; i++)
     {
         if (t.GetValue(i) == null)
         {
             arrays[i] = new TaggedChemHemRptArray((string)t.GetKey(i));
         }
         else if (MdwsUtils.isException(t.GetValue(i)))
         {
             arrays[i] = new TaggedChemHemRptArray((string)t.GetKey(i), (Exception)t.GetValue(i));
         }
         else if (t.GetValue(i).GetType() == typeof(System.Collections.Hashtable))
         {
             IList <ChemHemReport> temp = ((System.Collections.Hashtable)t.GetValue(i))["labs"] as IList <ChemHemReport>;
             if (temp == null || temp.Count == 0)
             {
                 arrays[i] = new TaggedChemHemRptArray((string)t.GetKey(i));
             }
             else
             {
                 ChemHemReport [] ary = new ChemHemReport[temp.Count];
                 temp.CopyTo(ary, 0);
                 arrays[i] = new TaggedChemHemRptArray((string)t.GetKey(i), ary);
             }
         }
         else if (t.GetValue(i).GetType().IsArray)
         {
             arrays[i] = new TaggedChemHemRptArray((string)t.GetKey(i), (ChemHemReport[])t.GetValue(i));
         }
         else
         {
             arrays[i] = new TaggedChemHemRptArray((string)t.GetKey(i), (ChemHemReport)t.GetValue(i));
         }
     }
     count = t.Count;
 }
Пример #7
0
        public ChemHemReport[] getChemHemReports(string dfn, string fromDate, string toDate)
        {
            string commandText = "SELECT TOP(1) * " +
                "FROM Chem.LabChem;";
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = new SqlCommand(commandText);

            adapter.SelectCommand.CommandTimeout = 600; // allow query to run for up to 10 minutes

            using (_cxn)
            {
                SqlDataReader reader = (SqlDataReader)_cxn.query(adapter);

                IList<ChemHemReport> results = new List<ChemHemReport>();

                while (reader.Read())
                {
                    if (reader.IsDBNull(1))
                    {
                        continue;
                    }
                    string labSid = ((Int64)reader[reader.GetOrdinal("LabChemSID")]).ToString();
                    string specimen = (string)reader[reader.GetOrdinal("Specimen")];
                    string siteId = ((Int16)reader[reader.GetOrdinal("Sta3n")]).ToString();
                    string testIen = (string)reader[reader.GetOrdinal("LabChemTestIEN")];
                    //DateTime completedTimestamp = (DateTime)reader[reader.GetOrdinal("LabChemCompleteDateTime")];

                    ChemHemReport result = new ChemHemReport()
                    {
                        Id = testIen,
                        Specimen = new LabSpecimen("", specimen, "", "")
                    };

                    results.Add(result);

                }
                return results.ToArray<ChemHemReport>();
            }
        }
Пример #8
0
        public ChemHemReport[] getChemHemReports(string dfn, string fromDate, string toDate)
        {
            string commandText = "SELECT TOP(1) * " +
                                 "FROM Chem.LabChem;";
            SqlDataAdapter adapter = new SqlDataAdapter();

            adapter.SelectCommand = new SqlCommand(commandText);

            adapter.SelectCommand.CommandTimeout = 600; // allow query to run for up to 10 minutes

            using (_cxn)
            {
                SqlDataReader reader = (SqlDataReader)_cxn.query(adapter);

                IList <ChemHemReport> results = new List <ChemHemReport>();

                while (reader.Read())
                {
                    if (reader.IsDBNull(1))
                    {
                        continue;
                    }
                    string labSid   = ((Int64)reader[reader.GetOrdinal("LabChemSID")]).ToString();
                    string specimen = (string)reader[reader.GetOrdinal("Specimen")];
                    string siteId   = ((Int16)reader[reader.GetOrdinal("Sta3n")]).ToString();
                    string testIen  = (string)reader[reader.GetOrdinal("LabChemTestIEN")];
                    //DateTime completedTimestamp = (DateTime)reader[reader.GetOrdinal("LabChemCompleteDateTime")];

                    ChemHemReport result = new ChemHemReport()
                    {
                        Id       = testIen,
                        Specimen = new LabSpecimen("", specimen, "", "")
                    };

                    results.Add(result);
                }
                return(results.ToArray <ChemHemReport>());
            }
        }
Пример #9
0
 public ChemHemRpt(ChemHemReport mdo)
 {
     this.id        = mdo.Id;
     this.title     = mdo.Title;
     this.timestamp = mdo.Timestamp;
     if (mdo.Author != null)
     {
         this.author = new AuthorTO(mdo.Author);
     }
     if (mdo.Facility != null)
     {
         this.facility = new TaggedText(mdo.Facility.Id, mdo.Facility.Name);
     }
     if (mdo.Specimen != null)
     {
         this.specimen = new LabSpecimenTO(mdo.Specimen);
     }
     this.comment = mdo.Comment;
     if (mdo.Results != null)
     {
         this.results = new LabResultTO[mdo.Results.Length];
         for (int i = 0; i < mdo.Results.Length; i++)
         {
             this.results[i] = new LabResultTO(mdo.Results[i]);
         }
     }
     if (mdo.LabSites != null)
     {
         this.labSites = new SiteTO[mdo.LabSites.Count];
         int i = 0;
         foreach (DictionaryEntry de in mdo.LabSites)
         {
             this.labSites[i++] = new SiteTO((Site)de.Value);
         }
     }
 }
Пример #10
0
        // it appears we're missing local IEN that maps to LabReport.Id
        LabResult readLab(XmlReader reader, ref ChemHemReport rpt)
        {
            LabResult result = new LabResult();
            result.Test = new LabTest();

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.EndElement && String.Equals(reader.Name, "lab", StringComparison.CurrentCultureIgnoreCase))
                {
                    break;
                }
                switch (reader.Name)
                {
                    case "collected":
                        if (reader.HasAttributes)
                        {
                            rpt.Specimen.CollectionDate = reader.GetAttribute("value");
                        }
                        break;
                    case "comment":
                        result.Comment = reader.GetAttribute("value");
                        break;
                    case "facility":
                        if (reader.HasAttributes)
                        {
                            rpt.Facility = new SiteId(reader.GetAttribute("code"), reader.GetAttribute("name"));
                        }
                        break;
                    case "groupName":
                        if (reader.HasAttributes)
                        {
                            rpt.Specimen.AccessionNumber = reader.GetAttribute("value");
                        }
                        break;
                    case "high":
                        result.Test.HiRef = reader.GetAttribute("value");
                        break;
                    case "id":
                        if (reader.HasAttributes)
                        {
                            rpt.Id = reader.GetAttribute("value"); // not the same as old ChemHemRpts ID!!!
                        }
                        break;
                    case "interpretation":
                        break;
                    case "labOrderID":
                        break;
                    case "localName":
                        result.Test.ShortName = reader.GetAttribute("value");
                        break;
                    case "loinc":
                        result.Test.Loinc = reader.GetAttribute("value");
                        break;
                    case "low":
                        result.Test.LowRef = reader.GetAttribute("value");
                        break;
                    case "orderID":
                        break;
                    case "result":
                        result.Value = reader.GetAttribute("value");
                        break;
                    case "resulted":
                        if (reader.HasAttributes)
                        {
                            rpt.Timestamp = reader.GetAttribute("value");
                        }
                        break;
                    case "specimen":
                        rpt.Specimen.Name = reader.GetAttribute("name");
                        break;
                    case "status":
                        // place to put this?
                        break;
                    case "test":
                        result.Test.Name = reader.GetAttribute("value");
                        break;
                    case "type":
                        // place to put this??
                        break;
                    case "units":
                        result.Test.Units = reader.GetAttribute("value");
                        break;
                    case "vuid":
                        // TBD - where to put this?
                        break;
                }
            }
            return result;
        }
Пример #11
0
        internal IList<LabResult> toLabReportsVPR(string xml, ref ChemHemReport rpt)
        {
            IList<LabResult> rpts = new List<LabResult>();
            int numRecs = 0;

            using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
            {
                while (reader.Read())
                {
                    if (numRecs > 0)
                    {
                        while (!reader.EOF && rpts.Count < numRecs)
                        {
                            rpts.Add(readLab(reader, ref rpt));
                        }
                    }

                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if (String.Equals(reader.Name, "labs", StringComparison.CurrentCultureIgnoreCase))
                            {
                                if (reader.AttributeCount > 0)
                                {
                                    string count = reader.GetAttribute("total");
                                    if (!Int32.TryParse(reader.Value, out numRecs))
                                    {
                                        throw new XmlException("Unexpected format - could not determine number of results\r\n" + xml);
                                    }
                                }
                            }

                            break;
                        case XmlNodeType.EndElement:
                            if (String.Equals(reader.Name, "labs", StringComparison.CurrentCultureIgnoreCase))
                            {
                                continue;
                            }
                            if (String.Equals(reader.Name, "results", StringComparison.CurrentCultureIgnoreCase))
                            {
                                return rpts;
                            }
                            break;
                        //case XmlNodeType.Comment:
                        //    break;
                        //case XmlNodeType.Document:
                        //    break;
                        //case XmlNodeType.Text:
                        //    break;
                        default:
                            break;
                    }
                }
            }

            return rpts;
        }
Пример #12
0
        internal ChemHemReport[] toChemHemReports(string response)
        {
            if (response == "")
            {
                return null;
            }
            DictionaryHashList lst = new DictionaryHashList();
            string[] lines = StringUtils.split(response, StringUtils.CRLF);
            lines = StringUtils.trimArray(lines);

            ChemHemReport rpt = null;
            LabResult rslt = null;
            string ts = "";
            string facilityTag = "";
            string facilityName = "";
            for (int i = 0; i < lines.Length; i++)
            {
                string[] flds = StringUtils.split(lines[i], StringUtils.CARET);
                if (!StringUtils.isNumeric(flds[0]))
                {
                    throw new DataMisalignedException("Invalid fldnum: " + flds[0] + " in lines[" + i + "]");
                }
                int fldnum = Convert.ToInt32(flds[0]);
                switch (fldnum)
                {
                    case 1:
                        string[] parts = StringUtils.split(flds[1], StringUtils.SEMICOLON);
                        if (parts.Length == 2)
                        {
                            facilityTag = parts[1];
                            facilityName = parts[0];
                        }
                        else if (flds[1] != "")
                        {
                            facilityTag = cxn.DataSource.SiteId.Id;
                            facilityName = flds[1];
                        }
                        else
                        {
                            facilityTag = cxn.DataSource.SiteId.Id;
                            facilityName = cxn.DataSource.SiteId.Name;
                        }
                        break;
                    case 2:
                        if (rpt != null)
                        {
                            if (StringUtils.isEmpty(rslt.Test.RefRange))
                            {
                                if (!StringUtils.isEmpty(rslt.Test.LowRef) &&
                                    !StringUtils.isEmpty(rslt.Test.HiRef))
                                {
                                    rslt.Test.RefRange = rslt.Test.LowRef + " - " + rslt.Test.HiRef;
                                }
                            }
                            rpt.AddResult(rslt);
                        }
                        rslt = new LabResult();
                        rslt.Test = new LabTest();
                        ts = VistaTimestamp.toUtcFromRdv(flds[1]);
                        if (lst[ts] == null)
                        {
                            rpt = new ChemHemReport();
                            rpt.Facility = new SiteId(facilityTag, facilityName);
                            rpt.Timestamp = ts;
                            lst.Add(ts, rpt);
                        }
                        break;
                    case 3:
                        if (flds.Length == 2)
                        {
                            rslt.Test.Name = flds[1];
                        }
                        break;
                    case 4:
                        if (flds.Length == 2)
                        {
                            if (null != rslt)
                                rslt.SpecimenType = flds[1];
                        }
                        break;
                    case 5:
                        if (flds.Length == 2)
                        {
                            rslt.Value = flds[1];
                        }
                        break;
                    case 6:
                        if (flds.Length == 2)
                        {
                            rslt.BoundaryStatus = flds[1];
                        }
                        break;
                    case 7:
                        if (flds.Length == 2)
                        {
                            rslt.Test.Units = flds[1];
                        }
                        break;
                    case 8:
                        if (flds.Length == 2)
                        {
                            rslt.Test.LowRef = flds[1];
                        }
                        break;
                    case 9:
                        if (flds.Length == 2)
                        {
                            rslt.Test.HiRef = flds[1];
                        }
                        break;
                    case 10:
                        if (flds.Length == 2)
                        {
                            rslt.Comment += flds[1] + '\n';
                        }
                        break;
                }
            }

            if (rpt != null)
            {
                if (StringUtils.isEmpty(rslt.Test.RefRange))
                {
                    if (!StringUtils.isEmpty(rslt.Test.LowRef) &&
                        !StringUtils.isEmpty(rslt.Test.HiRef))
                    {
                        rslt.Test.RefRange = rslt.Test.LowRef + " - " + rslt.Test.HiRef;
                    }
                }
                rpt.AddResult(rslt);
            }

            ChemHemReport[] result = new ChemHemReport[lst.Count];
            for (int i = 0; i < lst.Count; i++)
            {
                DictionaryEntry de = lst[i];
                result[i] = (ChemHemReport)de.Value;
            }
            return result;
        }
Пример #13
0
        internal ChemHemReport toChemHemReport(string response, ref string nextDate)
        {
            if (String.IsNullOrEmpty(response))
            {
                return null;
            }

            string[] lines = StringUtils.split(response, StringUtils.CRLF);
            lines = StringUtils.trimArray(lines);
            string[] flds = StringUtils.split(lines[0], StringUtils.CARET);
            nextDate = flds[2];
            if (flds[1] != "CH")
            {
                return null;
            }
            if (lines.Length == 1)
            {
                return null;
            }
            int ntests = Convert.ToInt16(flds[0]);
            ChemHemReport rpt = new ChemHemReport();
            rpt.Id = flds[2] + '^' + flds[5];
            rpt.Timestamp = flds[2];
            rpt.Specimen = new LabSpecimen();
            rpt.Specimen.CollectionDate = VistaTimestamp.toUtcString(flds[2]);
            rpt.Specimen.Name = flds[4];
            rpt.Specimen.AccessionNumber = flds[5];
            rpt.Author = new Author();
            rpt.Author.Name = flds[6];

            int lineIdx = 1;
            for (lineIdx = 1; lineIdx <= ntests; lineIdx++)
            {
                LabResult lr = new LabResult();
                flds = StringUtils.split(lines[lineIdx], StringUtils.CARET);
                if (flds.Length < 6)
                {
                    continue;
                }
                lr.Test = new LabTest();

                lr.Test.Id = flds[0];
                lr.Test.Name = flds[1];
                lr.Value = flds[2].Trim();
                lr.BoundaryStatus = flds[3];
                lr.Test.Units = flds[4].Trim();
                lr.Test.RefRange = flds[5];

                // MHV patch - probably no one needs this
                lr.LabSiteId = cxn.DataSource.SiteId.Id;

                rpt.AddResult(lr);
            }

            rpt.Comment = "";
            while (lineIdx < lines.Length)
            {
                rpt.Comment += lines[lineIdx++].TrimStart() + "\r\n";
            }

            return rpt;
        }
Пример #14
0
 public IList<ChemHemReport> getChemHemReportsVPR(string fromDate, string toDate)
 {
     VistaClinicalDao clinicalDao = new VistaClinicalDao(this.cxn);
     string results = clinicalDao.getNhinData("lab");
     ChemHemReport rpt = new ChemHemReport();
     (toLabReportsVPR(results, ref rpt)).CopyTo(rpt.Results, 0);
     return new List<ChemHemReport>() { rpt };
 }
Пример #15
0
        internal ChemHemReport buildChemHemReport(IDataReader reader)
        {
            string patientIcn          = DbReaderUtil.getValue(reader, reader.GetOrdinal("PatientICN"));
            string testName            = DbReaderUtil.getValue(reader, reader.GetOrdinal("LabChemTestName"));    // LabResult.LabTest.ShortName
            string resultValue         = DbReaderUtil.getValue(reader, reader.GetOrdinal("LabChemResultValue")); // LabResult.Value
            string refHigh             = DbReaderUtil.getValue(reader, reader.GetOrdinal("RefHigh"));            // LabResult.LabTest.hiRef
            string refLow              = DbReaderUtil.getValue(reader, reader.GetOrdinal("RefLow"));             // LabResult.LabTest.lowRef
            string abnormal            = DbReaderUtil.getValue(reader, reader.GetOrdinal("Abnormal"));           // LabResult.BoundaryStatus
            string loinc               = DbReaderUtil.getValue(reader, reader.GetOrdinal("LOINC"));              // LabResult.LabTest.Loinc
            string component           = DbReaderUtil.getValue(reader, reader.GetOrdinal("Component"));          // LabResult.LabTest.Name
            string labTestType         = DbReaderUtil.getValue(reader, reader.GetOrdinal("LabTestType"));        //LabResult.LabTest.Category
            string labChemTestSid      = DbReaderUtil.getInt32Value(reader, reader.GetOrdinal("LabChemTestSID"));
            string labChemTestIen      = DbReaderUtil.getValue(reader, reader.GetOrdinal("LabChemTestIEN"));
            string labChemIen          = DbReaderUtil.getValue(reader, reader.GetOrdinal("LabChemIEN")); // LabTest.Id
            string labChemSid          = DbReaderUtil.getInt64Value(reader, reader.GetOrdinal("LabChemSID"));
            string siteCode            = DbReaderUtil.getInt16Value(reader, reader.GetOrdinal("Sta3n"));
            string labChemCompleteDate = DbReaderUtil.getDateValue(reader, reader.GetOrdinal("LabChemCompleteDateTime"));

            SiteId facility = new SiteId()
            {
                Id = siteCode
            };

            LabTest labTest = new LabTest()
            {
                Id        = labChemTestIen,
                Name      = testName,
                ShortName = labTestType,
                DataId    = labChemTestSid,
                HiRef     = refHigh,
                LowRef    = refLow,
                Loinc     = loinc
            };

            LabResult labResult = new LabResult()
            {
                Value          = resultValue,
                BoundaryStatus = abnormal,
                Test           = labTest
            };

            LabResult[] labResults = new LabResult[1];
            labResults[0] = labResult;

            LabSpecimen labSpecimen = new LabSpecimen()
            {
                Id             = labChemIen,
                Name           = DbReaderUtil.getValue(reader, reader.GetOrdinal("Specimen")),
                CollectionDate = labChemCompleteDate,
                Site           = siteCode
            };

            ChemHemReport report = new ChemHemReport()
            {
                Id        = labChemSid,
                Specimen  = labSpecimen,
                Facility  = facility,
                Results   = labResults,
                Timestamp = labChemCompleteDate
            };

            return(report);
        }
Пример #16
0
        // it appears we're missing local IEN that maps to LabReport.Id
        LabResult readLab(XmlReader reader, ref ChemHemReport rpt)
        {
            LabResult result = new LabResult();

            result.Test = new LabTest();

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.EndElement && String.Equals(reader.Name, "lab", StringComparison.CurrentCultureIgnoreCase))
                {
                    break;
                }
                switch (reader.Name)
                {
                case "collected":
                    if (reader.HasAttributes)
                    {
                        rpt.Specimen.CollectionDate = reader.GetAttribute("value");
                    }
                    break;

                case "comment":
                    result.Comment = reader.GetAttribute("value");
                    break;

                case "facility":
                    if (reader.HasAttributes)
                    {
                        rpt.Facility = new SiteId(reader.GetAttribute("code"), reader.GetAttribute("name"));
                    }
                    break;

                case "groupName":
                    if (reader.HasAttributes)
                    {
                        rpt.Specimen.AccessionNumber = reader.GetAttribute("value");
                    }
                    break;

                case "high":
                    result.Test.HiRef = reader.GetAttribute("value");
                    break;

                case "id":
                    if (reader.HasAttributes)
                    {
                        rpt.Id = reader.GetAttribute("value");     // not the same as old ChemHemRpts ID!!!
                    }
                    break;

                case "interpretation":
                    break;

                case "labOrderID":
                    break;

                case "localName":
                    result.Test.ShortName = reader.GetAttribute("value");
                    break;

                case "loinc":
                    result.Test.Loinc = reader.GetAttribute("value");
                    break;

                case "low":
                    result.Test.LowRef = reader.GetAttribute("value");
                    break;

                case "orderID":
                    break;

                case "result":
                    result.Value = reader.GetAttribute("value");
                    break;

                case "resulted":
                    if (reader.HasAttributes)
                    {
                        rpt.Timestamp = reader.GetAttribute("value");
                    }
                    break;

                case "specimen":
                    rpt.Specimen.Name = reader.GetAttribute("name");
                    break;

                case "status":
                    // place to put this?
                    break;

                case "test":
                    result.Test.Name = reader.GetAttribute("value");
                    break;

                case "type":
                    // place to put this??
                    break;

                case "units":
                    result.Test.Units = reader.GetAttribute("value");
                    break;

                case "vuid":
                    // TBD - where to put this?
                    break;
                }
            }
            return(result);
        }
Пример #17
0
        internal ChemHemReport[] toChemHemReports(string response)
        {
            if (response == "")
            {
                return(null);
            }
            DictionaryHashList lst = new DictionaryHashList();

            string[] lines = StringUtils.split(response, StringUtils.CRLF);
            lines = StringUtils.trimArray(lines);

            ChemHemReport rpt          = null;
            LabResult     rslt         = null;
            string        ts           = "";
            string        facilityTag  = "";
            string        facilityName = "";

            for (int i = 0; i < lines.Length; i++)
            {
                string[] flds = StringUtils.split(lines[i], StringUtils.CARET);
                if (!StringUtils.isNumeric(flds[0]))
                {
                    throw new DataMisalignedException("Invalid fldnum: " + flds[0] + " in lines[" + i + "]");
                }
                int fldnum = Convert.ToInt32(flds[0]);
                switch (fldnum)
                {
                case 1:
                    string[] parts = StringUtils.split(flds[1], StringUtils.SEMICOLON);
                    if (parts.Length == 2)
                    {
                        facilityTag  = parts[1];
                        facilityName = parts[0];
                    }
                    else if (flds[1] != "")
                    {
                        facilityTag  = cxn.DataSource.SiteId.Id;
                        facilityName = flds[1];
                    }
                    else
                    {
                        facilityTag  = cxn.DataSource.SiteId.Id;
                        facilityName = cxn.DataSource.SiteId.Name;
                    }
                    break;

                case 2:
                    if (rpt != null)
                    {
                        if (StringUtils.isEmpty(rslt.Test.RefRange))
                        {
                            if (!StringUtils.isEmpty(rslt.Test.LowRef) &&
                                !StringUtils.isEmpty(rslt.Test.HiRef))
                            {
                                rslt.Test.RefRange = rslt.Test.LowRef + " - " + rslt.Test.HiRef;
                            }
                        }
                        rpt.AddResult(rslt);
                    }
                    rslt      = new LabResult();
                    rslt.Test = new LabTest();
                    ts        = VistaTimestamp.toUtcFromRdv(flds[1]);
                    if (lst[ts] == null)
                    {
                        rpt           = new ChemHemReport();
                        rpt.Facility  = new SiteId(facilityTag, facilityName);
                        rpt.Timestamp = ts;
                        lst.Add(ts, rpt);
                    }
                    break;

                case 3:
                    if (flds.Length == 2)
                    {
                        rslt.Test.Name = flds[1];
                    }
                    break;

                case 4:
                    if (flds.Length == 2)
                    {
                        if (null != rslt)
                        {
                            rslt.SpecimenType = flds[1];
                        }
                    }
                    break;

                case 5:
                    if (flds.Length == 2)
                    {
                        rslt.Value = flds[1];
                    }
                    break;

                case 6:
                    if (flds.Length == 2)
                    {
                        rslt.BoundaryStatus = flds[1];
                    }
                    break;

                case 7:
                    if (flds.Length == 2)
                    {
                        rslt.Test.Units = flds[1];
                    }
                    break;

                case 8:
                    if (flds.Length == 2)
                    {
                        rslt.Test.LowRef = flds[1];
                    }
                    break;

                case 9:
                    if (flds.Length == 2)
                    {
                        rslt.Test.HiRef = flds[1];
                    }
                    break;

                case 10:
                    if (flds.Length == 2)
                    {
                        rslt.Comment += flds[1] + '\n';
                    }
                    break;
                }
            }

            if (rpt != null)
            {
                if (StringUtils.isEmpty(rslt.Test.RefRange))
                {
                    if (!StringUtils.isEmpty(rslt.Test.LowRef) &&
                        !StringUtils.isEmpty(rslt.Test.HiRef))
                    {
                        rslt.Test.RefRange = rslt.Test.LowRef + " - " + rslt.Test.HiRef;
                    }
                }
                rpt.AddResult(rslt);
            }

            ChemHemReport[] result = new ChemHemReport[lst.Count];
            for (int i = 0; i < lst.Count; i++)
            {
                DictionaryEntry de = lst[i];
                result[i] = (ChemHemReport)de.Value;
            }
            return(result);
        }
Пример #18
0
        internal ChemHemReport toChemHemReport(string response, ref string nextDate)
        {
            if (String.IsNullOrEmpty(response))
            {
                return(null);
            }

            string[] lines = StringUtils.split(response, StringUtils.CRLF);
            lines = StringUtils.trimArray(lines);
            string[] flds = StringUtils.split(lines[0], StringUtils.CARET);
            nextDate = flds[2];
            if (flds[1] != "CH")
            {
                return(null);
            }
            if (lines.Length == 1)
            {
                return(null);
            }
            int           ntests = Convert.ToInt16(flds[0]);
            ChemHemReport rpt    = new ChemHemReport();

            rpt.Id        = flds[2] + '^' + flds[5];
            rpt.Timestamp = flds[2];
            rpt.Specimen  = new LabSpecimen();
            rpt.Specimen.CollectionDate  = VistaTimestamp.toUtcString(flds[2]);
            rpt.Specimen.Name            = flds[4];
            rpt.Specimen.AccessionNumber = flds[5];
            rpt.Author      = new Author();
            rpt.Author.Name = flds[6];

            int lineIdx = 1;

            for (lineIdx = 1; lineIdx <= ntests; lineIdx++)
            {
                LabResult lr = new LabResult();
                flds = StringUtils.split(lines[lineIdx], StringUtils.CARET);
                if (flds.Length < 6)
                {
                    continue;
                }
                lr.Test = new LabTest();

                lr.Test.Id        = flds[0];
                lr.Test.Name      = flds[1];
                lr.Value          = flds[2].Trim();
                lr.BoundaryStatus = flds[3];
                lr.Test.Units     = flds[4].Trim();
                lr.Test.RefRange  = flds[5];

                // MHV patch - probably no one needs this
                lr.LabSiteId = cxn.DataSource.SiteId.Id;

                rpt.AddResult(lr);
            }

            rpt.Comment = "";
            while (lineIdx < lines.Length)
            {
                rpt.Comment += lines[lineIdx++].TrimStart() + "\r\n";
            }

            return(rpt);
        }
Пример #19
0
        /*
         * In order to get the correct results with the correct reports using the DDR calls and RPCs
         * available, we are going to use the user specified fromDate but use today as the toDate (like
         * CPRS does) and retrieve all the specimens with in that time period. Then, we will find the
         * reports, match them up with their specimens and lastly filter those results using our original
         * date range
         */
        public ChemHemReport[] getChemHemReports(string dfn, string fromDate, string toDate)
        {
            if (!String.IsNullOrEmpty(toDate) && toDate.IndexOf(".") == -1)
            {
                toDate += ".235959";
            }

            IndexedHashtable specimens = getChemHemSpecimens(dfn, fromDate, toDate, "3");

            if (specimens == null || specimens.Count == 0)
            {
                return(null);
            }

            ArrayList lst = new ArrayList();
            //string nextDate = VistaTimestamp.fromUtcString(today);
            string nextDate = VistaTimestamp.fromUtcString(toDate);

            // Due to comment above, we want to loop through "ORWLRR INTERIMG" RPC until we
            // get as many reports as the DDR call above told us we would
            // TBD - this while statement screams infinite loop (i.e. what happens if we don't get all the
            // reports the DDR call above said we would?) Should we put an arbitrarily large stop in here?
            // e.g. if count > 1,000,000 then throw an exception that we didn't get what VistA said we should?
            int i = 0;

            while (lst.Count < specimens.Count)
            {
                LabSpecimen specimen = (LabSpecimen)specimens.GetValue(i);
                // ORWLRR INTERIMG rpc and function below updates nextDate for subsequent calls so LEAVE REF ALONE
                string        nextDateBefore = nextDate;
                ChemHemReport rpt            = getChemHemReport(dfn, ref nextDate);
                if (rpt != null)
                {
                    if ((rpt.Specimen != null) && (rpt.Specimen.AccessionNumber == specimen.AccessionNumber))
                    {
                        i++;
                        rpt.Id        = specimen.Id;
                        rpt.Facility  = specimen.Facility;
                        rpt.Specimen  = specimen;
                        rpt.Timestamp = specimen.ReportDate;
                        lst.Add(rpt);
                    }
                }
                // if the next date variable was not changed below, it means we are no longer looping through
                // the reports so we should go ahead and break out of this loop - should take care of
                // infinite loop concerns
                if (nextDate.Equals(nextDateBefore))
                {
                    break;
                }
            }
            // At last, filter the reports based on their timestamps
            ArrayList filteredList = new ArrayList();
            double    startDate    = Convert.ToDouble(fromDate);
            double    stopDate     = Convert.ToDouble(toDate);

            ChemHemReport[] rpts = (ChemHemReport[])lst.ToArray(typeof(ChemHemReport));
            foreach (ChemHemReport report in rpts)
            {
                // if the report doesn't have a timestamp, we will just add it to our list
                if (String.IsNullOrEmpty(report.Timestamp))
                {
                    filteredList.Add(report);
                    continue;
                }
                double reportTimeStamp = Convert.ToDouble(report.Timestamp);
                if (startDate <= reportTimeStamp && reportTimeStamp <= stopDate)
                {
                    filteredList.Add(report);
                }
            }
            return((ChemHemReport[])filteredList.ToArray(typeof(ChemHemReport)));
        }