Example #1
0
		private void FillForm(){
			ProgramProperties.RefreshCache();
			PropertyList=ProgramProperties.GetForProgram(ProgramCur.ProgramNum);
			textProgName.Text=ProgramCur.ProgName;
			textProgDesc.Text=ProgramCur.ProgDesc;
			checkEnabled.Checked=ProgramCur.Enabled;
			if(GetProp("HideChartRxButtons")=="1") {
				checkHideButChartRx.Checked=true;
			}
			else {
				checkHideButChartRx.Checked=false;
			}
			if(GetProp("ProcRequireSignature")=="1") {
				checkProcRequireSignature.Checked=true;
			}
			else {
				checkProcRequireSignature.Checked=false;
			}
			if(GetProp("ProcNotesNoIncomplete")=="1") {
				checkProcNotesNoIncomplete.Checked=true;
			}
			else {
				checkProcNotesNoIncomplete.Checked=false;
			}
			SetModeRadioButtons(GetProp("eClinicalWorksMode"));
			SetModeVisibilities();
			textECWServer.Text=GetProp("eCWServer");//this property will not exist if using Oracle, eCW will never use Oracle
			if(HL7Defs.IsExistingHL7Enabled()) {
				HL7Def def=HL7Defs.GetOneDeepEnabled();
				textHL7Server.Text=def.HL7Server;
				textHL7ServiceName.Text=def.HL7ServiceName;
				textHL7FolderIn.Text=def.OutgoingFolder;//because these are the opposite of the way they are in the HL7Def
				textHL7FolderOut.Text=def.IncomingFolder;
				checkQuadAsToothNum.Checked=def.IsQuadAsToothNum;
			}
			else {
				textHL7Server.Text=GetProp("HL7Server");//this property will not exist if using Oracle, eCW will never use Oracle
				textHL7ServiceName.Text=GetProp("HL7ServiceName");//this property will not exist if using Oracle, eCW will never use Oracle
				textHL7FolderIn.Text=PrefC.GetString(PrefName.HL7FolderIn);
				textHL7FolderOut.Text=PrefC.GetString(PrefName.HL7FolderOut);
				//if a def is enabled, the value associated with the def will override this setting
				checkQuadAsToothNum.Checked=GetProp("IsQuadAsToothNum")=="1";//this property will not exist if using Oracle, eCW will never use Oracle
			}
			textODServer.Text=MiscData.GetODServer();
			comboDefaultUserGroup.Items.Clear();
			_listUserGroups=UserGroups.GetList();
			for(int i=0;i<_listUserGroups.Count;i++) {
				comboDefaultUserGroup.Items.Add(_listUserGroups[i].Description);
				if(GetProp("DefaultUserGroup")==_listUserGroups[i].UserGroupNum.ToString()) {
					comboDefaultUserGroup.SelectedIndex=i;
				}
			}
			checkShowImages.Checked=GetProp("ShowImagesModule")=="1";
			checkFeeSchedules.Checked=GetProp("FeeSchedulesSetManually")=="1";
			textMedPanelURL.Text=GetProp("MedicalPanelUrl");//this property will not exist if using Oracle, eCW will never use Oracle
			checkLBSessionId.Checked=GetProp("IsLBSessionIdExcluded")=="1";
		}
Example #2
0
        ///<summary>Returns null if no HL7 def is enabled or no ACK is defined in the enabled def.</summary>
        public static MessageHL7 GenerateACK(string controlId, bool isAck, string ackEvent)
        {
            MessageHL7 messageHL7 = new MessageHL7(MessageTypeHL7.ACK);

            messageHL7.ControlId = controlId;
            messageHL7.AckEvent  = ackEvent;
            HL7Def hl7Def = HL7Defs.GetOneDeepEnabled();

            if (hl7Def == null)
            {
                return(null);               //no def enabled, return null
            }
            //find an ACK message in the def
            HL7DefMessage hl7DefMessage = null;

            for (int i = 0; i < hl7Def.hl7DefMessages.Count; i++)
            {
                if (hl7Def.hl7DefMessages[i].MessageType == MessageTypeHL7.ACK && hl7Def.hl7DefMessages[i].InOrOut == InOutHL7.Outgoing)
                {
                    hl7DefMessage = hl7Def.hl7DefMessages[i];
                    break;
                }
            }
            if (hl7DefMessage == null)           //ACK message type is not defined so do nothing and return
            {
                return(null);
            }
            //go through each segment in the def
            for (int s = 0; s < hl7DefMessage.hl7DefSegments.Count; s++)
            {
                SegmentHL7 seg = new SegmentHL7(hl7DefMessage.hl7DefSegments[s].SegmentName);
                seg.SetField(0, hl7DefMessage.hl7DefSegments[s].SegmentName.ToString());
                for (int f = 0; f < hl7DefMessage.hl7DefSegments[s].hl7DefFields.Count; f++)
                {
                    string fieldName = hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].FieldName;
                    if (fieldName == "")                   //If fixed text instead of field name just add text to segment
                    {
                        seg.SetField(hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].OrdinalPos, hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].FixedText);
                    }
                    else
                    {
                        seg.SetField(hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].OrdinalPos, FieldConstructor.GenerateACK(hl7Def, fieldName, controlId, isAck, ackEvent));
                    }
                }
                messageHL7.Segments.Add(seg);
            }
            return(messageHL7);
        }
Example #3
0
        ///<summary>Only use this constructor when generating a message instead of parsing a message.</summary>
        internal MessageHL7(MessageTypeHL7 msgType)
        {
            Segments   = new List <SegmentHL7>();
            MsgType    = msgType;
            ControlId  = "";
            AckCode    = "";
            AckEvent   = "";
            Delimiters = new char[] { '^', '~', '\\', '&' };       //this is the default delimiters
            //if def is enabled, set delimiters to user defined values
            HL7Def enabledDef = HL7Defs.GetOneDeepEnabled();

            if (enabledDef != null)
            {
                Delimiters    = new char[4];
                Delimiters[0] = enabledDef.ComponentSeparator.ToCharArray()[0];           //the enabled def is forced to have a component separator that is a single character
                Delimiters[1] = enabledDef.RepetitionSeparator.ToCharArray()[0];          //the enabled def is forced to have a repetition separator that is a single character
                Delimiters[2] = enabledDef.EscapeCharacter.ToCharArray()[0];              //the enabled def is forced to have an escape character that is a single character
                Delimiters[3] = enabledDef.SubcomponentSeparator.ToCharArray()[0];        //the enabled def is forced to have a subcomponent separator that is a single character
            }
        }
Example #4
0
 private void FillForm()
 {
     ProgramProperties.RefreshCache();
     PropertyList         = ProgramProperties.GetListForProgram(ProgramCur.ProgramNum);
     textProgName.Text    = ProgramCur.ProgName;
     textProgDesc.Text    = ProgramCur.ProgDesc;
     checkEnabled.Checked = ProgramCur.Enabled;
     SetModeRadioButtons(GetProp("eClinicalWorksMode"));
     SetModeVisibilities();
     textECWServer.Text = GetProp("eCWServer");
     if (HL7Defs.IsExistingHL7Enabled())
     {
         HL7Def def = HL7Defs.GetOneDeepEnabled();
         textHL7Server.Text      = def.HL7Server;
         textHL7ServiceName.Text = def.HL7ServiceName;
         textHL7FolderIn.Text    = def.OutgoingFolder;           //because these are the opposite of the way they are in the HL7Def
         textHL7FolderOut.Text   = def.IncomingFolder;
     }
     else
     {
         textHL7Server.Text      = GetProp("HL7Server");
         textHL7ServiceName.Text = GetProp("HL7ServiceName");
         textHL7FolderIn.Text    = PrefC.GetString(PrefName.HL7FolderIn);
         textHL7FolderOut.Text   = PrefC.GetString(PrefName.HL7FolderOut);
     }
     textODServer.Text = MiscData.GetODServer();
     comboDefaultUserGroup.Items.Clear();
     for (int i = 0; i < UserGroups.List.Length; i++)
     {
         comboDefaultUserGroup.Items.Add(UserGroups.List[i].Description);
         if (GetProp("DefaultUserGroup") == UserGroups.List[i].UserGroupNum.ToString())
         {
             comboDefaultUserGroup.SelectedIndex = i;
         }
     }
     checkShowImages.Checked   = GetProp("ShowImagesModule") == "1";
     checkFeeSchedules.Checked = GetProp("FeeSchedulesSetManually") == "1";
     textMedPanelURL.Text      = GetProp("MedicalPanelUrl");
 }
