Пример #1
0
        /// <summary>
        /// GetOrders - get all the segments that make up an order
        ///   {
        ///     ORC           - Required (Order)
        ///     [
        ///      OBR          - Required
        ///      [{NTE}]      - Optional, if present can repeat
        ///      [{DG1}]      - Optional, if present can repeat
        ///      [{
        ///        OBX        - Required
        ///        [{NTE}]    - Optional, if present can repeat
        ///      }]
        ///     ]
        ///     [{CTI}]       - Optional, if present can repeat
        ///     [BLG]         - Optional
        ///  }
        ///
        /// </summary>
        /// <param name="hl7Msg">HL7 ORM message</param>
        /// <returns>List<HL7Orders> object</returns>
        public List <HL7Order> GetOrders(HL7Encoding _encode, List <string> hl7Msg)
        {
            HL7Order        order     = null;
            HL7Details      od        = null;
            HL7Observation  obs       = null;
            List <HL7Order> hl7Orders = new List <HL7Order>();
            BuildOrders     bldOrders = new BuildOrders();
            BuildNTE        bldNTE    = new BuildNTE();

            ErrorMsg errorMsg = new ErrorMsg();

            List <ErrorMsg> lErrorMsg = new List <ErrorMsg>();
            string          line      = string.Empty;

            bool bOrder        = false;      // order
            bool bOrderDetails = false;      // order details
            bool bObservation  = false;      // observation

            try
            {
                // search for the ORC segment
                for (int nIdx = 0; nIdx < hl7Msg.Count; nIdx++)
                {
                    line = hl7Msg[nIdx].ToString();

                    string sTmp = GetField(_encode, line, 0);
                    if (string.IsNullOrEmpty(sTmp))
                    {
                        lErrorMsg.Add(new ErrorMsg(1, line));
                    }
                    else
                    {
                        // Enum.TryParse<Segments>(sTmp, out sResult);
                        switch (((Segments)Enum.Parse(typeof(Segments), sTmp)))
                        {
                        case Segments.ORC:                                   // start HL7 order
                            if (order != null)
                            {
                                if (bOrderDetails)
                                {
                                    if (bObservation)
                                    {
                                        if (obs != null)
                                        {
                                            od.Observations.Add(obs);
                                            obs = null;
                                        }
                                        bObservation = false;
                                    }
                                    if (od != null)
                                    {
                                        order.HL7Details.Add(od);
                                        od = null;
                                    }
                                    bOrderDetails = false;
                                }
                                // we are working on a current order and a new order was found
                                // we need to add the existing order to the array
                                // create new order and start again
                                hl7Orders.Add(order);
                                order = null;
                            }

                            // lets start again
                            order = new HL7Order
                            {
                                ORCSegment = new BuildORC().GetORC(_encode, line)                                           // build ORC object
                            };

                            bOrder        = true;                              // working on new order
                            bOrderDetails = false;
                            bObservation  = false;
                            break;

                        case Segments.OBR:                                      // order details
                            if (od != null)
                            {
                                // already building Order Detail object
                                // new message found add existing order detial and start again
                                order.HL7Details.Add(od);
                                od = null;
                            }
                            od = new HL7Details("ORM")
                            {
                                OBRSegment = new BuildOBR().GetOBR(_encode, line)
                            };

                            bOrderDetails = true;
                            bObservation  = false;
                            break;

                        case Segments.DG1:                                      // order details
                            od.DG1Segments.Add(new BuildDG1().GetDG1(_encode, line));
                            bObservation = false;
                            break;

                        // Observations consist of OBX, NTE
                        case Segments.OBX:                                      // Observations
                            if (obs != null)
                            {
                                od.Observations.Add(obs);
                                obs = null;
                            }
                            obs = new HL7Observation("ORM")
                            {
                                OBXSegment = new BuildOBX().GetOBX(_encode, line, "ORM")
                            };
                            bObservation = true;
                            break;

                        case Segments.NTE:
                            // note the order of the if statements matter.
                            // Observations than orderDetails than order
                            if (bObservation)                                        // NTE for Observations
                            {
                                obs.NTESegments.Add(bldNTE.GetNTE(_encode, line));   // build NTE for OBR group
                            }
                            else if (bOrderDetails)                                  // NTE for Order details
                            {
                                od.NTESegments.Add(bldNTE.GetNTE(_encode, line));    // build NTE for OBR group
                            }
                            else if (bOrder)                                         // NTE for Order
                            {
                                order.NTESegments.Add(bldNTE.GetNTE(_encode, line)); // build NTE for ORC group
                            }
                            break;

                        case Segments.BLG:
                            order.BLGSegment = new BuildBLG().GetBLG(_encode, line);                                          // build BLG
                            break;

                        case Segments.CTI:
                            order.CTISegments.Add(new BuildCTI().GetCTI(_encode, line));                                      // build CT1
                            break;

                        default:
                            // nIdx = hl7Msg.Count; // we are done, leave
                            break;
                        }
                    }
                }

                // we need to finish what we stated
                if (bOrder)
                {
                    if (order != null)
                    {
                        if (bOrderDetails)
                        {
                            if (bObservation)
                            {
                                if (obs != null)
                                {
                                    od.Observations.Add(obs);
                                    obs = null;
                                }
                                bObservation = false;
                            }
                            if (od != null)
                            {
                                order.HL7Details.Add(od);
                                od = null;
                            }
                            bOrderDetails = false;
                        }
                        // we are working on a current order and a new order was found
                        // we need to add the existing order to the array
                        // create new order and start again
                        hl7Orders.Add(order);
                        order = null;
                    }
                }
            }
            catch (Exception ex)
            {
                string sErr = string.Format("BuildOrders:GetOrders: Exception {0}", ex);
                errorMsg.Message = sErr;
                Console.WriteLine(sErr);
            }
            return(hl7Orders);
        }
