private void butSave_Click(object sender, EventArgs e) { if (PatCur == null) { MsgBox.Show(this, "Please attach to patient first."); return; } //Check lab dates to see if these labs already exist. for (int i = 0; i < ListEhrLabs.Count; i++) { EhrLab tempLab = null; //lab from DB if it exists. tempLab = EhrLabs.GetByGUID(ListEhrLabs[i].PlacerOrderUniversalID, ListEhrLabs[i].PlacerOrderNum); if (tempLab == null) { tempLab = EhrLabs.GetByGUID(ListEhrLabs[i].FillerOrderUniversalID, ListEhrLabs[i].FillerOrderNum); } if (tempLab != null) { //validate Date of Lab and attached patient. //Date if (tempLab.ResultDateTime.CompareTo(ListEhrLabs[i].ResultDateTime) < 0) //string compare dates will return 1+ if tempLab Date is greater. { MsgBox.Show(this, "This lab already exists in the database and has a more recent timestamp."); continue; } if (PatCur.PatNum != tempLab.PatNum) { //do nothing. We are importing an updated lab result and the previous lab result was attached to the wrong patient. //or do something. later maybe. } } ListEhrLabs[i].PatNum = PatCur.PatNum; Provider prov = Providers.GetProv(Security.CurUser.ProvNum); if (Security.CurUser.ProvNum != 0 && EhrProvKeys.GetKeysByFLName(prov.LName, prov.FName).Count > 0) //The user who is currently logged in is a provider and has a valid EHR key. { ListEhrLabs[i].IsCpoe = true; } ListEhrLabs[i] = EhrLabs.SaveToDB(ListEhrLabs[i]); //SAVE for (int j = 0; j < ListEhrLabs[i].ListEhrLabResults.Count; j++) //EHR TRIGGER { if (CDSPermissions.GetForUser(Security.CurUser.UserNum).ShowCDS&& CDSPermissions.GetForUser(Security.CurUser.UserNum).LabTestCDS) { FormCDSIntervention FormCDSI = new FormCDSIntervention(); FormCDSI.ListCDSI = EhrTriggers.TriggerMatch(ListEhrLabs[i].ListEhrLabResults[j], PatCur); FormCDSI.ShowIfRequired(false); } } } DialogResult = DialogResult.OK; //Done! }
private void butAdd_Click(object sender, EventArgs e) { FormEhrLabOrderEdit2014 FormLOE = new FormEhrLabOrderEdit2014(); FormLOE.EhrLabCur = new EhrLab(); FormLOE.EhrLabCur.PatNum = PatCur.PatNum; FormLOE.IsNew = true; FormLOE.ShowDialog(); if (FormLOE.DialogResult != DialogResult.OK) { return; } EhrMeasureEvent newMeasureEvent = new EhrMeasureEvent(); newMeasureEvent.DateTEvent = DateTime.Now; newMeasureEvent.EventType = EhrMeasureEventType.CPOE_LabOrdered; //default Loinc loinc = Loincs.GetByCode(FormLOE.EhrLabCur.UsiID); if (loinc != null && loinc.ClassType == "RAD") //short circuit logic { newMeasureEvent.EventType = EhrMeasureEventType.CPOE_RadOrdered; } newMeasureEvent.PatNum = FormLOE.EhrLabCur.PatNum; newMeasureEvent.MoreInfo = ""; newMeasureEvent.FKey = FormLOE.EhrLabCur.EhrLabNum; EhrMeasureEvents.Insert(newMeasureEvent); EhrLabs.SaveToDB(FormLOE.EhrLabCur); for (int i = 0; i < FormLOE.EhrLabCur.ListEhrLabResults.Count; i++) { if (CDSPermissions.GetForUser(Security.CurUser.UserNum).ShowCDS&& CDSPermissions.GetForUser(Security.CurUser.UserNum).LabTestCDS) { FormCDSIntervention FormCDSI = new FormCDSIntervention(); FormCDSI.ListCDSI = EhrTriggers.TriggerMatch(FormLOE.EhrLabCur.ListEhrLabResults[i], PatCur); FormCDSI.ShowIfRequired(false); } } FillGrid(); }
private void butImport_Click(object sender, EventArgs e) { MsgBoxCopyPaste MBCP = new MsgBoxCopyPaste("Paste HL7 Lab Message Text Here."); MBCP.textMain.SelectAll(); MBCP.ShowDialog(); if (MBCP.DialogResult != DialogResult.OK) { return; } List <EhrLab> listEhrLabs; try { listEhrLabs = EhrLabs.ProcessHl7Message(MBCP.textMain.Text); //Not a typical use of the msg box copy paste if (listEhrLabs[0].PatNum == PatCur.PatNum) //only need to check the first lab. //nothing to do here. Imported lab matches the current patient. { } else //does not match current patient, redirect to import form which displays patient information and is build for importing. { FormEhrLabOrderImport FormLOI = new FormEhrLabOrderImport(); FormLOI.PatCur = PatCur; FormLOI.Hl7LabMessage = MBCP.textMain.Text; FormLOI.ShowDialog(); FillGrid(); return; } //else if(listEhrLabs[0].PatNum==0) { // if(MessageBox.Show("Lab patient does not match current patient. Lab patient name is " // +MBCP.textMain.Text.Split(new string[] { "\r\n" },StringSplitOptions.RemoveEmptyEntries)[1].Split('|')[5].Split('~')[0].Split('^')[1]+" "//first name // +MBCP.textMain.Text.Split(new string[] { "\r\n" },StringSplitOptions.RemoveEmptyEntries)[1].Split('|')[5].Split('~')[0].Split('^')[1]+" "//last name // +"\r\nWould you like to import lab for the current patient?","",MessageBoxButtons.OKCancel)!=DialogResult.OK) // { // return; // } // //User agreed to import current lab(s) for current patient. // for(int i=0;i<listEhrLabs.Count;i++) { // listEhrLabs[i].PatNum=PatCur.PatNum; // //TODO: Import external OIDs and PatIDs so that we can identify this patient next time. // } //} //else {//Patnum is already associated with another patient. // MessageBox.Show("This lab contains patient information for a different patient. Lab patient name is " // +MBCP.textMain.Text.Split(new string[] { "\r\n" },StringSplitOptions.RemoveEmptyEntries)[1].Split('|')[5].Split('~')[0].Split('^')[1]+" "//first name // +MBCP.textMain.Text.Split(new string[] { "\r\n" },StringSplitOptions.RemoveEmptyEntries)[1].Split('|')[5].Split('~')[0].Split('^')[1]); // return; //} } catch (Exception Ex) { MessageBox.Show(this, "Unable to import lab.\r\n" + Ex.Message); return; } for (int i = 0; i < listEhrLabs.Count; i++) { EhrLab tempLab = null; //lab from DB if it exists. tempLab = EhrLabs.GetByGUID(listEhrLabs[i].PlacerOrderUniversalID, listEhrLabs[i].PlacerOrderNum); if (tempLab == null) { tempLab = EhrLabs.GetByGUID(listEhrLabs[i].FillerOrderUniversalID, listEhrLabs[i].FillerOrderNum); } if (tempLab != null) { //Date validation. //if(tempLab.ResultDateTime.CompareTo(listEhrLabs[i].ResultDateTime)<=0) {//string compare dates will return 1+ if tempLab Date is greater. // MsgBox.Show(this,"This lab already exists in the database and has a more recent timestamp."); // continue; //} //TODO: The code above works, but ignores more recent lab results. Although the lab order my be unchanged there may be updated lab results. //It would be better to check for updated results, unfortunately results have no unique identifiers. } Provider prov = Providers.GetProv(Security.CurUser.ProvNum); if (Security.CurUser.ProvNum != 0 && EhrProvKeys.GetKeysByFLName(prov.LName, prov.FName).Count > 0) //The user who is currently logged in is a provider and has a valid EHR key. { ListEhrLabs[i].IsCpoe = true; } listEhrLabs[i] = EhrLabs.SaveToDB(listEhrLabs[i]); //SAVE for (int j = 0; j < listEhrLabs[i].ListEhrLabResults.Count; j++) //EHR TRIGGER { if (CDSPermissions.GetForUser(Security.CurUser.UserNum).ShowCDS&& CDSPermissions.GetForUser(Security.CurUser.UserNum).LabTestCDS) { FormCDSIntervention FormCDSI = new FormCDSIntervention(); FormCDSI.ListCDSI = EhrTriggers.TriggerMatch(listEhrLabs[i].ListEhrLabResults[j], PatCur); FormCDSI.ShowIfRequired(false); } } } FillGrid(); }
private void butOk_Click(object sender, EventArgs e) { if (IsImport || IsViewOnly) { DialogResult = DialogResult.OK; return; } if (!EntriesAreValid()) { return; } if (Security.CurUser.ProvNum != 0 && Providers.GetProv(Security.CurUser.ProvNum).EhrKey != "") //The user who is currently logged in is a provider and has a valid EHR key. { EhrLabCur.IsCpoe = true; } if (EhrLabCur.PatNum == 0 && PatCurNum != null) { EhrLabCur.PatNum = PatCurNum; } //EhrLabCur.OrderControlCode=((HL70119)comb);//TODO:UI and this value. if (checkAutoID.Checked) { EhrLabCur.PlacerOrderNum = EhrLabs.GetNextOrderNum().ToString(); EhrLabCur.PlacerOrderNamespace = ""; EhrLabCur.PlacerOrderUniversalID = OIDInternals.GetForType(IdentifierType.LabOrder).IDRoot; EhrLabCur.PlacerOrderUniversalIDType = "ISO"; } else { EhrLabCur.PlacerOrderNum = textPlacerOrderNum.Text; EhrLabCur.PlacerOrderNamespace = textPlacerOrderNamespace.Text; EhrLabCur.PlacerOrderUniversalID = textPlacerOrderUniversalID.Text; EhrLabCur.PlacerOrderUniversalIDType = textPlacerOrderUniversalIDType.Text; } EhrLabCur.FillerOrderNum = textFillerOrderNum.Text; EhrLabCur.FillerOrderNamespace = textFillerOrderNamespace.Text; EhrLabCur.FillerOrderUniversalID = textFillerOrderUniversalID.Text; EhrLabCur.FillerOrderUniversalIDType = textFillerOrderUniversalIDType.Text; EhrLabCur.PlacerGroupNum = textPlacerGroupNum.Text; EhrLabCur.PlacerGroupNamespace = textPlacerGroupNamespace.Text; EhrLabCur.PlacerGroupUniversalID = textPlacerGroupUniversalID.Text; EhrLabCur.PlacerGroupUniversalIDType = textPlacerGroupUniversalIDType.Text; EhrLabCur.OrderingProviderID = textOrderingProvIdentifier.Text; EhrLabCur.OrderingProviderLName = textOrderingProvLastName.Text; EhrLabCur.OrderingProviderFName = textOrderingProvFirstName.Text; EhrLabCur.OrderingProviderMiddleNames = textOrderingProvMiddleName.Text; EhrLabCur.OrderingProviderSuffix = textOrderingProvSuffix.Text; EhrLabCur.OrderingProviderPrefix = textOrderingProvPrefix.Text; EhrLabCur.OrderingProviderAssigningAuthorityNamespaceID = textOrderingProvAANID.Text; EhrLabCur.OrderingProviderAssigningAuthorityUniversalID = textOrderingProvAAUID.Text; EhrLabCur.OrderingProviderAssigningAuthorityIDType = textOrderingProvAAUIDType.Text; EhrLabCur.OrderingProviderNameTypeCode = ((HL70200)comboOrderingProvNameType.SelectedIndex - 1); EhrLabCur.OrderingProviderIdentifierTypeCode = ((HL70203)comboOrderingProvIdType.SelectedIndex - 1); //EhrLabCur.SetIdOBR=PIn.Long("");//TODO: UI and Save EhrLabCur.UsiID = textUsiID.Text; EhrLabCur.UsiText = textUsiText.Text; EhrLabCur.UsiCodeSystemName = textUsiCodeSystemName.Text; EhrLabCur.UsiIDAlt = textUsiIDAlt.Text; EhrLabCur.UsiTextAlt = textUsiTextAlt.Text; EhrLabCur.UsiCodeSystemNameAlt = textUsiCodeSystemNameAlt.Text; EhrLabCur.UsiTextOriginal = textUsiTextOriginal.Text; EhrLabCur.ObservationDateTimeStart = EhrLab.formatDateToHL7(textObservationDateTimeStart.Text.Trim()); EhrLabCur.ObservationDateTimeEnd = EhrLab.formatDateToHL7(textObservationDateTimeEnd.Text.Trim()); EhrLabCur.SpecimenActionCode = ((HL70065)comboSpecimenActionCode.SelectedIndex - 1); EhrLabCur.ResultDateTime = EhrLab.formatDateToHL7(textResultDateTime.Text.Trim());//upper right hand corner of form. EhrLabCur.ResultStatus = ((HL70123)comboResultStatus.SelectedIndex - 1); //TODO: parent result. /* * EhrLabCur.ParentObservationID= * EhrLabCur.ParentObservationText= * EhrLabCur.ParentObservationCodeSystemName= * EhrLabCur.ParentObservationIDAlt= * EhrLabCur.ParentObservationTextAlt= * EhrLabCur.ParentObservationCodeSystemNameAlt= * EhrLabCur.ParentObservationTextOriginal= * EhrLabCur.ParentObservationSubID= * EhrLabCur.ParentPlacerOrderNum= * EhrLabCur.ParentPlacerOrderNamespace= * EhrLabCur.ParentPlacerOrderUniversalID= * EhrLabCur.ParentPlacerOrderUniversalIDType= * EhrLabCur.ParentFillerOrderNum= * EhrLabCur.ParentFillerOrderNamespace= * EhrLabCur.ParentFillerOrderUniversalID= * EhrLabCur.ParentFillerOrderUniversalIDType= */ EhrLabCur.ListEhrLabResultsHandlingF = checkResultsHandlingF.Checked; EhrLabCur.ListEhrLabResultsHandlingN = checkResultsHandlingN.Checked; //EhrLabCur.TQ1SetId=//TODO:this EhrLabCur.TQ1DateTimeStart = EhrLab.formatDateToHL7(textTQ1Start.Text); EhrLabCur.TQ1DateTimeEnd = EhrLab.formatDateToHL7(textTQ1Stop.Text); EhrLabs.SaveToDB(EhrLabCur); Patient patCur = Patients.GetPat(EhrLabCur.PatNum); for (int i = 0; i < EhrLabCur.ListEhrLabResults.Count; i++) { if (CDSPermissions.GetForUser(Security.CurUser.UserNum).ShowCDS&& CDSPermissions.GetForUser(Security.CurUser.UserNum).LabTestCDS) { FormCDSIntervention FormCDSI = new FormCDSIntervention(); FormCDSI.ListCDSI = EhrTriggers.TriggerMatch(EhrLabCur.ListEhrLabResults[i], patCur); FormCDSI.ShowIfRequired(false); } } DialogResult = DialogResult.OK; }