Example #5
0
        public static void ProcessAck(MessageHL7 msg, bool isVerboseLogging)
        {
            IsVerboseLogging = isVerboseLogging;
            HL7Def def = HL7Defs.GetOneDeepEnabled();

            if (def == null)
            {
                throw new Exception("Could not process ACK.  No HL7 definition is enabled.");
            }
            HL7DefMessage hl7defmsg = null;

            for (int i = 0; i < def.hl7DefMessages.Count; i++)
            {
                if (def.hl7DefMessages[i].MessageType == MessageTypeHL7.ACK && def.hl7DefMessages[i].InOrOut == InOutHL7.Incoming)
                {
                    hl7defmsg = def.hl7DefMessages[i];
                    break;
                }
            }
            if (hl7defmsg == null)           //No incoming ACK defined, do nothing with it
            {
                throw new Exception("Could not process HL7 ACK message.  No definition for this type of message in the enabled HL7Def.");
            }
            for (int i = 0; i < hl7defmsg.hl7DefSegments.Count; i++)
            {
                try {
                    SegmentHL7 seg = msg.GetSegment(hl7defmsg.hl7DefSegments[i].SegmentName, !hl7defmsg.hl7DefSegments[i].IsOptional);
                    if (seg != null)                   //null if segment was not found but is optional
                    {
                        ProcessSeg(null, 0, hl7defmsg.hl7DefSegments[i], seg, msg);
                    }
                }
                catch (ApplicationException ex) {               //Required segment was missing, or other error.
                    throw new Exception("Could not process HL7 message.  " + ex);
                }
            }
        }
Example #6
0
        public MessageHL7(string msgtext)
        {
            AckCode         = "";
            ControlId       = "";
            AckEvent        = "";
            originalMsgText = msgtext;
            Segments        = new List <SegmentHL7>();
            string[] rows = msgtext.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            //We need to get the separator characters in order to create the field objects.
            //The separators are part of the MSH segment and we force users to leave them in position 1 for incoming messages.
            Delimiters = new char[] { '^', '~', '\\', '&' };       //this is the default, but we will get them from the MSH segment of the incoming message in case they are using something unique.
            //if def is enabled, set delimiters to user defined values
            HL7Def enabledDef = HL7Defs.GetOneDeepEnabled();

            if (enabledDef != null)
            {
                for (int i = 0; i < rows.Length; i++)
                {
                    //we're going to assume that the user has not inserted an escaped '|' before the second field of the message and just split by '|'s without
                    //checking for escaped '|'s.  Technically '\|' would be a literal pipe and should not indicate a new field, but we only want to retrieve the
                    //delimiters from MSH.1 and we require field 0 to be MSH and field 1 should be ^~\&.
                    string[] fields = rows[i].Split(new string[] { "|" }, StringSplitOptions.None);
                    if (fields.Length > 1 && fields[0] == "MSH" && fields[1].Length == 4)
                    {
                        //Encoding characters are in the following order:  component separator, repetition separator, escape character, subcomponent separator
                        Delimiters = fields[1].ToCharArray();                      //we force users to leave the delimiters in position 1 of the MSH segment
                        break;
                    }
                }
            }
            SegmentHL7 segment;

            for (int i = 0; i < rows.Length; i++)
            {
                segment = new SegmentHL7(rows[i], Delimiters);             //this creates the field objects.
                Segments.Add(segment);
                if (i == 0 && segment.Name == SegmentNameHL7.MSH)
                {
//js 7/3/12 Make this more intelligent because we also now need the suffix
                    string msgtype      = segment.GetFieldComponent(8, 0);            //We force the user to leave the 'messageType' field in this position, position 8 of the MSH segment
                    string evnttype     = segment.GetFieldComponent(8, 1);
                    string msgStructure = segment.GetFieldComponent(8, 2);
                    AckEvent = evnttype;                  //We will use this when constructing the acknowledgment to echo back to sender the same event type sent to us
                    //If message type or event type are not in this list, they will default to the not supported type and will not be processed
                    try {
                        MsgType = (MessageTypeHL7)Enum.Parse(typeof(MessageTypeHL7), msgtype, true);
                    }
                    catch (Exception ex) {
                        ex.DoNothing();
                        MsgType = MessageTypeHL7.NotDefined;
                    }
                    try {
                        EventType = (EventTypeHL7)Enum.Parse(typeof(EventTypeHL7), evnttype, true);
                    }
                    catch (Exception ex) {
                        ex.DoNothing();
                        EventType = EventTypeHL7.NotDefined;
                    }
                    try {
                        MsgStructure = (MessageStructureHL7)Enum.Parse(typeof(MessageStructureHL7), msgStructure, true);
                    }
                    catch (Exception ex) {
                        ex.DoNothing();
                        MsgStructure = MessageStructureHL7.NotDefined;
                    }
                }
            }
        }
