/// <summary> /// Parse Json Fileds in class format /// </summary> public static JsonHL7Fields ParseJsonHL7Fields(string jsonData) { // Get Object data from input file JObject jsonObj = JObject.Parse(jsonData); var dKeyVal = new Dictionary <string, string>(); foreach (JObject prop in jsonObj["objects"]) { dKeyVal.Add(Convert.ToString(prop["name"]), Convert.ToString(prop["value"])); } var oRet = new JsonHL7Fields(); oRet.LabName = dKeyVal["LabName"]; oRet.PatientLastName = dKeyVal["PatientLastName"]; oRet.PatientFirstName = dKeyVal["PatientFirstName"]; oRet.PatientSSN = dKeyVal["PatientSSN"]; oRet.PatientDOB = dKeyVal["PatientDOB"]; oRet.PatientPhoneHome = dKeyVal["PatientHomePhone"]; oRet.PatientPhoneWork = dKeyVal["PatientWorkPhone"]; oRet.PatientAddress = dKeyVal["PatientAddress"]; oRet.PatientChartNo = dKeyVal["PatientChartNo"]; string patGenderMaleSelectedVal = dKeyVal["PatientGenderMale"]; string patGenderFemaleSelectedVal = dKeyVal["PatientGenderFemale"]; if (!string.IsNullOrEmpty(patGenderMaleSelectedVal)) { oRet.PatientGender = "M"; } else if (!string.IsNullOrEmpty(patGenderFemaleSelectedVal)) { oRet.PatientGender = "F"; } oRet.PhysicianName = dKeyVal["PhysicianName"]; oRet.PhysicianAccountNo = dKeyVal["PhysicianAccountName"]; oRet.PhysicianNpi = dKeyVal["PhysicianNPI"]; oRet.InsuranceName = dKeyVal["InsuranceName"]; oRet.InsurancePolicy = dKeyVal["InsurancePolicy"]; oRet.InsuranceGroup = dKeyVal["InsuranceGroup"]; oRet.InsuredName = dKeyVal["InsuredName"]; oRet.InsuredSSN = dKeyVal["InsuredSSN"]; oRet.InsuredDob = dKeyVal["InsuredDOB"]; string relToPatIsSelf = dKeyVal["RelationToPatientIsSelf"]; string relToPatIsSpouse = dKeyVal["RelationToPatientIsSpouse"]; string relToPatIsDependent = dKeyVal["RelationToPatientIsDependent"]; if (!string.IsNullOrEmpty(relToPatIsSelf)) { oRet.RelationToPatient = "Self"; } else if (!string.IsNullOrEmpty(relToPatIsSpouse)) { oRet.RelationToPatient = "Spouse"; } else if (!string.IsNullOrEmpty(relToPatIsDependent)) { oRet.RelationToPatient = "Dependent"; } // Add Collection Date/Time string colDate = dKeyVal["CollectionDate"]; string colTime = dKeyVal["CollectionTime"]; string colTimeIsAm = dKeyVal["CollectionTimeIsAM"]; string colTimeIsPm = dKeyVal["CollectionTimeIsPM"]; string colTimeAmPm = ""; if (!string.IsNullOrEmpty(colTimeIsAm)) { colTimeAmPm = "AM"; } else if (!string.IsNullOrEmpty(colTimeIsPm)) { colTimeAmPm = "PM"; } oRet.CollectionDateTime = $"{colDate} {colTime} {colTimeAmPm}"; // Add ICD Codes string IcdCodes = dKeyVal["ICD10DxCodes"]; if (!string.IsNullOrEmpty(IcdCodes)) { var arrIcdCodes = IcdCodes.Split(','); foreach (var itmIcd in arrIcdCodes) { oRet.Icd10Codes.Add(itmIcd.Trim()); } } // Add Question/Answers string Ques_ClinicalHistoryIsRoutinePap = string.IsNullOrEmpty(dKeyVal["ClinicalHistoryIsRoutinePap"]) ? "No" : "Yes"; string Ques_ClinicalHistoryIsAbnormalBleeding = string.IsNullOrEmpty(dKeyVal["ClinicalHistoryIsAbnormalBleeding"]) ? "No" : "Yes"; oRet.QuestionAnswer.Add(new KeyValuePair <string, string>("Is Routine PAP?", Ques_ClinicalHistoryIsRoutinePap)); oRet.QuestionAnswer.Add(new KeyValuePair <string, string>("Is Abnormal Bleeding?", Ques_ClinicalHistoryIsAbnormalBleeding)); return(oRet); }
/// <summary> /// Get HL7 format representation from input model /// </summary> public static string GetHL7Format(JsonHL7Fields inpModel) { // https://github.com/Efferent-Health/HL7-dotnetcore // http://www.j4jayant.com/2013/05/hl7-parsing-in-csharp.html Message oHl7Message = new Message(); // Add MSH Segment Segment mshSegment = new Segment("MSH", new HL7Encoding()); mshSegment.AddNewField("SendingApp", 3); mshSegment.AddNewField(inpModel.LabName ?? "", 4); mshSegment.AddNewField(DateTime.Now.ToString("yyyymmddhhMMss"), 7); mshSegment.AddNewField("ORM", 9); // Message type mshSegment.AddNewField("2.3", 12); // Message version oHl7Message.AddNewSegment(mshSegment); // Add PID Segment Segment pidSegment = new Segment("PID", new HL7Encoding()); pidSegment.AddNewField("1", 1); pidSegment.AddNewField(inpModel.PatientChartNo ?? "", 2); // Patient ID pidSegment.AddNewField(inpModel.PatientChartNo ?? "", 4); // Alternate Patient ID pidSegment.AddNewField($"{inpModel.PatientLastName ?? ""}^{inpModel.PatientFirstName ?? ""}", 5); // Patient Name pidSegment.AddNewField(inpModel.PatientDOB ?? "", 7); // Patient DOB pidSegment.AddNewField(inpModel.PatientGender ?? "", 8); // Patient Gender pidSegment.AddNewField(inpModel.PatientAddress ?? "", 11); // Patient Address pidSegment.AddNewField(inpModel.PatientPhoneHome ?? "", 13); // Patient Home Phone number pidSegment.AddNewField(inpModel.PatientSSN ?? "", 19); // Patient SSN Number oHl7Message.AddNewSegment(pidSegment); // Add PV1 Segment Segment pv1Segment = new Segment("PV1", new HL7Encoding()); pv1Segment.AddNewField($"{inpModel.PhysicianNpi ?? ""}^{inpModel.PhysicianName}", 7); // Physician information oHl7Message.AddNewSegment(pv1Segment); // Add IN1 Segment Segment in1Segment = new Segment("IN1", new HL7Encoding()); in1Segment.AddNewField("1", 1); in1Segment.AddNewField(inpModel.InsuranceName ?? "", 4); // Insurance Name in1Segment.AddNewField(inpModel.InsuranceGroup ?? "", 8); // Insurance Group Name in1Segment.AddNewField(inpModel.InsuredName ?? "", 16); // Insured Name in1Segment.AddNewField(inpModel.RelationToPatient ?? "", 17); // Insured Relatino in1Segment.AddNewField(inpModel.InsuredDob ?? "", 18); // Insured Date of Birth in1Segment.AddNewField(inpModel.InsurancePolicy ?? "", 36); // Insurance Policy Number oHl7Message.AddNewSegment(in1Segment); // Add ORC Segment Segment orcSegment = new Segment("ORC", new HL7Encoding()); orcSegment.AddNewField("NW", 1); // New Order orcSegment.AddNewField(inpModel.CollectionDateTime ?? "", 9); // Date/Time of Transaction orcSegment.AddNewField($"{inpModel.PhysicianNpi ?? ""}^{inpModel.PhysicianName ?? ""}", 12); // Ordering Provider oHl7Message.AddNewSegment(orcSegment); // Add OBR Segment Segment obrSegment = new Segment("OBR", new HL7Encoding()); obrSegment.AddNewField(inpModel.CollectionDateTime ?? "", 7); // Date/Time of Transaction obrSegment.AddNewField($"{inpModel.PhysicianNpi ?? ""}^{inpModel.PhysicianName ?? ""}", 16); // Ordering Provider oHl7Message.AddNewSegment(obrSegment); // Add Diagnosis for (int i = 0; i < inpModel.Icd10Codes.Count; i++) { Segment dg1Segment = new Segment("DG1", new HL7Encoding()); dg1Segment.AddNewField((i + 1).ToString(), 1); dg1Segment.AddNewField("I10", 2); // Icd Type dg1Segment.AddNewField(inpModel.Icd10Codes[i], 3); // Icd Code oHl7Message.AddNewSegment(dg1Segment); } // Add OBX for (int i = 0; i < inpModel.QuestionAnswer.Count; i++) { Segment obxSegment = new Segment("OBX", new HL7Encoding()); obxSegment.AddNewField((i + 1).ToString(), 1); obxSegment.AddNewField("ST", 2); // Value Type obxSegment.AddNewField(inpModel.QuestionAnswer[i].Key, 3); // Question obxSegment.AddNewField(inpModel.QuestionAnswer[i].Value, 5); // Answer oHl7Message.AddNewSegment(obxSegment); } string oRetMessage = oHl7Message.SerializeMessage(false); return oRetMessage; }