public Stream InterpretORU(Stream ORUMessageStream) { try { h.WriteToLog("In InterpretORU"); string ORUMessageString = StreamToString(ORUMessageStream); // get list of lab results List <LookupData> dataList = ParseORU(ORUMessageString); foreach (var data in dataList) { h.WriteToLog(data.LabName + " " + data.ResultName); } h.WriteToLog("Past ParseORU"); // interpret the list ReturnDataList returnDataList = InterpretData(dataList); h.WriteToLog("Past InterpretData"); // send the data back foreach (var data in returnDataList.DataList) { h.WriteToLog(data.CommonOrderName + " " + data.CommonResultName + " " + data.IsPositive.ToString()); } string json = JsonConvert.SerializeObject(returnDataList, Newtonsoft.Json.Formatting.Indented); h.WriteToLog("Past SerializeObject"); //return StringToStream("ok"); return(StringToStream(json)); return(StringToStream("test")); } catch (Exception e) { h.WriteToLog("InterpretORU error - " + e.Message); return(StringToStream(e.Message)); } }
private ReturnDataList InterpretData(List <LookupData> dataList) { ReturnDataList returnList = new ReturnDataList(); foreach (var data in dataList) { ReturnData returnData = new ReturnData(); returnData.OrderID = data.OrderID; returnData.OrderName = data.LabName; returnData.ResultName = data.ResultName; // call the database table using (var db = new InterpretationDBContext()) { var query = from l in db.LabLookups where l.FacilityName == data.FacilityName && l.LabCode == data.LabCode && l.ResultCode == data.ResultCode && l.ResultValue == data.ResultValue select l; if (query.Count() == 1) { if (query.First().CanSkip == null || query.First().CanSkip == true) { continue; } //var item = query.ElementAt(0); if (query.First().IsPositive != null) { returnData.IsPositive = query.First().IsPositive.Value; } else // null result, neither positive or negative { SendToPhysicianConsole(data); } returnData.CommonOrderName = query.First().CommonLabName; returnData.CommonResultName = query.First().CommonResultName; returnList.DataList.Add(returnData); //foreach (var item in query) //{ // returnData.IsPositive = item.Value; // Console.WriteLine(item.ToString()); //} } else // either 0 or many rows found { SendToPhysicianConsole(data); } } } return(returnList); }