Example #7
0
        //Open \\SERVERFILES\storage\OPEN DENTAL\Programmers Documents\Standards (X12, ADA, etc)\HL7\Version2.6\V26_CH02_Control_M4_JAN2007.doc
        //At the top of page 33, there are rules for the recipient.
        //Basically, they state that parsing should not fail just because there are extra unexpected items.
        //And parsing should also not fail if expected items are missing.

        public static void Process(MessageHL7 msg, bool isVerboseLogging)
        {
            HL7MsgCur           = new HL7Msg();
            HL7MsgCur.HL7Status = HL7MessageStatus.InFailed;          //it will be marked InProcessed once data is inserted.
            HL7MsgCur.MsgText   = msg.ToString();
            HL7MsgCur.PatNum    = 0;
            HL7MsgCur.AptNum    = 0;
            List <HL7Msg> hl7Existing = HL7Msgs.GetOneExisting(HL7MsgCur);

            if (hl7Existing.Count > 0)           //This message is already in the db
            {
                HL7MsgCur.HL7MsgNum = hl7Existing[0].HL7MsgNum;
                HL7Msgs.UpdateDateTStamp(HL7MsgCur);
                msg.ControlId = HL7Msgs.GetControlId(HL7MsgCur);
                return;
            }
            else
            {
                //Insert as InFailed until processing is complete.  Update once complete, PatNum will have correct value, AptNum will have correct value if SIU message or 0 if ADT, and status changed to InProcessed
                HL7Msgs.Insert(HL7MsgCur);
            }
            IsVerboseLogging = isVerboseLogging;
            IsNewPat         = false;
            HL7Def def = HL7Defs.GetOneDeepEnabled();

            if (def == null)
            {
                HL7MsgCur.Note = "Could not process HL7 message.  No HL7 definition is enabled.";
                HL7Msgs.Update(HL7MsgCur);
                throw new Exception("Could not process HL7 message.  No HL7 definition is enabled.");
            }
            HL7DefMessage hl7defmsg = null;

            for (int i = 0; i < def.hl7DefMessages.Count; i++)
            {
                if (def.hl7DefMessages[i].MessageType == msg.MsgType)               //&& def.hl7DefMessages[i].EventType==msg.EventType) { //Ignoring event type for now, we will treat all ADT's and SIU's the same
                {
                    hl7defmsg = def.hl7DefMessages[i];
                }
            }
            if (hl7defmsg == null)           //No message definition matches this message's MessageType and EventType
            {
                HL7MsgCur.Note = "Could not process HL7 message.  No definition for this type of message in the enabled HL7Def.";
                HL7Msgs.Update(HL7MsgCur);
                throw new Exception("Could not process HL7 message.  No definition for this type of message in the enabled HL7Def.");
            }
            string   chartNum      = null;
            long     patNum        = 0;
            DateTime birthdate     = DateTime.MinValue;
            string   patLName      = null;
            string   patFName      = null;
            bool     isExistingPID = false;      //Needed to add note to hl7msg table if there isn't a PID segment in the message.

            //Get patient in question, incoming messages must have a PID segment so use that to find the pat in question
            for (int s = 0; s < hl7defmsg.hl7DefSegments.Count; s++)
            {
                if (hl7defmsg.hl7DefSegments[s].SegmentName != SegmentNameHL7.PID)
                {
                    continue;
                }
                int pidOrder = hl7defmsg.hl7DefSegments[s].ItemOrder;
                //we found the PID segment in the def, make sure it exists in the msg
                if (msg.Segments.Count <= pidOrder ||           //If the number of segments in the message is less than the item order of the PID segment
                    msg.Segments[pidOrder].GetField(0).ToString() != "PID"                      //Or if the segment we expect to be the PID segment is not the PID segment
                    )
                {
                    break;
                }
                isExistingPID = true;
                for (int f = 0; f < hl7defmsg.hl7DefSegments[s].hl7DefFields.Count; f++)           //Go through fields of PID segment and get patnum, chartnum, patient name, and/or birthdate to locate patient
                {
                    if (hl7defmsg.hl7DefSegments[s].hl7DefFields[f].FieldName == "pat.ChartNumber")
                    {
                        int chartNumOrdinal = hl7defmsg.hl7DefSegments[s].hl7DefFields[f].OrdinalPos;
                        chartNum = msg.Segments[pidOrder].Fields[chartNumOrdinal].ToString();
                    }
                    else if (hl7defmsg.hl7DefSegments[s].hl7DefFields[f].FieldName == "pat.PatNum")
                    {
                        int patNumOrdinal = hl7defmsg.hl7DefSegments[s].hl7DefFields[f].OrdinalPos;
                        patNum = PIn.Long(msg.Segments[pidOrder].Fields[patNumOrdinal].ToString());
                    }
                    else if (hl7defmsg.hl7DefSegments[s].hl7DefFields[f].FieldName == "pat.birthdateTime")
                    {
                        int patBdayOrdinal = hl7defmsg.hl7DefSegments[s].hl7DefFields[f].OrdinalPos;
                        birthdate = FieldParser.DateTimeParse(msg.Segments[pidOrder].Fields[patBdayOrdinal].ToString());
                    }
                    else if (hl7defmsg.hl7DefSegments[s].hl7DefFields[f].FieldName == "pat.nameLFM")
                    {
                        int patNameOrdinal = hl7defmsg.hl7DefSegments[s].hl7DefFields[f].OrdinalPos;
                        patLName = msg.Segments[pidOrder].GetFieldComponent(patNameOrdinal, 0);
                        patFName = msg.Segments[pidOrder].GetFieldComponent(patNameOrdinal, 1);
                    }
                }
            }
            if (!isExistingPID)
            {
                HL7MsgCur.Note = "Could not process the HL7 message due to missing PID segment.";
                HL7Msgs.Update(HL7MsgCur);
                throw new Exception("Could not process HL7 message.  Could not process the HL7 message due to missing PID segment.");
            }
            //We now have patnum, chartnum, patname, and/or birthdate so locate pat
            Patient pat    = null;
            Patient patOld = null;

            if (patNum != 0)
            {
                pat = Patients.GetPat(patNum);
            }
            if (def.InternalType != "eCWStandalone" && pat == null)
            {
                IsNewPat = true;
            }
            //In eCWstandalone integration, if we couldn't locate patient by patNum or patNum was 0 then pat will still be null so try to locate by chartNum if chartNum is not null
            if (def.InternalType == "eCWStandalone" && chartNum != null)
            {
                pat = Patients.GetPatByChartNumber(chartNum);
            }
            //In eCWstandalone integration, if pat is still null we need to try to locate patient by name and birthdate
            if (def.InternalType == "eCWStandalone" && pat == null)
            {
                long patNumByName = Patients.GetPatNumByNameAndBirthday(patLName, patFName, birthdate);
                //If patNumByName is 0 we couldn't locate by patNum, chartNum or name and birthdate so this message must be for a new patient
                if (patNumByName == 0)
                {
                    IsNewPat = true;
                }
                else
                {
                    pat             = Patients.GetPat(patNumByName);
                    patOld          = pat.Copy();
                    pat.ChartNumber = chartNum;                  //from now on, we will be able to find pat by chartNumber
                    Patients.Update(pat, patOld);
                }
            }
            if (IsNewPat)
            {
                pat = new Patient();
                if (chartNum != null)
                {
                    pat.ChartNumber = chartNum;
                }
                if (patNum != 0)
                {
                    pat.PatNum    = patNum;
                    pat.Guarantor = patNum;
                }
                pat.PriProv     = PrefC.GetLong(PrefName.PracticeDefaultProv);
                pat.BillingType = PrefC.GetLong(PrefName.PracticeDefaultBillType);
            }
            else
            {
                patOld = pat.Copy();
            }
            //Update hl7msg table with correct PatNum for this message
            HL7MsgCur.PatNum = pat.PatNum;
            HL7Msgs.Update(HL7MsgCur);
            //If this is a message that contains an SCH segment, loop through to find the AptNum.  Pass it to the other segments that will need it.
            long aptNum = 0;

            for (int s = 0; s < hl7defmsg.hl7DefSegments.Count; s++)
            {
                if (hl7defmsg.hl7DefSegments[s].SegmentName != SegmentNameHL7.SCH)
                {
                    continue;
                }
                //we found the SCH segment
                int schOrder = hl7defmsg.hl7DefSegments[s].ItemOrder;
                for (int f = 0; f < hl7defmsg.hl7DefSegments[s].hl7DefFields.Count; f++)           //Go through fields of SCH segment and get AptNum
                {
                    if (hl7defmsg.hl7DefSegments[s].hl7DefFields[f].FieldName == "apt.AptNum")
                    {
                        int aptNumOrdinal = hl7defmsg.hl7DefSegments[s].hl7DefFields[f].OrdinalPos;
                        aptNum = PIn.Long(msg.Segments[schOrder].Fields[aptNumOrdinal].ToString());
                    }
                }
            }
            //We now have a patient object , either loaded from the db or new, and aptNum so process this message for this patient
            //We need to insert the pat to get a patnum so we can compare to guar patnum to see if relationship to guar is self
            if (IsNewPat)
            {
                if (isVerboseLogging)
                {
                    EventLog.WriteEntry("OpenDentHL7", "Inserted patient: " + pat.FName + " " + pat.LName, EventLogEntryType.Information);
                }
                if (pat.PatNum == 0)
                {
                    pat.PatNum = Patients.Insert(pat, false);
                }
                else
                {
                    pat.PatNum = Patients.Insert(pat, true);
                }
                patOld = pat.Copy();
            }
            for (int i = 0; i < hl7defmsg.hl7DefSegments.Count; i++)
            {
                try {
                    SegmentHL7 seg = msg.GetSegment(hl7defmsg.hl7DefSegments[i].SegmentName, !hl7defmsg.hl7DefSegments[i].IsOptional);
                    if (seg != null)                   //null if segment was not found but is optional
                    {
                        ProcessSeg(pat, aptNum, hl7defmsg.hl7DefSegments[i], seg, msg);
                    }
                }
                catch (ApplicationException ex) {               //Required segment was missing, or other error.
                    HL7MsgCur.Note = "Could not process this HL7 message.  " + ex;
                    HL7Msgs.Update(HL7MsgCur);
                    throw new Exception("Could not process HL7 message.  " + ex);
                }
            }
            //We have processed the message so now update or insert the patient
            if (pat.FName == "" || pat.LName == "")
            {
                EventLog.WriteEntry("OpenDentHL7", "Patient demographics not processed due to missing first or last name. PatNum:" + pat.PatNum.ToString()
                                    , EventLogEntryType.Information);
                HL7MsgCur.Note = "Patient demographics not processed due to missing first or last name. PatNum:" + pat.PatNum.ToString();
                HL7Msgs.Update(HL7MsgCur);
                return;
            }
            if (IsNewPat)
            {
                if (pat.Guarantor == 0)
                {
                    pat.Guarantor = pat.PatNum;
                    Patients.Update(pat, patOld);
                }
                else
                {
                    Patients.Update(pat, patOld);
                }
            }
            else
            {
                if (isVerboseLogging)
                {
                    EventLog.WriteEntry("OpenDentHL7", "Updated patient: " + pat.FName + " " + pat.LName, EventLogEntryType.Information);
                }
                Patients.Update(pat, patOld);
            }
            HL7MsgCur.HL7Status = HL7MessageStatus.InProcessed;
            HL7Msgs.Update(HL7MsgCur);
        }