Пример #2
0
        /// <summary>
        /// GetResults - get the HL7Result object based on the hl7 message
        /// </summary>
        /// <param name="_encode"></param>
        /// <param name="hl7Msg"></param>
        /// <returns></returns>
        public List <HL7Results> GetResults(HL7Encoding _encode, List <string> hl7Msg)
        {
            HL7Results        result     = null;
            HL7Details        od         = null;
            HL7Observation    obs        = null;
            List <HL7Results> hl7Results = new List <HL7Results>();
            BuildResults      bldResult  = new BuildResults();
            BuildNTE          bldNTE     = new BuildNTE();

            var errorMsg = new ErrorMsg();

            List <ErrorMsg> lErrorMsg = new List <ErrorMsg>();
            string          line      = string.Empty;

            bool bResult        = false;              // result
            bool bResultDetails = false;              // result details
            bool bObservation   = false;              // observation

            try
            {
                // search for the ORC segment
                for (int nIdx = 0; nIdx < hl7Msg.Count; nIdx++)
                {
                    line = hl7Msg[nIdx].ToString();

                    string sTmp = GetField(_encode, line, 0);
                    if (string.IsNullOrEmpty(sTmp))
                    {
                        lErrorMsg.Add(new ErrorMsg(1, line));
                    }
                    else
                    {
                        // Enum.TryParse<Segments>(sTmp, out sResult);
                        switch (((Segments)Enum.Parse(typeof(Segments), sTmp)))
                        {
                        case Segments.ORC:                                   // start HL7 order
                            if (result != null)
                            {
                                if (bResultDetails)
                                {
                                    if (bObservation)
                                    {
                                        if (obs != null)
                                        {
                                            od.Observations.Add(obs);
                                            obs = null;
                                        }
                                        bObservation = false;
                                    }
                                    if (od != null)
                                    {
                                        result.HL7Details.Add(od);
                                        od = null;
                                    }
                                    bResultDetails = false;
                                }
                                // we are working on a current order and a new order was found
                                // we need to add the existing order to the array
                                // create new order and start again
                                hl7Results.Add(result);
                                result = null;
                            }

                            // lets start again
                            result = new HL7Results
                            {
                                ORCSegment = new BuildORC().GetORC(_encode, line)                                           // build ORC object
                            };

                            bResult        = true;                              // working on new order
                            bResultDetails = false;
                            bObservation   = false;
                            break;

                        case Segments.OBR:                                      // order details
                            if (od != null)
                            {
                                // already building Order Detail object
                                // new message found add existing order detial and start again
                                result.HL7Details.Add(od);
                                od = null;
                            }
                            od = new HL7Details("ORU")
                            {
                                OBRSegment = new BuildOBR().GetOBR(_encode, line)
                            };

                            bResultDetails = true;
                            bObservation   = false;
                            break;

                        // Observations consist of OBX, NTE
                        case Segments.OBX:                                      // Observations
                            if (obs != null)
                            {
                                od.Observations.Add(obs);
                                obs = null;
                            }
                            obs = new HL7Observation("ORU")
                            {
                                OBXSegment = new BuildOBX().GetOBX(_encode, line, "ORU")
                            };
                            bObservation = true;
                            // if ("ED".Equals(obs.OBXSegment.ValueType))
                            // {
                            //  // this is the Embedded PDF segment so lets end this
                            //  bObservation = true;
                            // }
                            break;

                        case Segments.NTE:
                            // Note the order matters keep this order
                            //
                            if (bObservation)                                         // NTE for Observations
                            {
                                obs.NTESegments.Add(bldNTE.GetNTE(_encode, line));    // build NTE for OBR group
                            }
                            else if (bResultDetails)                                  // NTE for Order details
                            {
                                od.NTESegments.Add(bldNTE.GetNTE(_encode, line));     // build NTE for OBR group
                            }
                            else if (bResult)                                         // NTE for Order
                            {
                                result.NTESegments.Add(bldNTE.GetNTE(_encode, line)); // build NTE for ORC group
                            }
                            break;

                        default:
                            // nIdx = hl7Msg.Count; // we are done, leave
                            break;
                        }
                    }
                }

                // we need to finish what we stated
                if (bResult)
                {
                    if (result != null)
                    {
                        if (bResultDetails)
                        {
                            if (bObservation)
                            {
                                if (obs != null)
                                {
                                    od.Observations.Add(obs);
                                    obs = null;
                                }
                                bObservation = false;
                            }
                            if (od != null)
                            {
                                result.HL7Details.Add(od);
                                od = null;
                            }
                            bResultDetails = false;
                        }
                        // we are working on a current order and a new order was found
                        // we need to add the existing order to the array
                        // create new order and start again
                        hl7Results.Add(result);
                        result = null;
                    }
                }
            }
            catch (Exception ex)
            {
                string sErr = string.Format("BuildResults:GetResults: Exception {0}", ex);
                errorMsg.Message = sErr;
                Console.WriteLine(sErr);
            }
            return(hl7Results);
        }