using ADODB; using System; using System.Collections.Generic; using ZLPlugin_LisPacs_MR.Domain.Units; using ZLPlugin_LisPacs_MR.Model; namespace ZLPlugin_LisPacs_MR { public class LisPacs_MR_Bll { /// /// lis是否有互认项目 /// /// public static void IsLisProject(string zlid, out string code, out int total) { code = ""; total = 0; string sql = @"Select to_char(Replace(wm_concat(distinct(l.医保编码)),',','#')) Code,Count(1) total From 诊疗项目目录 x,诊疗收费关系 y,收费项目目录 z,保险支付项目 m,ZLLPMR.互认项目清单 l Where y.诊疗项目id = x.Id And z.Id = y.收费项目id And m.收费细目id = z.Id And l.医保通用编码 = m.项目编码 And m.险类 = 111 and x.类别 = 'C' And x.Id = {0}"; sql = string.Format(sql, zlid); //Log.Info("sql1:" + sql); Recordset rd = new Recordset(); Tools.QueryTable(sql, out rd); if (!rd.EOF) { rd.MoveFirst(); code = rd.Fields["CODE"].Value.ToString(); total = int.Parse(rd.Fields["TOTAL"].Value.ToString()); } } public static void IsPacsProject(string zlid, out int total,out string type) { total = 0; type = ""; string sql = @"Select Count(1) As total,b.代码 code From 诊疗项目目录 a,ZLLPMR.字典对码表 b Where 分类 ='检查互认项目' and a.类别 = 'D' And b.编码 = '{0}' group by b.代码"; sql = string.Format(sql, zlid); //Log.Info("sql2:" + sql); Recordset rd = new Recordset(); Tools.QueryTable(sql, out rd); if (!rd.EOF) { rd.MoveFirst(); total = int.Parse(rd.Fields["TOTAL"].Value.ToString()); type = rd.Fields["CODE"].Value.ToString(); } } public static void HandleYzData(List list, long patientId,long limit_day ,out string message) { Log.Info("enter HandleYzData = "+ list.Count); message = ""; //存在互认的医嘱 int existHuRemYz = 0; for (var i = 0; i < list.Count; i++) { if (list[i].诊疗类别 == "C" && list[i].相关ID != "0.0") { LisPacs_MR_Bll.GetHuRenYzData(patientId, list[i].诊疗项目ID, list[i].诊疗类别, limit_day,out existHuRemYz); if (existHuRemYz>=1) { message = list[i].医嘱内容; //return message; } } else if (list[i].诊疗类别 == "D" && list[i].相关ID == "0.0") { LisPacs_MR_Bll.GetHuRenYzData(patientId, list[i].诊疗项目ID, list[i].诊疗类别, limit_day, out existHuRemYz); if (existHuRemYz >= 1) { message = list[i].医嘱内容; //return message; } } } Log.Info("end HandleYzData = " + message); //return message; } /// /// 返回诊疗项目ID /// /// /// public static void GetTreatmentId(List list,out string codeNo,out List listlis, out List listPacs) { //lis = ""; //lis_id = ""; //pacs = ""; //pacs_id = ""; codeNo = ""; listlis = new List(); listPacs = new List(); for (var i = 0; i < list.Count; i++) { if (list[i].诊疗类别 == "C" && list[i].相关ID != "0.0") { string code = ""; int total = 0; IsLisProject(list[i].诊疗项目ID, out code, out total); if (total > 0) { Codes codes = new Codes(); codes.id = list[i].相关ID; //原先是 取id 不行 codes.code = code; listlis.Add(codes); //lis += list[i].诊疗项目ID + ","; //lis_id += list[i].ID + ","; codeNo += code + "#"; } } else if (list[i].诊疗类别 == "D" && list[i].相关ID != "0.0") { //pacs = list[i].诊疗项目ID + ","; //pacs_id = list[i].ID + ","; int total = 0; string type = ""; //IsPacsProject(list[i].诊疗项目ID, out total, out type); String param = list[i].诊疗项目ID + "_" + list[i].标本部位 + "_" + list[i].检查方法; IsPacsProject(param, out total, out type); if (total >0) { Codes codes = new Codes(); codes.id = list[i].ID; codes.type = type; listPacs.Add(codes); codeNo += type + "#"; } } } //lis = lis.Length > 0 ? lis.Substring(0, lis.Length - 1) : lis; codeNo = codeNo.Length > 0 ? codeNo.Substring(0, codeNo.Length - 1) : codeNo; //pacs = pacs.Length > 0 ? pacs.Substring(0, pacs.Length - 1) : pacs; //lis_id = lis_id.Length > 0 ? lis_id.Substring(0, lis_id.Length - 1) : lis_id; //pacs_id = pacs_id.Length > 0 ? pacs_id.Substring(0, pacs_id.Length - 1) : pacs_id; } /// /// 住院 /// /// /// /// /// public static Recordset GetZYPostJson(long lngPatientID, long ZYID, string no,int type) { string sql = @"Select distinct a.姓名 ""PatientName"", b.身份证号 ""PatientIdCard"", e.机构编码 ""jzOrgCode"", e.机构名称 ""jzOrgName"", c.编号 ""jzDoctorCode"", c.姓名 ""jzDoctorName"", d.编码 ""jzDeptCode"", d.名称 ""jzDeptName"", a.住院号 ""businessNumber"", '{2}' ""standardItemId"", '' ""reportStartTime"", '' ""reportEndTime"", '{3}' ""hrType"" From 病案主页 a,病人信息 b, 人员表 c,部门表 d,ZLLPMR.互认配置表 e Where b.病人id = a.病人id And c.姓名 = a.住院医师 And d.Id = a.入院科室id And a.病人id = {0} And a.主页id = {1}"; sql = string.Format(sql, lngPatientID, ZYID, no,type); Recordset rd = new Recordset(); Tools.QueryTable(sql, out rd); return rd; } /// /// 门诊 /// /// /// /// /// public static Recordset GetMZPostJson(long ZYID, string no,int type) { string sql = @"Select distinct a.姓名 ""PatientName"", b.身份证号 ""PatientIdCard"", e.机构编码 ""jzOrgCode"", e.机构名称 ""jzOrgName"", c.编号 ""jzDoctorCode"", c.姓名 ""jzDoctorName"", d.编码 ""jzDeptCode"", d.名称 ""jzDeptName"", a.门诊号 ""businessNumber"", '{1}' ""standardItemId"", '' ""reportStartTime"", '' ""reportEndTime"", '{2}' ""hrType"" From 病人挂号记录 a,病人信息 b, 人员表 c,部门表 d,ZLLPMR.互认配置表 e Where b.病人id = a.病人id And c.姓名 = a.执行人 And d.Id = a.执行部门id And a.id = {0}"; sql = string.Format(sql, ZYID, no,type); Recordset rd = new Recordset(); Tools.QueryTable(sql, out rd); return rd; } /// /// 判断之前是否开个互认医嘱 /// /// /// /// /// /// public static void GetHuRenYzData( long patientId ,string zlId,string zlType, long limitDay,out int existHuRemYz) { Log.Info("GetHuRenYzData"); existHuRemYz = 0; try { string sql = @"Select count(1) count From 病人医嘱记录 where 病人id={0} and 诊疗项目id = {1} and 诊疗类别 ='{2}' and 开嘱时间 > sysdate -{3} and 医嘱内容 like '%【互认】' "; sql = string.Format(sql, patientId, zlId, zlType, limitDay); Log.Info(sql); Recordset rd = new Recordset(); Tools.QueryTable(sql, out rd); if (!rd.EOF) { rd.MoveFirst(); existHuRemYz = int.Parse(rd.Fields["count"].Value.ToString()); } }catch(Exception ex) { Log.Info("GetHuRenYzData Exception" + ex.Message); existHuRemYz = 0; } } public static int InsertLis(LISItem lis, long lngPatientID, long lngClinicID, string date, string no,long yzid) { string sql = @"Insert Into ZLLPMR.互认_LIS(LISCHECKREPORTID,REPORTNAME,ORGNAME,REPORTTIME,病人ID,主页ID,TIME,OPERATORNO,医嘱id) Values('{0}','{1}','{2}',to_date('{3}','yyyy/mm/dd hh24:mi:ss'),{4},{5},to_date('{6}','yyyy/mm/dd hh24:mi:ss'),'{7}',{8})"; sql = string.Format(sql, lis.LisCheckReportId, lis.ReportName, lis.OrgName, lis.ReportTime, lngPatientID, lngClinicID, date, no, yzid); //Log.Info("InsertLis:" + sql); int res = Tools.ExecuteSql(sql); return res; } public static void InsertLisItem(ItemListItem item, string id, long lngPatientID, long lngClinicID, string date) { string sql = @"Insert Into ZLLPMR.互认_LISITEMS(LISCHECKREPORTID,ITEMCODE,ITEMNAME,RESULT,UNIT,HINT,RANGE,STANDARDITEMID,TIME) Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',to_date('{8}','yyyy/mm/dd hh24:mi:ss'))"; sql = string.Format(sql, id, item.ItemCode, item.ItemName, item.Result, item.Unit, item.Hint, item.Range, item.StandardItemId, date); //Log.Info("InsertLisItem:" + sql); Tools.ExecuteSql(sql); } public static int InsertPacs(PACSItem item, long lngPatientID, long lngClinicID, string no,long yzid) { string sql = @"Insert Into ZLLPMR.互认_PACS(PACSCHECKREPORTID,ITEMNAME,REPORTTIME,CHECKTYPENAME,POSITIONNAME,STANDARDITEMID,DIAGNOSRESULT,ORGNAME,病人ID,主页ID,TIME,OPERATORNO,医嘱id,REPORTTYPECODE) Values('{0}','{1}',to_date('{2}','yyyy/mm/dd hh24:mi:ss'),'{3}','{4}','{5}','{6}','{7}',{8},{9},sysdate,'{10}','{11}','{12}')"; //var lis = result.ResultText[0].LIS[0]; sql = string.Format(sql, item.PacsCheckReportId, item.ItemName, item.ReportTime, item.CheckTypeName, item.PositionName, item.StandardItemId, Tools.FormatStr(item.DiagnosResult), item.OrgName, lngPatientID, lngClinicID, no, yzid, item.reportTypeCode); return Tools.ExecuteSql(sql); } public static int GetLis(string id) { int total = 0; string sql = @"Select Count(1) as TOTAL From ZLLPMR.互认_LIS Where LISCHECKREPORTID = '{0}'"; sql = string.Format(sql, id); Recordset rd = new Recordset(); Tools.QueryTable(sql, out rd); if (!rd.EOF) { rd.MoveFirst(); total = int.Parse(rd.Fields["TOTAL"].Value.ToString()); } return total; } public static void SaveData(Results result, long lngPatientID, long lngClinicID, string no, List listlis, List listpacs,out long lis_id,out long pacs_id) { lis_id = -1; pacs_id = -1; //Log.Info("666"); var lis = result.ResultText[0].LIS; var pacs = result.ResultText[0].PACS; bool state = true; if (lis != null) { //Log.Info("777"); for (int i = 0; i < lis.Count; i++) { //long yzid = null; //string code = lis[i].ItemList[0].StandardItemId; for (int j = 0; j < lis[i].ItemList.Count; j++) { //Log.Info("state:" + state); if (!state) { break; } foreach (var items in listlis) { //Log.Info("state666"); if (items.code.Contains(lis[i].ItemList[j].StandardItemId)) { // Log.Info("items.code:" + items.code); //Log.Info("items.id:" + items.id); string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //Log.Info("items.code:" + items.code); //Log.Info("items.id:" + items.id); int res = InsertLis(lis[i], lngPatientID, lngClinicID, date, no, long.Parse(items.id)); //Log.Info("res:" + res); if (res > 0) { if (lis_id == -1) { lis_id = long.Parse(items.id); } //Log.Info("res1"); for (int k = 0; k < lis[i].ItemList.Count; k++) { //Log.Info("8888"); InsertLisItem(lis[i].ItemList[k], lis[i].LisCheckReportId, lngPatientID, lngClinicID, date); } } state = false; } } } } } if (pacs != null) { long id =long.Parse(listpacs[0].id); for (int i = 0; i < pacs.Count; i++) { foreach (var items in listpacs) { if (pacs[i].reportTypeCode == items.type) { id = long.Parse(items.id); break; } } int res = InsertPacs(pacs[i], lngPatientID, lngClinicID, no, id); if (res > 0) { if (pacs_id == -1) { pacs_id = id; } } } } } /// /// 是否互认 /// /// public static void IsAgree(out int res,out int date) { res = 1; date = 20000; try { string sql = @"Select 互认 As AGREE,WAITINGDATE From zllpmr.互认配置表"; Recordset rd = new Recordset(); Tools.QueryTable(sql, out rd); if (!rd.EOF) { rd.MoveFirst(); res = int.Parse(rd.Fields["AGREE"].Value.ToString()); date = int.Parse(rd.Fields["WAITINGDATE"].Value.ToString()); } } catch (Exception ex) { Log.Info(ex.Message); Log.Info(ex.StackTrace); } } /// /// 是否互认 /// /// public static void ExistHuRemYz(out long limit_day) { limit_day = 1; try { string sql = @"Select limit_day From zllpmr.互认配置表"; Recordset rd = new Recordset(); Tools.QueryTable(sql, out rd); if (!rd.EOF) { rd.MoveFirst(); limit_day = long.Parse(rd.Fields["limit_day"].Value.ToString()); } } catch (Exception ex) { Log.Info(ex.Message); Log.Info(ex.StackTrace); } } /// /// 仅一张纸使用,查询发送的医嘱 /// /// /// /// /// public static List GetYZList(long fsh) { string sql = @"select to_char(b.ID) as id , decode(b.相关id,null,'0.0',to_char(b.相关id)) as 相关id, to_char(b.前提id ) as 前提id, to_char(b.病人来源 ) as 病人来源, to_char(b.病人id )as 病人id, to_char(b.主页id )as 主页id, to_char(b.挂号单 )as 挂号单, to_char(b.婴儿 )as 婴儿, to_char(b.姓名 )as 姓名, to_char(b.性别 )as 性别, to_char(b.年龄 )as 年龄, to_char(b.病人科室id )as 病人科室id, to_char(b.序号 )as 序号, to_char(b.医嘱状态 )as 医嘱状态, to_char(b.医嘱期效 )as 医嘱期效, to_char(b.诊疗类别 )as 诊疗类别, to_char(b.诊疗项目ID )as 诊疗项目ID, to_char(b.标本部位 )as 标本部位, to_char(b.检查方法 )as 检查方法, to_char(b.收费细目id )as 收费细目id, to_char(b.天数 )as 天数, to_char(b.单次用量 )as 单次用量, to_char(b.总给予量 )as 总给予量, to_char(b.医嘱内容 )as 医嘱内容, to_char(b.医生嘱托 )as 医生嘱托, to_char(b.执行科室ID )as 执行科室ID, to_char(b.执行频次 )as 执行频次, to_char(b.频率次数 )as 频率次数, to_char(b.频率间隔 )as 频率间隔, to_char(b.间隔单位 )as 间隔单位, to_char(b.执行时间方案 )as 执行时间方案, to_char(b.计价特性 )as 计价特性, to_char(b.执行性质 )as 执行性质, to_char(b.执行标记 )as 执行标记, to_char(b.可否分零 )as 可否分零, to_char(b.紧急标志 )as 紧急标志, to_char(b.开始执行时间,'yyyy-mm-dd hh24:mi:ss' )as 开始执行时间, to_char(b.执行终止时间 ,'yyyy-mm-dd hh24:mi:ss' )as 执行终止时间, to_char(b.开嘱科室ID )as 开嘱科室ID, to_char(b.开嘱医生 )as 开嘱医生, to_char(b.开嘱时间 ,'yyyy-mm-dd hh24:mi:ss' )as 开嘱时间, to_char(b.摘要) as 摘要 from 病人医嘱发送 a,病人医嘱记录 b where b.id = a.医嘱id and 发送号 = {0} and 诊疗类别 in('D','C') and NOT EXISTS(select 1 from 病人医嘱记录 where id = b.id and 诊疗类别 = 'D' and 相关id is not null)"; sql = string.Format(sql, fsh); Recordset recordset = new Recordset(); Tools.QueryTable(sql, out recordset); List list = new List(); while (!recordset.EOF) { YZData yz = new YZData(); yz.ID = recordset.Fields["ID"].Value.ToString(); yz.相关ID = recordset.Fields["相关ID"].Value.ToString();// yz.3767642yz., yz.前提ID = recordset.Fields["前提ID"].Value.ToString();// yz.0.0yz., yz.病人来源 = recordset.Fields["病人来源"].Value.ToString();// yz.2yz., yz.病人ID = recordset.Fields["病人ID"].Value.ToString();// yz.46688yz., yz.主页ID = recordset.Fields["主页ID"].Value.ToString();// yz.1yz., yz.挂号单 = recordset.Fields["挂号单"].Value.ToString();// yz.yz., yz.婴儿 = recordset.Fields["婴儿"].Value.ToString();// yz.0.0yz., yz.姓名 = recordset.Fields["姓名"].Value.ToString();// yz.王少清yz., yz.性别 = recordset.Fields["性别"].Value.ToString();// yz.男yz., yz.年龄 = recordset.Fields["年龄"].Value.ToString();// yz.86yz., yz.病人科室ID = recordset.Fields["病人科室ID"].Value.ToString();// yz.232yz., yz.序号 = recordset.Fields["序号"].Value.ToString();// yz.87yz., yz.医嘱状态 = recordset.Fields["医嘱状态"].Value.ToString();// yz.-1yz., yz.医嘱期效 = recordset.Fields["医嘱期效"].Value.ToString();// yz.1yz., yz.诊疗类别 = recordset.Fields["诊疗类别"].Value.ToString();// yz.Cyz., yz.诊疗项目ID = recordset.Fields["诊疗项目ID"].Value.ToString();// yz.1890yz., yz.标本部位 = recordset.Fields["标本部位"].Value.ToString();// yz.静脉血yz., yz.检查方法 = recordset.Fields["检查方法"].Value.ToString();// yz.yz., yz.收费细目ID = recordset.Fields["收费细目ID"].Value.ToString();// yz.0.0yz., yz.天数 = recordset.Fields["天数"].Value.ToString();// yz.0.0yz., yz.单次用量 = recordset.Fields["单次用量"].Value.ToString();// yz.0.0yz., yz.总给予量 = recordset.Fields["总给予量"].Value.ToString();// yz.1yz., yz.医嘱内容 = recordset.Fields["医嘱内容"].Value.ToString();// yz.肝功能yz., yz.医生嘱托 = recordset.Fields["医生嘱托"].Value.ToString();// yz.yz., yz.执行科室ID = recordset.Fields["执行科室ID"].Value.ToString();// yz.167yz., list.Add(yz); recordset.MoveNext(); } return list; } /// /// 作废医嘱 /// public static void CancelYz(long 病人id, long 主医嘱id, int lis, int pacs) { string sql = @"select distinct c.no from 病人医嘱记录 a, 病人医嘱发送 b, 门诊费用记录 c where b.医嘱id = a.id and c.医嘱序号 = b.医嘱id and a.病人id = {0} and (a.id = {1} or a.相关id = {1})"; sql = string.Format(sql, 病人id, 主医嘱id); Recordset recordset = new Recordset(); Tools.QueryTable(sql, out recordset); string json = "{\"input\":{\"operator_name\":\"\",\"operator_code\":\"\",\"operator_time\":\"\",\"del_list\":["; while (!recordset.EOF) { string no = recordset.Fields["NO"].Value.ToString(); json += "{\"fee_source\":1,\"fee_bill_type\":1,\"fee_no\":\""+ no + "\",\"del_type\":2,\"serial_num\":\"\",\"exe_sta_nums\":\"\",\"fee_ids\":\"\"},"; recordset.MoveNext(); } json = json.Substring(0,json.Length - 1); json += "]}}"; Tools.ExecuteStoredProc(病人id, 主医嘱id, json, lis, pacs); } } }