Example #8
0
        ///<summary>Returns empty string if no duplicates, otherwise returns duplicate procedure information.  In all places where this is called, we are guaranteed to have the eCW bridge turned on.  So this is an eCW peculiarity rather than an HL7 restriction.  Other HL7 interfaces will not be checking for duplicate procedures unless we intentionally add that as a feature later.</summary>
        public static string ProcsContainDuplicates(List <Procedure> procs)
        {
            bool   hasLongDCodes = false;
            HL7Def defCur        = HL7Defs.GetOneDeepEnabled();

            if (defCur != null)
            {
                hasLongDCodes = defCur.HasLongDCodes;
            }
            string           info         = "";
            List <Procedure> procsChecked = new List <Procedure>();

            for (int i = 0; i < procs.Count; i++)
            {
                Procedure     proc        = procs[i];
                ProcedureCode procCode    = ProcedureCodes.GetProcCode(procs[i].CodeNum);
                string        procCodeStr = procCode.ProcCode;
                if (procCodeStr.Length > 5 &&
                    procCodeStr.StartsWith("D") &&
                    !hasLongDCodes)
                {
                    procCodeStr = procCodeStr.Substring(0, 5);
                }
                for (int j = 0; j < procsChecked.Count; j++)
                {
                    Procedure     procDup        = procsChecked[j];
                    ProcedureCode procCodeDup    = ProcedureCodes.GetProcCode(procsChecked[j].CodeNum);
                    string        procCodeDupStr = procCodeDup.ProcCode;
                    if (procCodeDupStr.Length > 5 &&
                        procCodeDupStr.StartsWith("D") &&
                        !hasLongDCodes)
                    {
                        procCodeDupStr = procCodeDupStr.Substring(0, 5);
                    }
                    if (procCodeDupStr != procCodeStr)
                    {
                        continue;
                    }
                    if (procDup.ToothNum != proc.ToothNum)
                    {
                        continue;
                    }
                    if (procDup.ToothRange != proc.ToothRange)
                    {
                        continue;
                    }
                    if (procDup.ProcFee != proc.ProcFee)
                    {
                        continue;
                    }
                    if (procDup.Surf != proc.Surf)
                    {
                        continue;
                    }
                    if (info != "")
                    {
                        info += ", ";
                    }
                    info += procCodeDupStr;
                }
                procsChecked.Add(proc);
            }
            if (info != "")
            {
                info = Lan.g("ProcedureL", "Duplicate procedures") + ": " + info;
            }
            return(info);
        }
