private static Dictionary <string, ItemMESUsageTreatment> ParseMESUsageDataTableToTreatments(DataTable dataTable) { Dictionary <string, ItemMESUsageTreatment> treatments = new Dictionary <string, ItemMESUsageTreatment>(); foreach (DataRow row in dataTable.Rows) { try { string treatcode = row["TREATCODE"].ToString(); string mid = row["MID"].ToString(); string listMES = row["LISTMES"].ToString(); string listReferrals = row["LISTREFERRALS"].ToString(); string listAllReferrals = row["LISTALLREFERRALS"].ToString(); string[] arrayMES = new string[0]; string[] arrayReferrals = new string[0]; string[] arrayAllReferrals = new string[0]; if (!string.IsNullOrEmpty(listMES)) { arrayMES = listMES.Split(';'); } if (!string.IsNullOrEmpty(listReferrals)) { arrayReferrals = listReferrals.Split(';'); } if (!string.IsNullOrEmpty(listAllReferrals)) { arrayAllReferrals = listAllReferrals.Split(';'); } if (treatments.ContainsKey(treatcode)) { foreach (KeyValuePair <string, int> pair in ParseMes(arrayMES)) { if (!treatments[treatcode].DictMES.ContainsKey(pair.Key)) { treatments[treatcode].DictMES.Add(pair.Key, pair.Value); } } if (string.IsNullOrEmpty(mid)) { treatments[treatcode].ListReferralsFromDoc.AddRange(arrayReferrals); } else { treatments[treatcode].ListReferralsFromMes.AddRange(arrayReferrals); } } else { ItemMESUsageTreatment treatment = new ItemMESUsageTreatment() { TREATDATE = row["TREATDATE"].ToString(), CLIENTNAME = row["CLIENTNAME"].ToString(), HISTNUM = row["HISTNUM"].ToString(), DOCNAME = row["DOCNAME"].ToString(), FILIAL = row["FILIAL"].ToString(), DEPNAME = row["DEPNAME"].ToString(), MKBCODE = row["MKBCODE"].ToString(), AGE = row["AGE"].ToString(), AGNAME = row["AGNAME"].ToString(), AGNUM = row["AGNUM"].ToString(), SERVICE_TYPE = row["LISTALLSERVICES"].ToString().ToUpper().Contains("ПЕРВИЧНЫЙ") ? "Первичный" : "Повторный", PAYMENT_TYPE = "ДМС", PERIOD = row["PERIOD"].ToString() }; if (!string.IsNullOrEmpty(row["GRNAME"].ToString())) { if (row["NOGP"].ToString().Equals("1") && row["NODMS"].ToString().Equals("1")) { treatment.PAYMENT_TYPE = "Нал"; } else { continue; } } if (string.IsNullOrEmpty(mid)) { treatment.ListReferralsFromDoc.AddRange(arrayReferrals); } else { treatment.ListReferralsFromMes.AddRange(arrayReferrals); } treatment.DictMES = ParseMes(arrayMES); treatment.DictAllReferrals = ParseAllReferrals(arrayAllReferrals); treatments.Add(treatcode, treatment); } } catch (Exception e) { Logging.ToLog(e.Message + Environment.NewLine + e.StackTrace); } } return(treatments); }
//============================ MesUsage ============================ public static string WriteMesUsageTreatmentsToExcel(DataTable dataTable, string resultFilePrefix, string templateFileName, bool isFullVersion = false) { if (!CreateNewIWorkbook(resultFilePrefix, templateFileName, out IWorkbook workbook, out ISheet sheet, out string resultFile, string.Empty)) { return(string.Empty); } Dictionary <string, ItemMESUsageTreatment> treatments = ParseMESUsageDataTableToTreatments(dataTable); int rowNumber = 1; int columnNumber = 0; foreach (KeyValuePair <string, ItemMESUsageTreatment> treatment in treatments) { IRow row = sheet.CreateRow(rowNumber); ItemMESUsageTreatment treat = treatment.Value; int necessaryServicesInMes = (from x in treat.DictMES where x.Value == 0 select x).Count(); if (necessaryServicesInMes == 0) { continue; } int hasAtLeastOneReferralByMes = treat.ListReferralsFromMes.Count > 0 ? 1 : 0; int necessaryServiceReferralByMesInstrumental = 0; int necessaryServiceReferralByMesLaboratory = 0; int necessaryServiceReferralCompletedByMesInstrumental = 0; int necessaryServiceReferralCompletedByMesLaboratory = 0; foreach (string item in treat.ListReferralsFromMes) { if (!treat.DictMES.ContainsKey(item)) { continue; } if (treat.DictMES[item] == 0) { if (!treat.DictAllReferrals.ContainsKey(item)) { continue; } int isCompleted = treat.DictAllReferrals[item].IsCompleted == 1 ? 1 : 0; int refType = treat.DictAllReferrals[item].RefType; if (refType == 2 || refType == 992140066) { necessaryServiceReferralByMesLaboratory++; necessaryServiceReferralCompletedByMesLaboratory += isCompleted; } else { necessaryServiceReferralByMesInstrumental++; necessaryServiceReferralCompletedByMesInstrumental += isCompleted; } } } int hasAtLeastOneReferralSelfMade = (treat.DictAllReferrals.Count - treat.ListReferralsFromMes.Count) > 0 ? 1 : 0; int necessaryServiceReferralSelfMadeInstrumental = 0; int necessaryServiceReferralSelfMadeLaboratory = 0; int necessaryServiceReferralCompletedSelfMadeInstrumental = 0; int necessaryServiceReferralCompletedSelfMadeLaboratory = 0; foreach (string item in treat.ListReferralsFromDoc) { if (!treat.DictMES.ContainsKey(item)) { continue; } if (treat.DictMES[item] == 0) { if (!treat.DictAllReferrals.ContainsKey(item)) { continue; } int isCompleted = treat.DictAllReferrals[item].IsCompleted == 1 ? 1 : 0; int refType = treat.DictAllReferrals[item].RefType; if (refType == 2 || refType == 992140066) { necessaryServiceReferralSelfMadeLaboratory++; necessaryServiceReferralCompletedSelfMadeLaboratory += isCompleted; } else { necessaryServiceReferralSelfMadeInstrumental++; necessaryServiceReferralCompletedSelfMadeInstrumental += isCompleted; } } } int servicesAllReferralsInstrumental = (from x in treat.DictAllReferrals where x.Value.RefType != 2 select x).Count(); int servicesAllReferralsLaboratory = treat.DictAllReferrals.Count - servicesAllReferralsInstrumental; int completedServicesInReferrals = (from x in treat.DictAllReferrals where x.Value.IsCompleted == 1 select x).Count(); int serviceInReferralOutsideMes = 0; foreach (KeyValuePair <string, ItemMESUsageTreatment.ReferralDetails> pair in treat.DictAllReferrals) { if (!treat.DictMES.ContainsKey(pair.Key)) { serviceInReferralOutsideMes++; } } double necessaryServiceInMesUsedPercent; if (necessaryServicesInMes > 0) { necessaryServiceInMesUsedPercent = (double)( necessaryServiceReferralByMesInstrumental + necessaryServiceReferralByMesLaboratory + necessaryServiceReferralSelfMadeInstrumental + necessaryServiceReferralSelfMadeLaboratory) / (double)necessaryServicesInMes; } else { necessaryServiceInMesUsedPercent = 1; } List <object> values = new List <object>() { treatment.Key, //Код лечения 1, //Прием treat.PERIOD, treat.TREATDATE, //Дата лечения treat.FILIAL, //Филиал treat.DEPNAME, //Подразделение treat.DOCNAME, //ФИО врача treat.HISTNUM, //Номер ИБ treat.CLIENTNAME, //ФИО пациента treat.AGE, //Возраст treat.MKBCODE, //Код МКБ necessaryServicesInMes, //Кол-во обязательных услуг согласно МЭС hasAtLeastOneReferralByMes, //Есть направление, созданное с использованием МЭС necessaryServiceReferralByMesInstrumental + necessaryServiceReferralByMesLaboratory, //Кол-во услуг в направлении с использованием МЭС hasAtLeastOneReferralSelfMade, //Есть направление, созданное самостоятельно necessaryServiceReferralSelfMadeInstrumental + necessaryServiceReferralSelfMadeLaboratory, //Кол-во услуг в направлении выставленных самостоятельно necessaryServiceInMesUsedPercent, //% Соответствия обязательных услуг МЭС (обязательные во всех направлениях) / всего обязательных в мэс necessaryServiceInMesUsedPercent == 1 ? 1 : 0, //Услуги из всех направлений соответсвуют обязательным услугам МЭС на 100% treat.SERVICE_TYPE, //Тип приема treat.PAYMENT_TYPE, //Тип оплаты приема }; if (isFullVersion) { values = new List <object>() { treatment.Key, //Код лечения 1, //Прием treat.PERIOD, treat.TREATDATE, //Дата лечения treat.FILIAL, //Филиал treat.DEPNAME, //Подразделение treat.DOCNAME, //ФИО врача treat.HISTNUM, //Номер ИБ treat.CLIENTNAME, //ФИО пациента treat.AGE, //Возраст treat.MKBCODE, //Код МКБ necessaryServicesInMes, //Кол-во обязательных услуг согласно МЭС treat.DictMES.Count, //Всего услуг в МЭС hasAtLeastOneReferralByMes, //Есть направление, созданное с использованием МЭС necessaryServiceReferralByMesInstrumental, //Кол-во обязательных услуг в направлении с использованием МЭС (инструментальных) necessaryServiceReferralByMesLaboratory, //Кол-во обязательных услуг в направлении с использованием МЭС (лабораторных) necessaryServiceReferralCompletedByMesInstrumental, //Кол-во исполненных обязательных услуг в направлении МЭС (инструментальных) necessaryServiceReferralCompletedByMesLaboratory, //Кол-во исполненных обязательных услуг в направлении МЭС (лабораторных) hasAtLeastOneReferralSelfMade, //Есть направление, созданное самостоятельно necessaryServiceReferralSelfMadeInstrumental, //Кол-во обязательных услуг в направлении выставленных самостоятельно (инструментальных) necessaryServiceReferralSelfMadeLaboratory, //Кол-во обязательных услуг в направлении выставленных самостоятельно (лабораторных) necessaryServiceReferralCompletedSelfMadeInstrumental, //Кол-во исполненных обязательных услуг в самостоятельно созданных направлениях (инструментальных) necessaryServiceReferralCompletedSelfMadeLaboratory, //Кол-во исполненных обязательных услуг в самостоятельно созданных направлениях (лабораторных) servicesAllReferralsInstrumental, //Всего услуг во всех направлениях (иснтрументальных) servicesAllReferralsLaboratory, //Всего услуг во всех направлениях (лабораторных) completedServicesInReferrals, //Кол-во выполненных услуг во всех направлениях serviceInReferralOutsideMes, //Кол-во услуг в направлениях, не входящих в МЭС necessaryServiceInMesUsedPercent, //% Соответствия обязательных услуг МЭС (обязательные во всех направлениях) / всего обязательных в мэс necessaryServiceInMesUsedPercent == 1 ? 1 : 0, //Услуги из всех направлений соответсвуют обязательным услугам МЭС на 100% treat.SERVICE_TYPE, //Тип приема treat.PAYMENT_TYPE, //Тип оплаты приема treat.AGNAME, //Наименование организации treat.AGNUM //Номер договора }; } foreach (object value in values) { ICell cell = row.CreateCell(columnNumber); if (double.TryParse(value.ToString(), out double result)) { cell.SetCellValue(result); } else if (DateTime.TryParseExact(value.ToString(), "dd.MM.yyyy h:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime date)) { cell.SetCellValue(date); } else { cell.SetCellValue(value.ToString()); } columnNumber++; } columnNumber = 0; rowNumber++; } if (!SaveAndCloseIWorkbook(workbook, resultFile)) { return(string.Empty); } return(resultFile); }