internal static IDiagnosticResultDto GetDiagnosticResult(string text) { // Process Text. var output = new DiagnosticResultDto { // Load Vehicle Info. VehicleModel = GetFieldValue(text, "Model"), VehicleVin = RemoveWhiteSpaces(GetFieldValue(text, "VIN")), VehicleYear = GetFieldValue(text, "Year"), // Create Collections. TestabilityIssuesList = new List <string>(), Controllers = new List <IDiagnosticControllerDto>() }; // Split Text to lines var controllers = Regex.Split(text.Trim(), @"(.*)[\n\r]*Frozen Values", RegexOptions.CultureInvariant) .Where(s => s.Trim().Length > 25 && s.Trim().Length < 500) .Select(s => s.Trim()).ToList(); foreach (var controllerText in controllers) { // Process Info. output.Controllers.Add(GetController(controllerText)); } return(output); }
private static DiagnosticResultDto MapDiagnosticResult(Dictionary <int, DiagnosticResultDto> resultDictionary, DiagnosticResultDto r, DiagnosticControllerDto c, DiagnosticTroubleCodeDto tc, dynamic ff) { if (!r.ResultId.HasValue) { return(null); } if (!resultDictionary.TryGetValue(r.ResultId.Value, out var result)) { result = r; result.Controllers = new List <IDiagnosticControllerDto>(); resultDictionary.Add(r.ResultId.Value, result); } if (c == null) { return(result); } var controller = result.Controllers.FirstOrDefault(rc => rc.ControllerId == c.ControllerId); if (controller == null) { controller = c; controller.TroubleCodes = new List <IDiagnosticTroubleCodeDto>(); controller.FreezeFrames = new List <IDiagnosticFreezeFrameDto>(); result.Controllers.Add(controller); } if (controller.TroubleCodes.All(ctc => ctc.DiagnosticTroubleCodeId != tc.DiagnosticTroubleCodeId)) { controller.TroubleCodes.Add(tc); } if (string.IsNullOrEmpty(ff?.SensorGroupsJson)) { return(result); } if (controller.FreezeFrames.Any(cff => cff.FreezeFrameDiagnosticTroubleCode == ff.FreezeFrameDiagnosticTroubleCode)) { return(result); } List <DiagnosticFreezeFrameSensorGroupDto> groups = JsonConvert.DeserializeObject <ICollection <DiagnosticFreezeFrameSensorGroupDto> >(ff.SensorGroupsJson); var freezeFrame = new DiagnosticFreezeFrameDto { FreezeFrameDiagnosticTroubleCode = ff.FreezeFrameDiagnosticTroubleCode, FreezeFrameSensorGroups = groups.ToList <IDiagnosticFreezeFrameSensorGroupDto>() }; controller.FreezeFrames.Add(freezeFrame); return(result); }
public async Task <List <DiagnosticResultDto> > GetResult(List <Guid> SymptomIds) { try { using (DHContext db = new DHContext()) { var AllDisease = await db.Diseases.Include(d => d.ICD).Include(d => d.Symptoms).ToListAsync(); List <DiagnosticResultDto> result = new List <DiagnosticResultDto>(); foreach (var disease in AllDisease) { DiagnosticResultDto currnetresult = null; foreach (var diseaseSymptom in disease.Symptoms) { if (SymptomIds.Contains(diseaseSymptom.Id)) { if (currnetresult == null) { currnetresult = new DiagnosticResultDto(); currnetresult.NumberOfCoincidences = 1; var diseaseresult = new DiseaseDto { Id = disease.Id, Description = disease.Description, ICDID = disease.ICDID, ICDName = disease.ICD.Name, Name = disease.Name, SymptomIds = disease.Symptoms.Select(s => s.Id).ToList(), SymptomNames = disease.Symptoms.Select(s => s.Name).ToList() }; currnetresult.Disease = diseaseresult; } else { currnetresult.NumberOfCoincidences++; } } } if (currnetresult != null) { result.Add(currnetresult); } } return(result.OrderByDescending(r => r.NumberOfCoincidences).ToList()); } } catch (Exception exc) { _logger.Error($"Failed get result for diagnostic : {exc}"); throw; } }
internal static IDiagnosticResultDto GetDiagnosticResult(string text) { // Split Text into Lines. var lines = Regex.Split(text.Trim(), @"(\<\/?\w+\>)", RegexOptions.CultureInvariant).Where(s => s.Trim().Length > 0) .Select(s => s.Trim()).ToList(); // Create Result. var output = new DiagnosticResultDto { TestabilityIssuesList = new List <string>(), Controllers = new List <IDiagnosticControllerDto>() }; // Process File Lines. for (var i = 0; i < lines.Count - 1; ++i) { // Check Line. if (CheckLine(lines[i], lines[i + 1])) { continue; } // Load Values. var value = GetValue(lines[i + 1]); switch (lines[i]) { case "<SHOP_NAME>": output.ShopName = value; break; case "<SHOP_ADDRESS>": output.ShopAddress = value; break; case "<SHOP_PHONE>": output.ShopPhone = value; break; case "<SHOP_FAX>": output.ShopFax = value; break; case "<SHOP_EMAIL>": output.ShopEmail = value; break; case "<DATE_TIME>": output.ScanDateTime = DateTime.TryParse(value, out var dt) ? (DateTime?)dt : null; break; case "<MAKE>": output.VehicleMake = value; break; case "<MODEL>": output.VehicleModel = value; break; case "<YEAR>": output.VehicleYear = value; break; case "<VIN>": output.VehicleVin = value; break; case "<RO>": output.CustomerRo = value; break; case "<FIRST_NAME>": output.CustomerFirstName = value; break; case "<LAST_NAME>": output.CustomerLastName = value; break; case "<TESTABILITY_ISSUE>": output.TestabilityIssuesList.Add(value); break; case "<CONTROLLER>": var endIndex = lines.FindIndex(i + 1, e => e.EndsWith("CONTROLLER>")) - 1; output.Controllers.Add(GetController(lines.Skip(i + 1).Take(endIndex - i).ToList())); i = endIndex; break; } } return(output); }
public IDiagnosticResultDto Save(IDiagnosticResultDto update) { try { // Check Update. if (update == null) { throw new NullReferenceException("Update can NOT be NULL."); } // Lookup Vehicle. if (!string.IsNullOrEmpty(update?.VehicleVin)) { var vs = new VehicleService(Settings); vs.GetById(update.VehicleVin); } // Create Trouble Codes. var troubleCodes = new DataTable(); troubleCodes.Columns.Add("ControllerId", typeof(int)); troubleCodes.Columns.Add("ControllerName", typeof(string)); troubleCodes.Columns.Add("TroubleCodeId", typeof(int)); troubleCodes.Columns.Add("TroubleCode", typeof(string)); troubleCodes.Columns.Add("TroubleCodeDescription", typeof(string)); troubleCodes.Columns.Add("TroubleCodeInformation", typeof(string)); // Create Freeze Frames. var freezeFrames = new DataTable(); freezeFrames.Columns.Add("ControllerId", typeof(int)); freezeFrames.Columns.Add("ControllerName", typeof(string)); freezeFrames.Columns.Add("FreezeFrameId", typeof(int)); freezeFrames.Columns.Add("FreezeFrameTroubleCode", typeof(string)); freezeFrames.Columns.Add("SensorGroupsJson", typeof(string)); // Process Controllers. foreach (var c in update?.Controllers ?? new List <IDiagnosticControllerDto>()) { // Load Trouble Codes. foreach (var tc in c.TroubleCodes) { if (!string.IsNullOrEmpty(tc.DiagnosticTroubleCodeDescription)) { troubleCodes.Rows.Add(c.ControllerId, c.ControllerName, tc.DiagnosticTroubleCodeId, tc.DiagnosticTroubleCode, tc.DiagnosticTroubleCodeDescription, JsonConvert.SerializeObject(tc.DiagnosticTroubleCodeInformationList)); } } // Load Freeze Frames. foreach (var ff in c.FreezeFrames) { freezeFrames.Rows.Add(c.ControllerId, c.ControllerName, null, ff.FreezeFrameDiagnosticTroubleCode, JsonConvert.SerializeObject(ff.FreezeFrameSensorGroups)); } } // Create Parameter. var param = new { User.UserGuid, update.DiagnosticTool, update.DiagnosticFileType, update.DiagnosticFileText, update.ResultId, update.RequestId, update.CustomerFirstName, update.CustomerLastName, update.CustomerRo, update.ScanDateTime, update.ShopName, update.ShopAddress, update.ShopEmail, update.ShopFax, update.ShopPhone, update.VehicleVin, update.VehicleMake, update.VehicleModel, update.VehicleYear, TestabilityIssues = JsonConvert.SerializeObject(update.TestabilityIssuesList), DeletedInd = false, TroubleCodes = troubleCodes.AsTableValuedParameter("Diagnostic.udt_ResultTroubleCodes"), FreezeFrames = freezeFrames.AsTableValuedParameter("Diagnostic.udt_ResultFreezeFrames") }; // Execute Update. update.ResultId = Conn.Query <int>("Diagnostic.usp_SaveDiagnosticResult", param, null, true, null, CommandType.StoredProcedure).First(); } catch (Exception e) { Logger.LogException(e, update); } // Update Result. if (update == null) { update = new DiagnosticResultDto(); } update.UpdateResult = update.ResultId > 0 ? new UpdateResultDto(true, "Result Saved.") : new UpdateResultDto(false, "Result Save Failed."); // Return. return(update); }