Example #9
0
        public void StartManually()
        {
            //connect to OD db.
            XmlDocument document = new XmlDocument();
            string      pathXml  = Path.Combine(Application.StartupPath, "FreeDentalConfig.xml");

            try{
                document.Load(pathXml);
            }
            catch {
                EventLog.WriteEntry("OpenDentHL7", DateTime.Now.ToLongTimeString() + " - Could not find " + pathXml, EventLogEntryType.Error);
                throw new ApplicationException("Could not find " + pathXml);
            }
            XPathNavigator Navigator = document.CreateNavigator();
            XPathNavigator nav;

            DataConnection.DBtype = DatabaseType.MySql;
            nav = Navigator.SelectSingleNode("//DatabaseConnection");
            string         computerName = nav.SelectSingleNode("ComputerName").Value;
            string         database     = nav.SelectSingleNode("Database").Value;
            string         user         = nav.SelectSingleNode("User").Value;
            string         password     = nav.SelectSingleNode("Password").Value;
            XPathNavigator verboseNav   = Navigator.SelectSingleNode("//HL7verbose");

            if (verboseNav != null && verboseNav.Value == "True")
            {
                IsVerboseLogging = true;
                EventLog.WriteEntry("OpenDentHL7", "Verbose mode.", EventLogEntryType.Information);
            }
            OpenDentBusiness.DataConnection dcon = new OpenDentBusiness.DataConnection();
            //Try to connect to the database directly
            try {
                dcon.SetDb(computerName, database, user, password, "", "", DataConnection.DBtype);
                //a direct connection does not utilize lower privileges.
                RemotingClient.RemotingRole = RemotingRole.ClientDirect;
            }
            catch {            //(Exception ex){
                throw new ApplicationException("Connection to database failed.");
            }
            //check db version
            string dbVersion = PrefC.GetString(PrefName.ProgramVersion);

            if (Application.ProductVersion.ToString() != dbVersion)
            {
                EventLog.WriteEntry("OpenDentHL7", "Versions do not match.  Db version:" + dbVersion + ".  Application version:" + Application.ProductVersion.ToString(), EventLogEntryType.Error);
                throw new ApplicationException("Versions do not match.  Db version:" + dbVersion + ".  Application version:" + Application.ProductVersion.ToString());
            }
            if (Programs.IsEnabled(ProgramName.eClinicalWorks) && !HL7Defs.IsExistingHL7Enabled())             //eCW enabled, and no HL7def enabled.
            //prevent startup:
            {
                long   progNum        = Programs.GetProgramNum(ProgramName.eClinicalWorks);
                string hl7Server      = ProgramProperties.GetPropVal(progNum, "HL7Server");
                string hl7ServiceName = ProgramProperties.GetPropVal(progNum, "HL7ServiceName");
                if (hl7Server == "")               //for the first time run
                {
                    ProgramProperties.SetProperty(progNum, "HL7Server", System.Environment.MachineName);
                    hl7Server = System.Environment.MachineName;
                }
                if (hl7ServiceName == "")               //for the first time run
                {
                    ProgramProperties.SetProperty(progNum, "HL7ServiceName", this.ServiceName);
                    hl7ServiceName = this.ServiceName;
                }
                if (hl7Server.ToLower() != System.Environment.MachineName.ToLower())
                {
                    EventLog.WriteEntry("OpenDentHL7", "The HL7 Server name does not match the name set in Program Links eClinicalWorks Setup.  Server name: " + System.Environment.MachineName
                                        + ", Server name in Program Links: " + hl7Server, EventLogEntryType.Error);
                    throw new ApplicationException("The HL7 Server name does not match the name set in Program Links eClinicalWorks Setup.  Server name: " + System.Environment.MachineName
                                                   + ", Server name in Program Links: " + hl7Server);
                }
                if (hl7ServiceName.ToLower() != this.ServiceName.ToLower())
                {
                    EventLog.WriteEntry("OpenDentHL7", "The HL7 Service Name does not match the name set in Program Links eClinicalWorks Setup.  Service name: " + this.ServiceName + ", Service name in Program Links: "
                                        + hl7ServiceName, EventLogEntryType.Error);
                    throw new ApplicationException("The HL7 Service Name does not match the name set in Program Links eClinicalWorks Setup.  Service name: " + this.ServiceName + ", Service name in Program Links: "
                                                   + hl7ServiceName);
                }
                EcwOldSendAndReceive();
                return;
            }
            HL7Def hL7Def = HL7Defs.GetOneDeepEnabled();

            if (hL7Def == null)
            {
                return;
            }
            if (hL7Def.HL7Server == "")
            {
                hL7Def.HL7Server = System.Environment.MachineName;
                HL7Defs.Update(hL7Def);
            }
            if (hL7Def.HL7ServiceName == "")
            {
                hL7Def.HL7ServiceName = this.ServiceName;
                HL7Defs.Update(hL7Def);
            }
            if (hL7Def.HL7Server.ToLower() != System.Environment.MachineName.ToLower())
            {
                EventLog.WriteEntry("OpenDentHL7", "The HL7 Server name does not match the name in the enabled HL7Def Setup.  Server name: " + System.Environment.MachineName + ", Server name in HL7Def: " + hL7Def.HL7Server,
                                    EventLogEntryType.Error);
                throw new ApplicationException("The HL7 Server name does not match the name in the enabled HL7Def Setup.  Server name: " + System.Environment.MachineName + ", Server name in HL7Def: " + hL7Def.HL7Server);
            }
            if (hL7Def.HL7ServiceName.ToLower() != this.ServiceName.ToLower())
            {
                EventLog.WriteEntry("OpenDentHL7", "The HL7 Service Name does not match the name in the enabled HL7Def Setup.  Service name: " + this.ServiceName + ", Service name in HL7Def: " + hL7Def.HL7ServiceName,
                                    EventLogEntryType.Error);
                throw new ApplicationException("The HL7 Service Name does not match the name in the enabled HL7Def Setup.  Service name: " + this.ServiceName + ", Service name in HL7Def: " + hL7Def.HL7ServiceName);
            }
            HL7DefEnabled = hL7Def;          //so we can access it later from other methods
            if (HL7DefEnabled.ModeTx == ModeTxHL7.File)
            {
                hl7FolderOut = HL7DefEnabled.OutgoingFolder;
                hl7FolderIn  = HL7DefEnabled.IncomingFolder;
                if (!Directory.Exists(hl7FolderOut))
                {
                    EventLog.WriteEntry("OpenDentHL7", "The outgoing HL7 folder does not exist.  Path is set to: " + hl7FolderOut, EventLogEntryType.Error);
                    throw new ApplicationException("The outgoing HL7 folder does not exist.  Path is set to: " + hl7FolderOut);
                }
                if (!Directory.Exists(hl7FolderIn))
                {
                    EventLog.WriteEntry("OpenDentHL7", "The incoming HL7 folder does not exist.  Path is set to: " + hl7FolderIn, EventLogEntryType.Error);
                    throw new ApplicationException("The incoming HL7 folder does not exist.  Path is set to: " + hl7FolderIn);
                }
                //start polling the folder for waiting messages to import.  Every 5 seconds.
                TimerCallback timercallbackReceive = new TimerCallback(TimerCallbackReceiveFiles);
                timerReceiveFiles = new System.Threading.Timer(timercallbackReceive, null, 5000, 5000);
                //start polling the db for new HL7 messages to send. Every 1.8 seconds.
                TimerCallback timercallbackSend = new TimerCallback(TimerCallbackSendFiles);
                timerSendFiles = new System.Threading.Timer(timercallbackSend, null, 1800, 1800);
            }
            else              //TCP/IP
            {
                CreateIncomingTcpListener();
                //start a timer to poll the database and to send messages as needed.  Every 6 seconds.  We increased the time between polling the database from 3 seconds to 6 seconds because we are now waiting 5 seconds for a message acknowledgment from eCW.
                TimerCallback timercallbackSendTCP = new TimerCallback(TimerCallbackSendTCP);
                timerSendTCP = new System.Threading.Timer(timercallbackSendTCP, null, 1800, 6000);
            }
        }
Example #10
0
        ///<summary>Returns null if there is no HL7Def enabled or if there is no outbound DFT defined for the enabled HL7Def.</summary>
        public static MessageHL7 GenerateDFT(List <Procedure> listProcs, EventTypeHL7 eventType, Patient pat, Patient guar, long aptNum, string pdfDescription, string pdfDataString)
        {
            //In \\SERVERFILES\storage\OPEN DENTAL\Programmers Documents\Standards (X12, ADA, etc)\HL7\Version2.6\V26_CH02_Control_M4_JAN2007.doc
            //On page 28, there is a Message Construction Pseudocode as well as a flowchart which might help.
            MessageHL7 msgHl7 = new MessageHL7(MessageTypeHL7.DFT);
            HL7Def     hl7Def = HL7Defs.GetOneDeepEnabled();

            if (hl7Def == null)
            {
                return(null);
            }
            //find a DFT message in the def
            HL7DefMessage hl7DefMessage = null;

            for (int i = 0; i < hl7Def.hl7DefMessages.Count; i++)
            {
                if (hl7Def.hl7DefMessages[i].MessageType == MessageTypeHL7.DFT && hl7Def.hl7DefMessages[i].InOrOut == InOutHL7.Outgoing)
                {
                    hl7DefMessage = hl7Def.hl7DefMessages[i];
                    //continue;
                    break;
                }
            }
            if (hl7DefMessage == null)           //DFT message type is not defined so do nothing and return
            {
                return(null);
            }
            if (PrefC.GetBool(PrefName.ShowFeaturePatientClone))
            {
                pat = Patients.GetOriginalPatientForClone(pat);
            }
            Provider       prov         = Providers.GetProv(Patients.GetProvNum(pat));
            Appointment    apt          = Appointments.GetOneApt(aptNum);
            List <PatPlan> listPatPlans = PatPlans.Refresh(pat.PatNum);

            for (int i = 0; i < hl7DefMessage.hl7DefSegments.Count; i++)
            {
                int repeatCount = 1;
                if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.FT1)
                {
                    repeatCount = listProcs.Count;
                }
                else if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.IN1)
                {
                    repeatCount = listPatPlans.Count;
                }
                //for example, countRepeat can be zero in the case where we are only sending a PDF of the TP to eCW, and no procs.
                //or the patient does not have any current insplans for IN1 segments
                for (int j = 0; j < repeatCount; j++)           //FT1 is optional and can repeat so add as many FT1's as procs in procList, IN1 is optional and can repeat as well, repeat for the number of patplans in patplanList
                {
                    if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.FT1 && listProcs.Count > j)
                    {
                        prov = Providers.GetProv(listProcs[j].ProvNum);
                    }
                    Procedure proc = null;
                    if (listProcs.Count > j)                   //procList could be an empty list
                    {
                        proc = listProcs[j];
                    }
                    PatPlan patPlanCur = null;
                    InsPlan insPlanCur = null;
                    InsSub  insSubCur  = null;
                    Carrier carrierCur = null;
                    Patient subscriber = null;
                    if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.IN1)
                    {
                        patPlanCur = listPatPlans[j];
                        insSubCur  = InsSubs.GetOne(patPlanCur.InsSubNum);
                        insPlanCur = InsPlans.RefreshOne(insSubCur.PlanNum);
                        carrierCur = Carriers.GetCarrier(insPlanCur.CarrierNum);
                        subscriber = Patients.GetPat(insSubCur.Subscriber);
                    }
                    SegmentHL7 seg = new SegmentHL7(hl7DefMessage.hl7DefSegments[i].SegmentName);
                    seg.SetField(0, hl7DefMessage.hl7DefSegments[i].SegmentName.ToString());
                    for (int f = 0; f < hl7DefMessage.hl7DefSegments[i].hl7DefFields.Count; f++)
                    {
                        string fieldName = hl7DefMessage.hl7DefSegments[i].hl7DefFields[f].FieldName;
                        if (fieldName == "")                       //If fixed text instead of field name just add text to segment
                        {
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[f].OrdinalPos, hl7DefMessage.hl7DefSegments[i].hl7DefFields[f].FixedText);
                        }
                        else
                        {
                            string fieldValue = "";
                            if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.IN1)
                            {
                                fieldValue = FieldConstructor.GenerateFieldIN1(hl7Def, fieldName, j + 1, patPlanCur, insSubCur, insPlanCur, carrierCur, listPatPlans.Count, subscriber);
                            }
                            else
                            {
                                fieldValue = FieldConstructor.GenerateField(hl7Def, fieldName, MessageTypeHL7.DFT, pat, prov, proc, guar, apt, j + 1, eventType,
                                                                            pdfDescription, pdfDataString, MessageStructureHL7.DFT_P03, seg.Name);
                            }
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[f].OrdinalPos, fieldValue);
                        }
                    }
                    msgHl7.Segments.Add(seg);
                }
            }
            return(msgHl7);
        }
