示例#1
0
        ///<summary>Gets the patient info from the MedLab.OriginalPIDSegments.  Returns null if there is an error processing the PID segments.</summary>
        private List <string[]> GetPatInfoFromPidSegments()
        {
            List <string[]> listPats  = new List <string[]>();
            HL7Def          hl7DefCur = HL7Defs.GetOneDeepEnabled(true);

            if (hl7DefCur == null)
            {
                MsgBox.Show(this, "There must be an enabled MedLab HL7 interface in order to parse the message details.");
                return(null);
            }
            HL7DefMessage hl7defmsg = null;

            for (int i = 0; i < hl7DefCur.hl7DefMessages.Count; i++)
            {
                //for now there are only incoming ORU messages supported, so there should only be one defined message type and it should be inbound
                if (hl7DefCur.hl7DefMessages[i].MessageType == MessageTypeHL7.ORU && hl7DefCur.hl7DefMessages[i].InOrOut == InOutHL7.Incoming)
                {
                    hl7defmsg = hl7DefCur.hl7DefMessages[i];
                    break;
                }
            }
            if (hl7defmsg == null)
            {
                MsgBox.Show(this, "There must be a message definition for an inbound ORU message in order to parse this message.");
                return(null);
            }
            //for MedLab interfaces, we limit the ability to rearrange the message structure, so the PID segment is always in position 1
            if (hl7defmsg.hl7DefSegments.Count < 2)
            {
                MsgBox.Show(this, "The message definition for an inbound ORU message does not have the correct number of segments.");
                return(null);
            }
            HL7DefSegment pidSegDef = hl7defmsg.hl7DefSegments[1];

            if (pidSegDef.SegmentName != SegmentNameHL7.PID)
            {
                MsgBox.Show(this, "The message definition for an inbound ORU message does not have the PID segment as the second segment.");
                return(null);
            }
            for (int i = 0; i < ListMedLabs.Count; i++)
            {
                string[]        fields     = ListMedLabs[i].OriginalPIDSegment.Split(new string[] { "|" }, StringSplitOptions.None);
                List <FieldHL7> listFields = new List <FieldHL7>();
                for (int j = 0; j < fields.Length; j++)
                {
                    listFields.Add(new FieldHL7(fields[j]));
                }
                string patName   = "";
                string birthdate = "";
                string gender    = "";
                string ssn       = "";
                for (int j = 0; j < pidSegDef.hl7DefFields.Count; j++)
                {
                    int itemOrder = pidSegDef.hl7DefFields[j].OrdinalPos;
                    if (itemOrder > listFields.Count - 1)
                    {
                        continue;
                    }
                    switch (pidSegDef.hl7DefFields[j].FieldName)
                    {
                    case "pat.nameLFM":
                        patName = listFields[itemOrder].GetComponentVal(1);
                        if (patName != "" && listFields[itemOrder].GetComponentVal(2) != "")
                        {
                            patName += " ";
                        }
                        patName += listFields[itemOrder].GetComponentVal(2);
                        if (patName != "" && listFields[itemOrder].GetComponentVal(0) != "")
                        {
                            patName += " ";
                        }
                        patName += listFields[itemOrder].GetComponentVal(0);
                        continue;

                    case "patBirthdateAge":
                        //LabCorp sends the birthdate and age in years, months, and days like yyyyMMdd^YYY^MM^DD
                        birthdate = FieldParser.DateTimeParse(listFields[itemOrder].GetComponentVal(0)).ToShortDateString();
                        continue;

                    case "pat.Gender":
                        gender = Lan.g("enumPatientGender", FieldParser.GenderParse(listFields[itemOrder].GetComponentVal(0)).ToString());
                        continue;

                    case "pat.SSN":
                        if (listFields[itemOrder].GetComponentVal(0).Length > 3)
                        {
                            ssn  = "***-**-";
                            ssn += listFields[itemOrder].GetComponentVal(0).Substring(listFields[itemOrder].GetComponentVal(0).Length - 4, 4);
                        }
                        continue;

                    default:
                        continue;
                    }
                }
                bool isDuplicate = false;
                for (int j = 0; j < listPats.Count; j++)
                {
                    if (listPats[j].Length < 4)                   //should never happen
                    {
                        continue;
                    }
                    if (listPats[j][0] == patName && listPats[j][1] == birthdate && listPats[j][2] == gender && listPats[j][3] == ssn)
                    {
                        isDuplicate = true;
                    }
                }
                if (!isDuplicate)
                {
                    listPats.Add(new string[] { patName, birthdate, gender, ssn });
                }
            }
            return(listPats);
        }