/// <summary> /// 同步科室 /// </summary> public void SyncDepartment() { var ds = PivasDbHelperSQL.Query(@"select [Code] ,[Name] ,[ShortCut] ,[Isuse] from v_for_ydwl_dept where Name like '%2%' or isuse=1"); var dt = ds.Tables[0]; var deptList = DBContext.tDepts.ToList(); foreach (DataRow zhyDept in dt.Rows) { var dept = deptList.FirstOrDefault(s => s.Code == zhyDept["Code"].ToString()); if (dept == null) { DBContext.tDepts.Add(new tDept() { Code = zhyDept["Code"].ToString(), Isuse = Convert.ToInt32(zhyDept["Isuse"]), Name = zhyDept["Name"].ToString(), ShortCut = zhyDept["ShortCut"].ToString() }); } else { dept.Name = zhyDept["Name"].ToString(); } } DBContext.SaveChanges(); }
/// <summary> /// 同步批次 /// </summary> public void SyncBatch() { var ds = PivasDbHelperSQL.Query(@"select [batch] ,[batch_name] ,[start_time] ,[end_time] from v_for_ydwl_batch"); var dt = ds.Tables[0]; var batchList = DBContext.tBatches.ToList(); foreach (DataRow zhyBatch in dt.Rows) { var batch = batchList.FirstOrDefault(s => s.batch == zhyBatch["batch"].ToString()); if (batch == null) { batch = new tBatch(); batch.batch = zhyBatch["batch"].ToString(); batch.batch_name = zhyBatch["batch_name"].ToString(); batch.end_time = zhyBatch["end_time"].ToString(); batch.start_time = zhyBatch["start_time"].ToString(); DBContext.tBatches.Add(batch); } else { batch.batch = zhyBatch["batch"].ToString(); batch.batch_name = zhyBatch["batch_name"].ToString(); batch.end_time = zhyBatch["end_time"].ToString(); batch.start_time = zhyBatch["start_time"].ToString(); } } DBContext.SaveChanges(); }
/// <summary> /// 检查Pivas数据库连接状态 /// </summary> /// <returns></returns> public static bool CheckPivasConnetionStatus() { try { PivasDbHelperSQL.Query("select top 1 * from v_for_ydwl_batch"); return(true); } catch (Exception ex) { throw ex; } }
/// <summary> /// 根据用户名获取用户信息 /// </summary> /// <param name="login"></param> /// <returns></returns> public tUser GetUser(string login) { SqlParameter loginParameter = new SqlParameter("@login", login); var dataset = PivasDbHelperSQL.Query("select top 1 * from v_for_ydwl_user where login=@login", loginParameter); var dt = dataset.Tables[0]; if (dt.Rows.Count == 0) { return(null); } DataRow dr = dt.Rows[0]; return(new tUser() { user_name = dr["login"].ToString(), true_name = dr["username"].ToString(), password = dr["pwd"].ToString() }); }
/// <summary> /// 同步药品信息 /// </summary> public void SyncDrug() { var pivasDrugCount = PivasDbHelperSQL.GetSingle(@"select count(*) from v_for_ydwl_drug"); var drugCount = DbHelperSQL.GetSingle(@"select count(*) from tDrug"); if (Convert.ToInt32(pivasDrugCount) != Convert.ToInt32(drugCount)) { DbHelperSQL.ExecuteSql(@"truncate table tdrug"); var ds = PivasDbHelperSQL.Query(@"select [drug_code] ,[drug_name] ,[drug_spec] ,[drug_units] ,[drug_use_spec] ,[drug_use_units] ,[drug_form] ,[input_code] from v_for_ydwl_drug"); DbHelperSQL.SqlBulkCopyByDataTable("tDrug", ds.Tables[0]); } }
/// <summary> /// 提交贴签状态 /// </summary> public void SubmitPrinter() { using (var db = new PrintTagDbEntities()) { var orders = db.Database.SqlQuery <tOrder>("select * from torder where (hasSubmit is null or hasSubmit <>1) and printing_status=1 ").ToList(); SqlParameter id = null; SqlParameter barcode = null; SqlParameter printer = null; foreach (var order in orders) { id = new SqlParameter("@id", order.Id); barcode = new SqlParameter("@barcode", order.barcode); printer = new SqlParameter("@printer", order.PrintUserId); PivasDbHelperSQL.ExecuteSql("exec p_for_ydwl_update 1,@barcode,@printer", barcode, printer); } db.Database.ExecuteSqlCommand("update torder set hasSubmit=1 where (hasSubmit is null or hasSubmit <>1) and printing_status=1"); } }
/// <summary> /// 从Pivas下载数据到tZHY中 /// </summary> /// <param name="dateTime">用药日期</param> /// <param name="batch">批次时间</param> private void DownloadOrder(DateTime dateTime, string batch) { var useDateParam = new SqlParameter("@usedate", dateTime.ToString("yyyy-MM-dd")); var batchParam = new SqlParameter("@batch", batch); var dataset = PivasDbHelperSQL.Query(@"select [drug_id] ,[drug_number] ,[drug_name] ,[drug_weight] ,[drug_spmc] ,[drug_class_name] ,[drug_spec] ,[usage_id] ,[use_org] ,[use_count] ,[durg_use_sp] ,[drug_use_units] ,[use_frequency] ,[use_date] ,[use_time] ,[stop_date_time] ,[start_date_time] ,[order_sub_no] ,[order_type] ,[icatrepeat_indorm] ,[new_orders] ,[yebz] ,config_name_jc [special_medicationtip] ,[size_specification] ,[pass_remark] ,[patient_id] ,[doctor_name] ,[patient_name] ,[batch] ,'' as [batch_name] ,[departmengt_name] ,[department_code] ,[zone] ,[visit_id] ,[group_num] ,[sum_num] ,[ml_speed] ,[create_date] ,[order_status] ,[is_twice_print] ,[checker] ,[deliveryer] ,[config_person] ,[config_date] ,[usage_name] ,[bed_number] ,[basket_number] ,[sorting_status] ,[sorting_model] ,[electroni_signature] ,[is_cpfh] ,[is_sf] ,[age] ,[is_db] ,[config_name] ,is_print_sn as [is_print_snv] ,[barcode] ,[sex] ,[is_cpfhr] ,[pyhfr] ,[freq_counter_sub] ,[xsyxjnew] from v_for_ydwl where use_date=@usedate", useDateParam); var dt = dataset.Tables[0]; //dt.Columns.Remove(dt.Columns["id"]); dt.Columns.Add(new DataColumn("Id", typeof(Guid))); foreach (DataRow dataRow in dt.Rows) { dataRow["Id"] = Guid.NewGuid(); } // tZHY:Pivas医嘱缓存表 // tOrder:待贴签医嘱表 // 删除原有数据 DbHelperSQL.ExecuteSql("delete tZHY where use_date=@usedate", useDateParam); // 添加新数据 DbHelperSQL.SqlBulkCopyByDataTable("tZHY", dataset.Tables[0]); // 对比医嘱数据,将需要增加的医嘱信息添加到tOrder表中 DbHelperSQL.ExecuteSql("exec P_InsertIntotOrderSelecttZHY @usedate,@batch", useDateParam, batchParam); var bakDateParam = new SqlParameter("@usedate", OrderConfig.GetBakDate()); // 更新医嘱信息 DbHelperSQL.ExecuteSql("exec P_UpdatetOrderFromtZHY @usedate,@batch", bakDateParam, batchParam); // 备份历史数据 DbHelperSQL.ExecuteSql("exec P_BakHistoryData @usedate", bakDateParam); }