Example #11
0
        ///<summary>Returns null if no HL7 def is enabled or no SRR is defined in the enabled def.  An SRR - Schedule Request Response message is sent when an SRM - Schedule Request Message is received.  The SRM is acknowledged just like any inbound message, but the SRR notifies the placer application that the requested modification took place.  Currently the only appointment modifications allowed are updating the appt note, setting the dentist and hygienist, updating the confirmation status, and changing the ClinicNum.  Setting the appointment status to Broken is also supported.</summary>
        public static MessageHL7 GenerateSRR(Patient pat, Appointment apt, EventTypeHL7 eventType, string controlId, bool isAck, string ackEvent)
        {
            HL7Def hl7Def = HL7Defs.GetOneDeepEnabled();

            if (hl7Def == null)
            {
                return(null);
            }
            //find an outbound SRR message in the def
            HL7DefMessage hl7DefMessage = null;

            for (int i = 0; i < hl7Def.hl7DefMessages.Count; i++)
            {
                if (hl7Def.hl7DefMessages[i].MessageType == MessageTypeHL7.SRR && hl7Def.hl7DefMessages[i].InOrOut == InOutHL7.Outgoing)
                {
                    hl7DefMessage = hl7Def.hl7DefMessages[i];
                    break;
                }
            }
            if (hl7DefMessage == null)           //SRR message type is not defined so do nothing and return
            {
                return(null);
            }
            if (PrefC.GetBool(PrefName.ShowFeaturePatientClone))
            {
                pat = Patients.GetOriginalPatientForClone(pat);
            }
            MessageHL7 msgHl7  = new MessageHL7(MessageTypeHL7.SRR);
            Provider   provPri = Providers.GetProv(apt.ProvNum);

            //go through each segment in the def
            for (int i = 0; i < hl7DefMessage.hl7DefSegments.Count; i++)
            {
                List <Provider> listProvs = new List <Provider>();
                listProvs.Add(provPri);
                if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.AIP && apt.ProvHyg > 0)
                {
                    listProvs.Add(Providers.GetProv(apt.ProvHyg));
                }
                for (int j = 0; j < listProvs.Count; j++)           //AIP will be repeated if there is a dentist and a hygienist on the appt
                {
                    Provider   prov = listProvs[j];
                    SegmentHL7 seg  = new SegmentHL7(hl7DefMessage.hl7DefSegments[i].SegmentName);
                    seg.SetField(0, hl7DefMessage.hl7DefSegments[i].SegmentName.ToString());
                    for (int k = 0; k < hl7DefMessage.hl7DefSegments[i].hl7DefFields.Count; k++)
                    {
                        string fieldName = hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].FieldName;
                        if (fieldName == "")                       //If fixed text instead of field name just add text to segment
                        {
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].OrdinalPos, hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].FixedText);
                        }
                        else
                        {
                            string fieldValue = "";
                            if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.MSA)
                            {
                                fieldValue = FieldConstructor.GenerateFieldACK(hl7Def, fieldName, controlId, isAck, ackEvent);
                            }
                            else
                            {
                                fieldValue = FieldConstructor.GenerateFieldSRR(hl7Def, fieldName, pat, prov, apt, j + 1, eventType, seg.Name);
                            }
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].OrdinalPos, fieldValue);
                        }
                    }
                    msgHl7.Segments.Add(seg);
                }
            }
            return(msgHl7);
        }
Example #12
0
        ///<summary>Returns null if there is no HL7Def enabled or if there is no outbound SIU defined for the enabled HL7Def.</summary>
        public static MessageHL7 GenerateSIU(Patient pat, Patient guar, EventTypeHL7 eventType, Appointment apt)
        {
            HL7Def hl7Def = HL7Defs.GetOneDeepEnabled();

            if (hl7Def == null)
            {
                return(null);
            }
            //find an outbound SIU message in the def
            HL7DefMessage hl7DefMessage = null;

            for (int i = 0; i < hl7Def.hl7DefMessages.Count; i++)
            {
                if (hl7Def.hl7DefMessages[i].MessageType == MessageTypeHL7.SIU && hl7Def.hl7DefMessages[i].InOrOut == InOutHL7.Outgoing)
                {
                    hl7DefMessage = hl7Def.hl7DefMessages[i];
                    //continue;
                    break;
                }
            }
            if (hl7DefMessage == null)           //SIU message type is not defined so do nothing and return
            {
                return(null);
            }
            if (apt == null)           //SIU messages must have an appointment
            {
                return(null);
            }
            if (PrefC.GetBool(PrefName.ShowFeaturePatientClone))
            {
                pat = Patients.GetOriginalPatientForClone(pat);
            }
            MessageHL7 messageHL7 = new MessageHL7(MessageTypeHL7.SIU);
            Provider   prov       = Providers.GetProv(apt.ProvNum);

            for (int i = 0; i < hl7DefMessage.hl7DefSegments.Count; i++)
            {
                int repeatCount = 1;
                //AIP segment can repeat, once for the dentist on the appt and once for the hygienist
                if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.AIP && apt.ProvHyg > 0)
                {
                    repeatCount = 2;
                }
                for (int j = 0; j < repeatCount; j++)           //AIP will be repeated if there is a dentist and a hygienist on the appt
                {
                    if (j > 0)
                    {
                        prov = Providers.GetProv(apt.ProvHyg);
                        if (prov == null)
                        {
                            break;                            //shouldn't happen, apt.ProvHyg would have to be set to an invalid ProvNum on the appt, just in case
                        }
                    }
                    SegmentHL7 seg = new SegmentHL7(hl7DefMessage.hl7DefSegments[i].SegmentName);
                    seg.SetField(0, hl7DefMessage.hl7DefSegments[i].SegmentName.ToString());
                    for (int k = 0; k < hl7DefMessage.hl7DefSegments[i].hl7DefFields.Count; k++)
                    {
                        string fieldName = hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].FieldName;
                        if (fieldName == "")                       //If fixed text instead of field name just add text to segment
                        {
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].OrdinalPos, hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].FixedText);
                        }
                        else
                        {
                            string fieldValue = FieldConstructor.GenerateFieldSIU(hl7Def, fieldName, pat, prov, guar, apt, j + 1, eventType, seg.Name);
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].OrdinalPos, fieldValue);
                        }
                    }
                    messageHL7.Segments.Add(seg);
                }
            }
            return(messageHL7);
        }
