private static void checkDateInOut(IBackgroundContext context, BillsValidatorDataContext dataContext, BillData bill) { if (context.CancellationPending) return; var invalidUsl = (from u in bill.Reestr.USL where u.Kol_Usl == 1 && u.Date_In != u.Date_Out && !(u.CODE_USL.StartsWith("0100") || u.CODE_USL.StartsWith("1000")) && !(u.IsFullStationar || u.IsDayStationar) select u).ToList(); if(invalidUsl.Any()) { context.ReportError(@"Даты начала и окончания услуги не равны при количестве = 1"); invalidUsl.ForEach(x => context.ReportProgress(@" -> {0}", x)); } }
public static void ValidateBills(IBackgroundContext context, LpuExecParams executorParams) { if (context.CancellationPending) return; context.ProgressSeparator(); context.ReportProgress(@"ПРОВЕРКА СЧЕТОВ"); context.ReportProgress(""); using (var dataContext = new BillsValidatorDataContext()) { var dir = Properties.Settings.Default.DataDir; dataContext.Load(context, dir, dir, dir); if (context.CancellationPending) return; foreach (var bill in dataContext.Bills.TakeWhile(x => !context.CancellationPending)) { validateBill(context, dataContext, bill); } } context.ProgressSeparator('-'); }
private static void checkForDoubleUsl(IBackgroundContext context, BillsValidatorDataContext dataContext, BillData bill) { if (context.CancellationPending) return; var dupGroups = from u in bill.Reestr.USL where !(u.CODE_USL.StartsWith("0090") || u.CODE_USL.StartsWith("1090") || u.CODE_USL.StartsWith("00184")) group u by u.PacientRow.ID_PAC + " " + u.DATE_IN + " " + u.DATE_OUT + " " + u.CODE_USL into g where g.Count() > 1 select g; foreach (var dupGroup in dupGroups) { context.ReportError(@"Дублирование услуг"); foreach (var uslRow in dupGroup) { context.ReportProgress(@" > {0}", uslRow); } } }
private static void checkForCrossPeriods(IBackgroundContext context, BillsValidatorDataContext dataContext, BillData bill) { if (context.CancellationPending) return; var fullStationar = (from u in bill.Reestr.USL where u.IsFullStationar select u).ToList(); foreach (var usl in fullStationar.TakeWhile(x => !context.CancellationPending)) { var stacUsl = usl; var crossUsl = (from c in bill.Reestr.USL where c != stacUsl && c.PacientRow.PersRow == stacUsl.PacientRow.PersRow && (new DateRange(c.Date_In, c.Date_Out)).Intersects(new DateRange(stacUsl.Date_In, stacUsl.Date_Out)) select c).ToList(); crossUsl = crossUsl.Where(x => !x.IsFullStationar).ToList(); if (crossUsl.Count > 0) { context.ReportError(@" Оказание услуг во время нахождения в кругл.стационаре {0}", stacUsl.PacientRow.ToString()); context.ReportProgress(@" Стац. {0}", stacUsl.ToShortString()); crossUsl.ForEach(x => context.ReportProgress(@" -> {0}", x.ToShortString())); } } }
private static void checkForExpertDs(IBackgroundContext context, BillsValidatorDataContext dataContext, BillData bill) { if (context.CancellationPending) return; var fileName = Utils.GetOptionsFileName(@"ExpertDs.txt"); if (!File.Exists(fileName)) { context.ReportError(@"Файл {0} не найден. Проверка экспертных диагнозов не проводится", fileName); return; } var allLines = File.ReadAllLines(fileName); var expertDsAll = getDsList(allLines, 0); var expertUslAll = (from u in bill.Reestr.USL from d in expertDsAll where Regex.IsMatch(u.DS, @"^" + d + @".*$") //&& u.DS != @"R10.4" select u).GroupBy(x => x.DS); foreach (var invGroup in expertUslAll) { context.ReportProgress(@"Диагноз требующий проведения предварительной экспертизы {0}", invGroup.Key); invGroup.ToList().ForEach(x => context.ReportProgress(@" -> {0}", x)); } }
private static void validateRequeredFields(IBackgroundContext context, BillsValidatorDataContext dataContext, BillData bill) { if (context.CancellationPending) return; foreach (var fieldName in new[] { "VERSION", "DATA", "FILENAME", "FILENAME1" }) validateRequeredField(context, dataContext, bill.Persons.ZGLV, fieldName, "Persons.ZGLV"); foreach (var fieldName in new[] { "ID_PAC", "FAM", "IM", "OT", "W", "DR" }) validateRequeredField(context, dataContext, bill.Persons.PERS, fieldName, "Persons.PERS"); foreach (var fieldName in new[] { "FAM_P", "IM_P", "OT_P", "W_P", "DR_P" }) validateRequeredField(context, dataContext, bill.Persons.PERS.Where(x => !x.IsFAM_PNull()), fieldName, "Persons.PERS"); foreach (var fieldName in new[] { "VERSION", "DATA", "FILENAME" }) validateRequeredField(context, dataContext, bill.Reestr.ZGLV, fieldName, "Reestr.ZGLV"); foreach (var fieldName in new[] { "CODE", "CODE_MO", "YEAR", "MONTH", "NSCHET", "DSCHET", "PLAT", "SUMMAV" }) validateRequeredField(context, dataContext, bill.Reestr.SCHET, fieldName, "Reestr.SCHET"); foreach (var fieldName in new[] { "N_ZAP", "PR_NOV" }) validateRequeredField(context, dataContext, bill.Reestr.ZAP, fieldName, "Reestr.ZAP"); foreach (var fieldName in new[] { "ID_PAC", "VPOLIS", "NPOLIS", "NOVOR" }) validateRequeredField(context, dataContext, bill.Reestr.PACIENT, fieldName, "Reestr.PACIENT"); foreach (var fieldName in new[] { "IDCASE", "USL_OK", "VIDPOM", "PODR", "LPU", "PROFIL" , "DET", "NHISTORY", "DATE_1", "DATE_2", "DS1", "RSLT", "ISHOD", "PRVS", "IDDOKT", "IDSP", "SUMV" }) validateRequeredField(context, dataContext, bill.Reestr.SLUCH, fieldName, "Reestr.SLUCH"); foreach (var fieldName in new[] { "IDSERV", "LPU", "PROFIL", "DET", "DATE_IN", "DATE_OUT", "DS", "CODE_USL", "KOL_USL", "TARIF", "SUMV_USL", "PRVS", "CODE_MD" }) validateRequeredField(context, dataContext, bill.Reestr.USL, fieldName, "Reestr.USL"); }
private static void validateRequeredField(IBackgroundContext context, BillsValidatorDataContext dataContext, IEnumerable<DataRow> rows, string colName, string tableName) { if (context.CancellationPending) return; (from c in rows.TakeWhile(x => !context.CancellationPending) where c[colName] == "" select c).GroupBy(x => 1).ToList(). ForEach( group => { context.ReportError(@"Не заполнено обязательное поле {0} в {1}", colName, tableName); group.ToList().ForEach(x => context.ReportProgress(@" {0}", x)); }); }
private static void validatePolicyKind(IBackgroundContext context, BillsValidatorDataContext dataContext, BillData bill) { if (context.CancellationPending) return; var validKinds = new[] {"1", "2", "3"}; var invalidPolicies = (from p in bill.Reestr.PACIENT where !validKinds.Contains(p.VPOLIS) select p).ToList(); if (invalidPolicies.Any()) { context.ReportError(@"Неверный вид полиса"); invalidPolicies.ForEach(x => context.ReportProgress(@" -> {0} {1} вид полиса {2}", x.PersRow.Fio, x.PersRow.DR, x.VPOLIS)); } }
private static void validateFrmr(IBackgroundContext context, BillsValidatorDataContext dataContext, BillData bill) { if(context.CancellationPending) return; validateFrmrSluch(context, bill); validateFrmrUsl(context, bill); }
private static void validateBill(IBackgroundContext context, BillsValidatorDataContext dataContext, BillData bill) { if (context.CancellationPending) return; context.ProgressSeparator(); context.ReportProgress(@"Проверка файла {0}", bill.LFileName); if (!validateBillStructure(context, bill)) return; context.ReportProgress(@"Счет " + bill.Schet.ToString() + " " + bill.Zglv.ToString()); context.ReportProgress(""); validateFrmr(context, dataContext, bill); validatePolicyKind(context, dataContext, bill); checkForCrossPeriods(context, dataContext, bill); validateRequeredFields(context, dataContext, bill); checkForPersonDuplicates(context, dataContext, bill); checkForInvalidPolicies(context, dataContext, bill); if (bill.BillType == BillType.Common) { //checkForInvalidDs(context, dataContext, bill); //checkForExpertDs(context, dataContext, bill); } // checkForDoubleUsl(context, dataContext, bill); checkDateInOut(context, dataContext, bill); }
private static void checkForPersonDuplicates(IBackgroundContext context, BillsValidatorDataContext dataContext, BillData bill) { if (context.CancellationPending) return; var duplicates = new List<PERS_LIST.PERSRow>(); foreach (var currPers in bill.Persons.PERS.TakeWhile(x => !context.CancellationPending)) { var person = currPers; if(!duplicates.Contains(person)) { List<PERS_LIST.PERSRow> persDup; if(person.SmoPacient != null) persDup = (from c in bill.Persons.PERS where c != person && c.SmoPacient == person.SmoPacient select c).ToList(); else persDup = (from c in bill.Persons.PERS where c != person && c.Fio == person.Fio && c.DR == person.DR select c).ToList(); if(persDup.Count > 0) { context.ReportError(" Повторные записи пациента в списке пролеченных {0}", person.ToString()); persDup.ForEach(x => context.ReportProgress(@" -> {0}", x)); duplicates.AddRange(persDup); } } } }
private static void checkForInvalidPolicies(IBackgroundContext context, BillsValidatorDataContext dataContext, BillData bill) { if (context.CancellationPending) return; if (dataContext.SmoPacients.ContainsKey(bill.SmoCode)) { var invPers = (from c in bill.Persons.PERS let pac = (from p in bill.Reestr.PACIENT where p.PersRow == c select p).FirstOrDefault() where c.SmoPacient == null select new {Person = c, Pacient = pac } ); invPers.GroupBy(x => 1).ToList() .ForEach(group => { context.ReportError(@"Пациенты на найдены в БД СМО"); group.ToList().ForEach(x => context.ReportProgress(@" {0}", ((object)x.Pacient ?? x.Person).ToString())); }); } }
private static void checkForInvalidDs(IBackgroundContext context, BillsValidatorDataContext dataContext, BillData bill) { if (context.CancellationPending) return; var fileName = Utils.GetOptionsFileName(@"InvalidDs.txt"); if(!File.Exists(fileName)) { context.ReportError(@"Файл {0} не найден. Проверка диагнозов не проводится", fileName); return; } var allLines = File.ReadAllLines(fileName); var invalidDsAll = getDsList(allLines, 0); var invalidDsChildren = getDsList(allLines, 1); var invalidDsAdult = getDsList(allLines, 2); var invalidUslAll = (from u in bill.Reestr.USL from d in invalidDsAll where Regex.IsMatch(u.DS, @"^" + d + @".*$") select u).GroupBy(x => x.DS); foreach (var invGroup in invalidUslAll) { context.ReportError(@"Неоплачиваемый диагноз {0}", invGroup.Key); invGroup.ToList().ForEach(x => context.ReportProgress(@" -> {0}", x)); } var invalidUslChildren = (from u in bill.Reestr.USL from d in invalidDsChildren where Regex.IsMatch(u.DS, @"^" + d + @".*$") && u.DET == "1" select u).GroupBy(x => x.DS); foreach (var invGroup in invalidUslChildren) { context.ReportError(@"Неоплачиваемый диагноз для детей {0}", invGroup.Key); invGroup.ToList().ForEach(x => context.ReportProgress(@" -> {0}", x)); } var invalidUslAdult = (from u in bill.Reestr.USL from d in invalidDsAdult where Regex.IsMatch(u.DS, @"^" + d + @".*$") && u.DET == "1" select u).GroupBy(x => x.DS); foreach (var invGroup in invalidUslAdult) { context.ReportError(@"Неоплачиваемый диагноз для взрослых {0}", invGroup.Key); invGroup.ToList().ForEach(x => context.ReportProgress(@" -> {0}", x)); } }