private void CreatePidSegment() { var pidSegment = _oruR01Message.GetRESPONSE().PATIENT.PID; var patientName = pidSegment.GetPatientName(0); patientName.FamilyName.Value = "Mouse"; patientName.GivenName.Value = "Mickey"; pidSegment.SetIDPatientID.Value = "378785433211"; var patientAddress = pidSegment.GetPatientAddress(0); patientAddress.StreetAddress.Value = "123 Main Street"; patientAddress.City.Value = "Lake Buena Vista"; patientAddress.StateOrProvince.Value = "FL"; patientAddress.Country.Value = "USA"; }
public void WhenSegmentParsedAndEscaped_SegmentValueIsEncoded() { // Arrange var oruR01 = new ORU_R01(); var ft = new FT(oruR01); oruR01.GetRESPONSE().GetORDER_OBSERVATION().GetOBSERVATION().OBX.ValueType.Value = "FT"; oruR01.GetRESPONSE().GetORDER_OBSERVATION().GetOBSERVATION().OBX.GetObservationValue(0).Data = ft; ft.Value = "H \\H\\ N \\N\\ "; // Act / Assert Assert.AreEqual("H \\H\\ N \\N\\ ", ft.Value); Assert.AreEqual("H \\H\\ N \\N\\ ", PipeParser.Encode(ft, encodingCharacters)); ft.Value = "H \\C00FF\\ N"; Assert.AreEqual("H \\C00FF\\ N", ft.Value); Assert.AreEqual("H \\C00FF\\ N", PipeParser.Encode(ft, encodingCharacters)); }
private static ED ExtractEncapsulatedPdfDataInBase64Format(ORU_R01 oruR01Message) { //start retrieving the OBX segment data to get at the PDF report content LogToDebugConsole("Extracting message data from parsed message.."); var ourOrderObservation = oruR01Message.GetRESPONSE().GetORDER_OBSERVATION(); var observation = ourOrderObservation.GetOBSERVATION(0); var obxSegment = observation.OBX; var encapsulatedPdfDataInBase64Format = obxSegment.GetObservationValue(0).Data as ED; return(encapsulatedPdfDataInBase64Format); }
protected void linkBtnSave_OnClick(object sender, EventArgs e) { SqlCommand cmdSave = new SqlCommand(); SqlCommand cmdLoad = new SqlCommand(); DataSet dsPathologyID; int newPathologyID = 0; try { gClass.MakeStoreProcedureName(ref cmdSave, "sp_PatientPathology_UpdatePathology", true); //save pathology id cmdSave.Parameters.Add("@OrganizationCode", SqlDbType.Int).Value = Convert.ToInt32(gClass.OrganizationCode); cmdSave.Parameters.Add("@PatientID", SqlDbType.Int).Value = Convert.ToInt32(Request.Cookies["PatientID"].Value); cmdSave.Parameters.Add("@PathologyBaseline", SqlDbType.VarChar).Value = "progress"; cmdSave.Parameters.Add("@DeletedByUser", SqlDbType.VarChar, 50).Value = Context.Request.Cookies["Logon_UserName"].Value; cmdSave.Parameters.Add("@DateDeleted", SqlDbType.DateTime).Value = Convert.ToDateTime(txtHCurrentDate.Value); gClass.ExecuteDMLCommand(cmdSave); gClass.SaveUserLogFile(Context.Request.Cookies["UserPracticeCode"].Value, Context.Request.Cookies["Logon_UserName"].Value, Context.Request.Url.Host, "EMR Form", 2, "Save Pathology", "PID:", Context.Request.Cookies["PatientID"].Value); gClass.MakeStoreProcedureName(ref cmdLoad, "sp_PatientPathology_LastPathologyID", true); cmdLoad.Parameters.Add("@OrganizationCode", SqlDbType.Int).Value = Convert.ToInt32(gClass.OrganizationCode); cmdLoad.Parameters.Add("@PatientID", SqlDbType.Int).Value = Convert.ToInt32(Request.Cookies["PatientID"].Value); dsPathologyID = gClass.FetchData(cmdLoad, "tblPatientPathology"); Int32.TryParse(dsPathologyID.Tables[0].Rows[0]["PathologyID"].ToString(), out newPathologyID); } catch (Exception err) { gClass.AddErrorLogData(Context.Request.Cookies["UserPracticeCode"].Value, Context.Request.Url.Host, Context.Request.Cookies["Logon_UserName"].Value, "EMR PID : " + Context.Request.Cookies["PatientID"].Value, "Save Pathology", err.ToString()); } if (newPathologyID > 0) { //save pathology data try { string strDocumentName = ""; string strFilePath = GetFilePath(txtFile.PostedFile.FileName); if (strFilePath.Trim() != "") { if (System.IO.File.Exists(strFilePath)) { System.IO.File.Delete(strFilePath); } strDocumentName = txtFile.PostedFile.FileName; txtFile.PostedFile.SaveAs(strFilePath); StreamReader streamReader = new StreamReader(strFilePath); string message = streamReader.ReadToEnd(); streamReader.Close(); PipeParser parser = new PipeParser(); IMessage m = parser.Parse(message); ORU_R01 oruR01 = m as ORU_R01; oruR01 = oruR01; string testID = ""; string testName = ""; string testValue = ""; string testUnit = ""; string testRange = ""; string testStatus = ""; string testDate = ""; string pathologyDate = ""; string year = ""; string month = ""; string date = ""; gClass.MakeStoreProcedureName(ref cmdSave, "sp_PatientPathology_InsertPathologyData", true); cmdSave.Parameters.Clear(); cmdSave.Parameters.Add("@OrganizationCode", SqlDbType.Int).Value = Convert.ToInt32(gClass.OrganizationCode); cmdSave.Parameters.Add("@PatientID", SqlDbType.Int).Value = Convert.ToInt32(Request.Cookies["PatientID"].Value); cmdSave.Parameters.Add("@PathologyID", SqlDbType.Int).Value = newPathologyID; cmdSave.Parameters.Add("@PathologyDataDate", SqlDbType.DateTime); cmdSave.Parameters.Add("@SectionID", SqlDbType.Int); cmdSave.Parameters.Add("@TestID", SqlDbType.VarChar); cmdSave.Parameters.Add("@TestName", SqlDbType.VarChar); cmdSave.Parameters.Add("@TestValue", SqlDbType.VarChar); cmdSave.Parameters.Add("@TestUnit", SqlDbType.VarChar); cmdSave.Parameters.Add("@TestRange", SqlDbType.VarChar); cmdSave.Parameters.Add("@TestStatus", SqlDbType.VarChar); //gClass.TruncateDate(dvPatient[0]["BirthDate"].ToString().Trim(), Request.Cookies["CultureInfo"].Value, 1); for (int i = 0; i < oruR01.RESPONSERepetitionsUsed; i++) { for (int j = 0; j < oruR01.GetRESPONSE(i).ORDER_OBSERVATIONRepetitionsUsed; j++) { testDate = oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).OBR.RequestedDateTime.TimeOfAnEvent.Value.ToString(); year = testDate.Substring(0, 4); month = testDate.Substring(4, 2); date = testDate.Substring(6, 2); pathologyDate = date + "-" + month + "-" + year; cmdSave.Parameters["@PathologyDataDate"].Value = gClass.TruncateDate(pathologyDate, Request.Cookies["CultureInfo"].Value, 1); for (int k = 0; k < oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).OBSERVATIONRepetitionsUsed; k++) { testID = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).GetOBSERVATION(k).OBX.ObservationIdentifier.Identifier.Value); testName = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).GetOBSERVATION(k).OBX.ObservationIdentifier.Text.Value); testValue = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).GetOBSERVATION(k).OBX.GetObservationValue(0).Data); testUnit = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).GetOBSERVATION(k).OBX.Units.Identifier.Value); testRange = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).GetOBSERVATION(k).OBX.ReferencesRange.Value); testStatus = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).GetOBSERVATION(k).OBX.AbnormalFlagsRepetitionsUsed); cmdSave.Parameters["@SectionID"].Value = i; cmdSave.Parameters["@TestID"].Value = testID; cmdSave.Parameters["@TestName"].Value = testName; cmdSave.Parameters["@TestValue"].Value = testValue; cmdSave.Parameters["@TestUnit"].Value = testUnit; cmdSave.Parameters["@TestRange"].Value = testRange; cmdSave.Parameters["@TestStatus"].Value = testStatus; gClass.ExecuteDMLCommand(cmdSave); gClass.SaveUserLogFile(Context.Request.Cookies["UserPracticeCode"].Value, Context.Request.Cookies["Logon_UserName"].Value, Context.Request.Url.Host, "EMR Form", 2, "Save Pathology Data", "PID:", Context.Request.Cookies["PatientID"].Value); } } } if (pathologyDate != "") { gClass.MakeStoreProcedureName(ref cmdSave, "sp_PatientPathology_UpdatePathology", true); cmdSave.Parameters.Clear(); //save pathology id cmdSave.Parameters.Add("@OrganizationCode", SqlDbType.Int).Value = Convert.ToInt32(gClass.OrganizationCode); cmdSave.Parameters.Add("@PatientID", SqlDbType.Int).Value = Convert.ToInt32(Request.Cookies["PatientID"].Value); cmdSave.Parameters.Add("@PathologyID", SqlDbType.Int).Value = Convert.ToInt32(newPathologyID); cmdSave.Parameters.Add("@PathologyDate", SqlDbType.DateTime).Value = gClass.TruncateDate(pathologyDate, Request.Cookies["CultureInfo"].Value, 1); gClass.ExecuteDMLCommand(cmdSave); } } } catch (Exception err) { gClass.AddErrorLogData(Context.Request.Cookies["UserPracticeCode"].Value, Context.Request.Url.Host, Context.Request.Cookies["Logon_UserName"].Value, "PID : " + Context.Request.Cookies["PatientID"].Value, "Save Pathology Data", err.ToString()); } Response.Redirect("~/Forms/Labs/LabForm.aspx?PatID=" + newPathologyID, false); } }
protected void ImportPathology(object sender, EventArgs e) { try { String[] FileControl = new String[] { "textFile1", "textFile2", "textFile3", "textFile4", "textFile5", "textFile6", "textFile7", "textFile8", "textFile9", "textFile10" }; string filePath = ""; int patientFound = 0; int patientNotFound = 0; int fileCount = 0; int fileSuccessCount = 0; int fileFailCount = 0; Boolean failImport = false; string fileFailList = ""; string patientSuccessList = ""; string patientFailList = ""; HtmlInputFile tempControlFile = new HtmlInputFile(); for (int Xh = 0; Xh < FileControl.Length; Xh++) { tempControlFile = (HtmlInputFile)FindControlRecursive(this.Page, FileControl[Xh]); filePath = GetFilePath(tempControlFile.PostedFile.FileName); if (tempControlFile.PostedFile.FileName != "") { fileCount++; if (Path.GetExtension(tempControlFile.PostedFile.FileName).ToUpper() == ".ORU") { fileSuccessCount++; if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } tempControlFile.PostedFile.SaveAs(filePath); StreamReader streamReader = new StreamReader(filePath); string message = streamReader.ReadToEnd(); streamReader.Close(); PipeParser parser = new PipeParser(); IMessage m = parser.Parse(message); ORU_R01 oruR01 = m as ORU_R01; oruR01 = oruR01; string testID = ""; string testName = ""; string testValue = ""; string testUnit = ""; string testRange = ""; string testStatus = ""; string testDate = ""; string pathologyDate = ""; string year = ""; string month = ""; string date = ""; string birthyear = ""; string birthmonth = ""; string birthdate = ""; string formattedBirthdate = ""; string unformattedBirthdate = ""; string firstname = ""; string surname = ""; string refFirstname = ""; string refSurname = ""; string refDr = ""; int matchingPatientID = 0; int pathologyID = 0; SqlCommand cmdSave = new SqlCommand(); gClass.MakeStoreProcedureName(ref cmdSave, "sp_PatientPathology_InsertPathologyData", true); cmdSave.Parameters.Add("@OrganizationCode", SqlDbType.Int).Value = Convert.ToInt32(gClass.OrganizationCode); cmdSave.Parameters.Add("@PatientID", SqlDbType.Int); cmdSave.Parameters.Add("@PathologyDataDate", SqlDbType.DateTime); cmdSave.Parameters.Add("@PathologyID", SqlDbType.Int); cmdSave.Parameters.Add("@SectionID", SqlDbType.Int); cmdSave.Parameters.Add("@TestID", SqlDbType.VarChar); cmdSave.Parameters.Add("@TestName", SqlDbType.VarChar); cmdSave.Parameters.Add("@TestValue", SqlDbType.VarChar); cmdSave.Parameters.Add("@TestUnit", SqlDbType.VarChar); cmdSave.Parameters.Add("@TestRange", SqlDbType.VarChar); cmdSave.Parameters.Add("@TestStatus", SqlDbType.VarChar); //gClass.TruncateDate(dvPatient[0]["BirthDate"].ToString().Trim(), Request.Cookies["CultureInfo"].Value, 1); for (int i = 0; i < oruR01.RESPONSERepetitionsUsed; i++) { failImport = false; for (int j = 0; j < oruR01.GetRESPONSE(i).ORDER_OBSERVATIONRepetitionsUsed; j++) { testDate = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).OBR.RequestedDateTime.TimeOfAnEvent.Value.ToString()); unformattedBirthdate = CheckNull(oruR01.GetRESPONSE(i).PATIENT.PID.DateOfBirth.TimeOfAnEvent.Value); firstname = CheckNull(oruR01.GetRESPONSE(i).PATIENT.PID.PatientName.GivenName.Value); surname = CheckNull(oruR01.GetRESPONSE(i).PATIENT.PID.PatientName.FamilyName.Value); formattedBirthdate = ""; refFirstname = CheckNull(oruR01.GetRESPONSE(i).PATIENT.VISIT.PV1.ReferringDoctor.GivenName.Value.ToString()); refSurname = CheckNull(oruR01.GetRESPONSE(i).PATIENT.VISIT.PV1.ReferringDoctor.FamilyName.Value.ToString()); refDr = refFirstname + " " + refSurname; if (surname != "" && firstname != "" && unformattedBirthdate != "") { birthyear = unformattedBirthdate.Substring(0, 4); birthmonth = unformattedBirthdate.Substring(4, 2); birthdate = unformattedBirthdate.Substring(6, 2); formattedBirthdate = birthdate + "-" + birthmonth + "-" + birthyear; SqlCommand cmdSelect = new SqlCommand(); DataSet dsPatient = new DataSet(); gClass.MakeStoreProcedureName(ref cmdSelect, "sp_PatientData_LoadDataByNameDOB", true); cmdSelect.Parameters.Add("@OrganizationCode", System.Data.SqlDbType.Int).Value = Convert.ToInt32(gClass.OrganizationCode); cmdSelect.Parameters.Add("@Surname", System.Data.SqlDbType.VarChar, 40).Value = surname; cmdSelect.Parameters.Add("@Firstname", System.Data.SqlDbType.VarChar, 30).Value = firstname; cmdSelect.Parameters.Add("@Birthdate", System.Data.SqlDbType.DateTime).Value = Convert.ToDateTime(formattedBirthdate); dsPatient = gClass.FetchData(cmdSelect, "tblPatient"); if (dsPatient.Tables[0].Rows.Count > 0) { //insert pathology data record as it is matchingPatientID = Convert.ToInt32(dsPatient.Tables[0].Rows[0]["Patient ID"]); year = testDate.Substring(0, 4); month = testDate.Substring(4, 2); date = testDate.Substring(6, 2); pathologyDate = date + "-" + month + "-" + year; cmdSave.Parameters["@PathologyDataDate"].Value = gClass.TruncateDate(pathologyDate, Request.Cookies["CultureInfo"].Value, 1); //check for pathology record //when saving, check if the record with date is available //if not, add a new one and select the pathology id //if yes, return the pathology id SqlCommand cmdSavePathology = new SqlCommand(); DataSet dsPathology = new DataSet(); gClass.MakeStoreProcedureName(ref cmdSavePathology, "sp_PatientPathology_InsertPathology", true); cmdSavePathology.Parameters.Add("@OrganizationCode", SqlDbType.Int).Value = Convert.ToInt32(gClass.OrganizationCode); cmdSavePathology.Parameters.Add("@PatientID", SqlDbType.Int).Value = Convert.ToInt32(matchingPatientID); cmdSavePathology.Parameters.Add("@PathologyDate", SqlDbType.DateTime).Value = gClass.TruncateDate(pathologyDate, Request.Cookies["CultureInfo"].Value, 1); cmdSavePathology.Parameters.Add("@RefDr", SqlDbType.VarChar, 100).Value = refDr; try { dsPathology = gClass.FetchData(cmdSavePathology, "tblPathology"); gClass.SaveUserLogFile(Context.Request.Cookies["UserPracticeCode"].Value, Context.Request.Cookies["Logon_UserName"].Value, Context.Request.Url.Host, "Import Pathology", 2, "Save Pathology", "PID:", matchingPatientID.ToString()); } catch (Exception err) { gClass.AddErrorLogData(Context.Request.Cookies["UserPracticeCode"].Value, Context.Request.Url.Host, Context.Request.Cookies["Logon_UserName"].Value, "PID : " + Context.Request.Cookies["PatientID"].Value, "Save Pathology", err.ToString()); } if (dsPathology.Tables[0].Rows.Count > 0) { pathologyID = Convert.ToInt32(dsPathology.Tables[0].Rows[0]["PathologyID"]); for (int k = 0; k < oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).OBSERVATIONRepetitionsUsed; k++) { testID = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).GetOBSERVATION(k).OBX.ObservationIdentifier.Identifier.Value); testName = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).GetOBSERVATION(k).OBX.ObservationIdentifier.Text.Value); testValue = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).GetOBSERVATION(k).OBX.GetObservationValue(0).Data); testUnit = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).GetOBSERVATION(k).OBX.Units.Identifier.Value); testRange = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).GetOBSERVATION(k).OBX.ReferencesRange.Value); testStatus = CheckNull(oruR01.GetRESPONSE(i).GetORDER_OBSERVATION(j).GetOBSERVATION(k).OBX.AbnormalFlagsRepetitionsUsed); cmdSave.Parameters["@PatientID"].Value = matchingPatientID; cmdSave.Parameters["@PathologyID"].Value = pathologyID; cmdSave.Parameters["@SectionID"].Value = i; cmdSave.Parameters["@TestID"].Value = testID; cmdSave.Parameters["@TestName"].Value = testName; cmdSave.Parameters["@TestValue"].Value = testValue; cmdSave.Parameters["@TestUnit"].Value = testUnit; cmdSave.Parameters["@TestRange"].Value = testRange; cmdSave.Parameters["@TestStatus"].Value = testStatus; try { gClass.ExecuteDMLCommand(cmdSave); gClass.SaveUserLogFile(Context.Request.Cookies["UserPracticeCode"].Value, Context.Request.Cookies["Logon_UserName"].Value, Context.Request.Url.Host, "Import Pathology", 2, "Save Pathology Data", "PID:", matchingPatientID.ToString()); } catch (Exception err) { // failed to insert test for which patient in which file name gClass.AddErrorLogData(Context.Request.Cookies["UserPracticeCode"].Value, Context.Request.Url.Host, Context.Request.Cookies["Logon_UserName"].Value, "PID : " + matchingPatientID.ToString(), "Save Pathology Data", err.ToString()); } } } } else { //patient is not exist in the db in which file name patientFailList += "\n-" + firstname + " " + surname + ", " + formattedBirthdate + " (" + tempControlFile.PostedFile.FileName + "): This patient is not exist in our database"; patientNotFound++; failImport = true; break; } } else { //check firstname, surname, dob () should not be empty, in which file name patientFailList += "\n-" + firstname + " " + surname + ", " + formattedBirthdate + "(" + tempControlFile.PostedFile.FileName + "): The data on the file is incomplete. Please check on the firstname, surname and date of birth"; patientNotFound++; failImport = true; break; } } if (failImport == false) { //add to patient success patientSuccessList += "\n-" + firstname + " " + surname + ", " + formattedBirthdate; patientFound++; } } } else { fileFailList += "\n-" + tempControlFile.PostedFile.FileName; fileFailCount++; } } } string validFileNote = fileSuccessCount > 0?"\nValid files: " + fileSuccessCount:""; string invalidFileNote = fileFailCount > 0?"\n\n\nInvalid Files:" + fileFailCount + fileFailList:""; string patientMatchNote = patientFound > 0?"\nMatching records: " + patientFound + patientSuccessList:""; string patientNotMatchNote = patientNotFound > 0?"\n\nNot matching records: " + patientNotFound + patientFailList:""; txtNotes.Value = "RESULT:\n\nTotal files: " + fileCount + validFileNote + patientMatchNote + patientNotMatchNote + invalidFileNote; } catch (Exception err) { gClass.AddErrorLogData(Context.Request.Cookies["UserPracticeCode"].Value, Context.Request.Url.Host, Context.Request.Cookies["Logon_UserName"].Value, "Import Pathology", "Import Pathology", err.ToString()); } LoadLabHistory(); }