Example #13
0
        ///<summary>Returns null if there is no HL7Def enabled or if there is no outbound ADT defined for the enabled HL7Def.</summary>
        public static MessageHL7 GenerateADT(Patient pat, Patient guar, EventTypeHL7 eventType)
        {
            HL7Def hl7Def = HL7Defs.GetOneDeepEnabled();

            if (hl7Def == null)
            {
                return(null);
            }
            //find an outbound ADT message in the def
            HL7DefMessage hl7DefMessage = null;

            for (int i = 0; i < hl7Def.hl7DefMessages.Count; i++)
            {
                if (hl7Def.hl7DefMessages[i].MessageType == MessageTypeHL7.ADT && hl7Def.hl7DefMessages[i].InOrOut == InOutHL7.Outgoing)
                {
                    hl7DefMessage = hl7Def.hl7DefMessages[i];
                    //continue;
                    break;
                }
            }
            if (hl7DefMessage == null)           //ADT message type is not defined so do nothing and return
            {
                return(null);
            }
            if (PrefC.GetBool(PrefName.ShowFeaturePatientClone))
            {
                pat = Patients.GetOriginalPatientForClone(pat);
            }
            MessageHL7     messageHL7   = new MessageHL7(MessageTypeHL7.ADT);
            Provider       prov         = Providers.GetProv(Patients.GetProvNum(pat));
            List <PatPlan> listPatPlans = PatPlans.Refresh(pat.PatNum);

            for (int i = 0; i < hl7DefMessage.hl7DefSegments.Count; i++)
            {
                int countRepeat = 1;
                //IN1 segment can repeat, get the number of current insurance plans attached to the patient
                if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.IN1)
                {
                    countRepeat = listPatPlans.Count;
                }
                //countRepeat is usually 1, but for repeatable/optional fields, it may be 0 or greater than 1
                //for example, countRepeat can be zero if the patient does not have any current insplans, in which case no IN1 segments will be included
                for (int j = 0; j < countRepeat; j++)           //IN1 is optional and can repeat so add as many as listPatplans
                {
                    PatPlan patplanCur = null;
                    InsPlan insplanCur = null;
                    InsSub  inssubCur  = null;
                    Carrier carrierCur = null;
                    Patient patSub     = null;
                    if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.IN1)                   //index repeat is guaranteed to be less than listPatplans.Count
                    {
                        patplanCur = listPatPlans[j];
                        inssubCur  = InsSubs.GetOne(patplanCur.InsSubNum);
                        insplanCur = InsPlans.RefreshOne(inssubCur.PlanNum);
                        carrierCur = Carriers.GetCarrier(insplanCur.CarrierNum);
                        if (pat.PatNum == inssubCur.Subscriber)
                        {
                            patSub = pat.Copy();
                        }
                        else
                        {
                            patSub = Patients.GetPat(inssubCur.Subscriber);
                        }
                    }
                    SegmentHL7 seg = new SegmentHL7(hl7DefMessage.hl7DefSegments[i].SegmentName);
                    seg.SetField(0, hl7DefMessage.hl7DefSegments[i].SegmentName.ToString());
                    for (int k = 0; k < hl7DefMessage.hl7DefSegments[i].hl7DefFields.Count; k++)
                    {
                        string fieldName = hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].FieldName;
                        if (fieldName == "")                       //If fixed text instead of field name just add text to segment
                        {
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].OrdinalPos, hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].FixedText);
                        }
                        else
                        {
                            string fieldValue = "";
                            if (hl7DefMessage.hl7DefSegments[i].SegmentName == SegmentNameHL7.IN1)
                            {
                                fieldValue = FieldConstructor.GenerateFieldIN1(hl7Def, fieldName, j + 1, patplanCur, inssubCur, insplanCur, carrierCur, listPatPlans.Count, patSub);
                            }
                            else
                            {
                                fieldValue = FieldConstructor.GenerateFieldADT(hl7Def, fieldName, pat, prov, guar, j + 1, eventType, seg.Name);
                            }
                            seg.SetField(hl7DefMessage.hl7DefSegments[i].hl7DefFields[k].OrdinalPos, fieldValue);
                        }
                    }
                    messageHL7.Segments.Add(seg);
                }
            }
            return(messageHL7);
        }
Example #14
0
        ///<summary>Uses sheet framework to generate a PDF file, save it to patient's image folder, and attempt to launch file with defualt reader.
        ///If using ImagesStoredInDB it will not launch PDF. If no valid patient is selected you cannot perform this action.</summary>
        private void butPDF_Click(object sender, EventArgs e)
        {
            if (PatCur == null)           //not attached to a patient when form loaded and they haven't selected a patient to attach to yet
            {
                MsgBox.Show(this, "The Medical Lab must be attached to a patient before the PDF can be saved.");
                return;
            }
            if (PatCur.PatNum > 0 && _medLabCur.PatNum != PatCur.PatNum)         //save the current patient attached to the MedLab if it has been changed
            {
                MoveLabsAndImagesHelper();
            }
            Cursor = Cursors.WaitCursor;
            SheetDef sheetDef = SheetUtil.GetMedLabResultsSheetDef();
            Sheet    sheet    = SheetUtil.CreateSheet(sheetDef, _medLabCur.PatNum);

            SheetFiller.FillFields(sheet, null, null, _medLabCur);
            //create the file in the temp folder location, then import so it works when storing images in the db
            string tempPath = ODFileUtils.CombinePaths(PrefC.GetTempFolderPath(), _medLabCur.PatNum.ToString() + ".pdf");

            SheetPrinting.CreatePdf(sheet, tempPath, null, _medLabCur);
            HL7Def defCur   = HL7Defs.GetOneDeepEnabled(true);
            long   category = defCur.LabResultImageCat;

            if (category == 0)
            {
                category = Defs.GetFirstForCategory(DefCat.ImageCats, true).DefNum;             //put it in the first category.
            }
            //create doc--------------------------------------------------------------------------------------
            OpenDentBusiness.Document docc = null;
            try {
                docc = ImageStore.Import(tempPath, category, Patients.GetPat(_medLabCur.PatNum));
            }
            catch (Exception ex) {
                ex.DoNothing();
                Cursor = Cursors.Default;
                MsgBox.Show(this, "Error saving document.");
                return;
            }
            finally {
                //Delete the temp file since we don't need it anymore.
                try {
                    File.Delete(tempPath);
                }
                catch {
                    //Do nothing.  This file will likely get cleaned up later.
                }
            }
            docc.Description = Lan.g(this, "MedLab Result");
            docc.DateCreated = DateTime.Now;
            Documents.Update(docc);
            string filePathAndName = "";

            if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
            {
                string patFolder = ImageStore.GetPatientFolder(Patients.GetPat(_medLabCur.PatNum), ImageStore.GetPreferredAtoZpath());
                filePathAndName = ODFileUtils.CombinePaths(patFolder, docc.FileName);
            }
            else if (CloudStorage.IsCloudStorage)
            {
                FormProgress FormP = new FormProgress();
                FormP.DisplayText          = "Downloading...";
                FormP.NumberFormat         = "F";
                FormP.NumberMultiplication = 1;
                FormP.MaxVal = 100;              //Doesn't matter what this value is as long as it is greater than 0
                FormP.TickMS = 1000;
                OpenDentalCloud.Core.TaskStateDownload state = CloudStorage.DownloadAsync(
                    ImageStore.GetPatientFolder(Patients.GetPat(_medLabCur.PatNum), ImageStore.GetPreferredAtoZpath())
                    , docc.FileName
                    , new OpenDentalCloud.ProgressHandler(FormP.OnProgress));
                if (FormP.ShowDialog() == DialogResult.Cancel)
                {
                    state.DoCancel = true;
                    return;
                }
                filePathAndName = PrefC.GetRandomTempFile(Path.GetExtension(docc.FileName));
                File.WriteAllBytes(filePathAndName, state.FileContent);
            }
            Cursor = Cursors.Default;
            if (filePathAndName != "")
            {
                Process.Start(filePathAndName);
            }
            SecurityLogs.MakeLogEntry(Permissions.SheetEdit, sheet.PatNum, sheet.Description + " from " + sheet.DateTimeSheet.ToShortDateString() + " pdf was created");
            DialogResult = DialogResult.OK;
        }
Example #15
0
        ///<summary>Returns null if there is no DFT defined for the enabled HL7Def.</summary>
        public static MessageHL7 GenerateDFT(List <Procedure> procList, EventTypeHL7 eventType, Patient pat, Patient guar, long aptNum, string pdfDescription, string pdfDataString)   //add event (A04 etc) parameters later if needed
        //In \\SERVERFILES\storage\OPEN DENTAL\Programmers Documents\Standards (X12, ADA, etc)\HL7\Version2.6\V26_CH02_Control_M4_JAN2007.doc
        //On page 28, there is a Message Construction Pseudocode as well as a flowchart which might help.
        {
            Provider    prov       = Providers.GetProv(Patients.GetProvNum(pat));
            Appointment apt        = Appointments.GetOneApt(aptNum);
            MessageHL7  messageHL7 = new MessageHL7(MessageTypeHL7.DFT);
            HL7Def      hl7Def     = HL7Defs.GetOneDeepEnabled();

            if (hl7Def == null)
            {
                return(null);
            }
            //find a DFT message in the def
            HL7DefMessage hl7DefMessage = null;

            for (int i = 0; i < hl7Def.hl7DefMessages.Count; i++)
            {
                if (hl7Def.hl7DefMessages[i].MessageType == MessageTypeHL7.DFT)
                {
                    hl7DefMessage = hl7Def.hl7DefMessages[i];
                    //continue;
                    break;
                }
            }
            if (hl7DefMessage == null)           //DFT message type is not defined so do nothing and return
            {
                return(null);
            }
            for (int s = 0; s < hl7DefMessage.hl7DefSegments.Count; s++)
            {
                int countRepeat = 1;
                if (hl7DefMessage.hl7DefSegments[s].SegmentName == SegmentNameHL7.FT1)
                {
                    countRepeat = procList.Count;
                }
                //for example, countRepeat can be zero in the case where we are only sending a PDF of the TP to eCW, and no procs.
                for (int repeat = 0; repeat < countRepeat; repeat++)           //FT1 is optional and can repeat so add as many FT1's as procs in procList
                //if(hl7DefMessage.hl7DefSegments[s].SegmentName==SegmentNameHL7.FT1) {
                {
                    if (hl7DefMessage.hl7DefSegments[s].SegmentName == SegmentNameHL7.FT1 && procList.Count > repeat)
                    {
                        prov = Providers.GetProv(procList[repeat].ProvNum);
                    }
                    SegmentHL7 seg = new SegmentHL7(hl7DefMessage.hl7DefSegments[s].SegmentName);
                    seg.SetField(0, hl7DefMessage.hl7DefSegments[s].SegmentName.ToString());
                    for (int f = 0; f < hl7DefMessage.hl7DefSegments[s].hl7DefFields.Count; f++)
                    {
                        string fieldName = hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].FieldName;
                        if (fieldName == "")                       //If fixed text instead of field name just add text to segment
                        {
                            seg.SetField(hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].OrdinalPos, hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].FixedText);
                        }
                        else
                        {
                            //seg.SetField(hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].OrdinalPos,
                            //FieldConstructor.GenerateDFT(hl7Def,fieldName,pat,prov,procList[repeat],guar,apt,repeat+1,eventType,pdfDescription,pdfDataString));
                            Procedure proc = null;
                            if (procList.Count > repeat)                           //procList could be an empty list
                            {
                                proc = procList[repeat];
                            }
                            seg.SetField(hl7DefMessage.hl7DefSegments[s].hl7DefFields[f].OrdinalPos,
                                         FieldConstructor.GenerateDFT(hl7Def, fieldName, pat, prov, proc, guar, apt, repeat + 1, eventType, pdfDescription, pdfDataString));
                        }
                    }
                    messageHL7.Segments.Add(seg);
                }
            }
            return(messageHL7);
        }
Example #16
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);
        }
        ///<summary></summary>
        public void FormRecTreatment_Load(object sender, System.EventArgs e)
        {
            labelCountry.Visible = false;
            textCountry.Visible  = false;
            textRegKey.Visible   = false;
            groupAddPt.Visible   = true;



            //Cannot add new patients from OD select patient interface.  Patient must be added from HL7 message.
            if (HL7Defs.IsExistingHL7Enabled())
            {
                HL7Def def = HL7Defs.GetOneDeepEnabled();
                if (def.ShowDemographics != HL7ShowDemographics.ChangeAndAdd)
                {
                    groupAddPt.Visible = false;
                }
            }
            else
            {
                if (Programs.UsingEcwTightOrFullMode())
                {
                    groupAddPt.Visible = false;
                }
            }
            comboBillingType.Items.Add(Lan.g(this, "All"));
            comboBillingType.SelectedIndex = 0;
            for (int i = 0; i < DefC.Short[(int)DefCat.BillingTypes].Length; i++)
            {
                comboBillingType.Items.Add(DefC.Short[(int)DefCat.BillingTypes][i].ItemName);
            }

            comboSite.Visible = false;
            labelSite.Visible = false;

            labelClinic.Visible = false;
            comboClinic.Visible = false;

            FillSearchOption();
            SetGridCols();
            if (ExplicitPatNums != null && ExplicitPatNums.Count > 0)
            {
                FillGrid(false, ExplicitPatNums);
                return;
            }
            if (InitialPatNum != 0)
            {
                Patient iPatient = Patients.GetLim(InitialPatNum);
                textLName.Text = iPatient.LName;
                FillGrid(false);

                /*if(grid2.CurrentRowIndex>-1){
                 *                      grid2.UnSelect(grid2.CurrentRowIndex);
                 *              }
                 *              for(int i=0;i<PtDataTable.Rows.Count;i++){
                 *                      if(PIn.PInt(PtDataTable.Rows[i][0].ToString())==InitialPatNum){
                 *                              grid2.CurrentRowIndex=i;
                 *                              grid2.Select(i);
                 *                              break;
                 *                      }
                 *              }*/
                return;
            }
            //Always fillGrid if _isPreFilledLoad.  Since the first name and last name are pre-filled, the results should be minimal.
            if (checkRefresh.Checked || _isPreFillLoad)
            {
                FillGrid(true);
                _isPreFillLoad = false;
            }

            if (cmbProc.Items.Count == 0)
            {
                fill_cmbProc();
            }
            if (pc != "")
            {
                pc = "";
            }
            if (SelectedPatNum != 0)
            {
                SelectedPatNum = 0;
            }

            dateStartPick.Value = DateTime.Today.AddYears(-1);
            dsVAL = dateStartPick.Value.ToShortDateString();
            deVAL = dateEndPick.Value.ToShortDateString();
        }