using Newtonsoft.Json.Linq; using PTMedicalInsurance.Helper; using PTMedicalInsurance.Variables; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PTMedicalInsurance.Business.MI { class DataImport { //PTMedicalInsurance.Services.MIIrisServices mis = new PTMedicalInsurance.Services.MIIrisServices(); MIIrisServices mis = new MIIrisServices(); /// /// 读取TXT后,Array中的空值会返回NULL,将其转换为"".应有其他方式处理,后面再优化 /// 明天试试Convert.ToString(a) /// /// /// private string convertArrayNull(string arrayValue) { string returnValue = string.Empty; if (arrayValue == "null") { returnValue = ""; } else { returnValue = arrayValue; } return returnValue; } private void convertChrgItmTypeToMIType(string chrgItmType,out string hisType,out string hisTypeName) { hisType = ""; hisTypeName = ""; switch (chrgItmType) { case "301"://卫生材料 { hisType = "3"; hisTypeName = "材料"; break; } case "101"://西药 { hisType = "1"; hisTypeName = "药品"; break; } case "102"://中药 { hisType = "1"; hisTypeName = "药品"; break; } case "103"://中成药 { hisType = "1"; hisTypeName = "药品"; break; } case "104"://中成药 { hisType = "1"; hisTypeName = "药品"; break; } case "106"://草药 { hisType = "1"; hisTypeName = "药品"; break; } default: { hisType = "2"; hisTypeName = "诊疗"; break; } } } private string convertDictionaryValue(string type, string code) { try { JObject joRtn = mis.getSpecDictionary(Global.inf.interfaceDr.ToString(), type, code); string errMsg = ""; JArray ja = JArray.Parse(JsonHelper.getDestValue(joRtn, "result.data")); if (ja.Count == 1) { return ja[0]["name"].ToString(); } else { return code; } } catch (Exception ex) { Global.writeLog("convertDictionaryValue", ex.Message, ""); return code; } } /// /// 从TXT文件中获取医保目录,并组装成JSON /// /// /// private JObject GetMIDirectorynByTxt(string[] arr) { string hisType = "";string hisTypeName =""; dynamic jsonTemp; jsonTemp = new JObject(); jsonTemp.ID = ""; jsonTemp.updateUserID = Global.user.ID; jsonTemp.HospitalDr = Global.inf.hospitalDr; jsonTemp.InterfaceDr = Global.inf.interfaceDr; jsonTemp.Code = arr[1]; jsonTemp.Name = arr[2]; convertChrgItmTypeToMIType(arr[23],out hisType,out hisTypeName); jsonTemp.HisType = hisType; jsonTemp.HisTypeName = hisTypeName; jsonTemp.LocateCode = ""; jsonTemp.LocateName = ""; jsonTemp.DosageFormCode = arr[28]; jsonTemp.DosageFormName = arr[9]; jsonTemp.CategoryCode = arr[4];// jsonTemp.CategoryName = convertDictionaryValue("medChrgitmType", arr[4]); jsonTemp.Specification = arr[8]; //jsonTemp.SpecificationCode = arr[24]; jsonTemp.UnitOfPackag = arr[26]; jsonTemp.UnitOfValuation = ""; jsonTemp.StartDate = convertArrayNull(arr[21]); jsonTemp.EndDate = convertArrayNull(arr[22]); jsonTemp.PinyinSearchCode = ""; jsonTemp.Instructions = arr[18]; jsonTemp.ExceptContent = arr[17]; jsonTemp.Connotation = arr[16]; jsonTemp.ValidFlag = "1"; jsonTemp.Note = arr[10]; jsonTemp.VersionNO = arr[0]; jsonTemp.VersionName = ""; jsonTemp.UseFlag = 1; jsonTemp.DrugSafetyStandardCode = arr[29]; jsonTemp.ApprovalNO = arr[15]; jsonTemp.SpecialFlag = ""; jsonTemp.LimitFlag = ""; jsonTemp.LimitRange = arr[18]; jsonTemp.UniqueRecordNO = ""; jsonTemp.Manufacturers = arr[12]; jsonTemp.Company = arr[13]; jsonTemp.ChargeItemLevel = arr[5]; jsonTemp.ChargeItemLevelName = convertDictionaryValue("chrgitmLv", arr[5]); jsonTemp.ListType = arr[23]; jsonTemp.MinPackagingQuantity = arr[25]; jsonTemp.MinPackagingUnit = arr[26]; jsonTemp.PlaceOfProduct = arr[13]; jsonTemp.ChargeItemType = arr[4];//大类编码 return jsonTemp; } /// /// 从TXT文件中获取医保目录自付比例信息,并组装成JSON /// /// /// private JObject GetMIDirSelfPersentInfoByTxt(string[] arr) { dynamic jsonTemp; jsonTemp = new JObject(); jsonTemp.ID = ""; jsonTemp.updateUserID = Global.user.ID; jsonTemp.HospitalDr = Global.inf.hospitalDr; jsonTemp.InterfaceDr = Global.inf.interfaceDr; jsonTemp.Code = arr[1]; jsonTemp.Name = ""; jsonTemp.PersonnelType = arr[2]; jsonTemp.ProportionType = arr[5]; jsonTemp.InsuranceAreaCode = arr[4]; jsonTemp.BeginDate = arr[3]; jsonTemp.EndDate = arr[6]; jsonTemp.PoolAreaNO = ""; jsonTemp.ValidFlag = 1; jsonTemp.RequiredID = arr[0]; //存版本号 jsonTemp.SelfProportion = arr[7]; return jsonTemp; } /// /// 从TXT文件中获取医保目录限价信息,并组装成JSON /// /// /// private JObject GetMIDirLimitPriceByTxt(string[] arr) { dynamic jsonTemp; jsonTemp = new JObject(); jsonTemp.ID = ""; jsonTemp.updateUserID = Global.user.ID; jsonTemp.HospitalDr = Global.inf.hospitalDr; jsonTemp.InterfaceDr = Global.inf.interfaceDr; jsonTemp.Code = arr[1]; jsonTemp.Name = ""; jsonTemp.LimitType = arr[2]; jsonTemp.DisposeWay = arr[5]; jsonTemp.InsuranceAreaCode = arr[4]; jsonTemp.BeginDate = arr[3]; jsonTemp.EndDate = arr[6]; jsonTemp.ValidFlag = 1; jsonTemp.RequiredID = arr[0]; jsonTemp.UpLimitAmount = arr[7]; return jsonTemp; } /// /// 从TXT文件中获取医保诊断,并组装成JSON /// /// /// private JObject GetMIDiseByTxt(string[] arr) { dynamic jsonTemp; jsonTemp = new JObject(); jsonTemp.ID = ""; jsonTemp.updateUserID = Global.user.ID; jsonTemp.HospitalDr = Global.inf.hospitalDr; jsonTemp.InterfaceDr = Global.inf.interfaceDr; jsonTemp.Code = arr[0]; jsonTemp.Name = arr[2]; jsonTemp.HisType = 4; jsonTemp.HisTypeName = "疾病诊断"; jsonTemp.LocateCode = ""; jsonTemp.LocateName = ""; jsonTemp.DosageFormCode = ""; jsonTemp.DosageFormName = ""; ; jsonTemp.CategoryCode = arr[5]; jsonTemp.CategoryName = ""; jsonTemp.Specification = ""; ; jsonTemp.SpecificationCode = ""; jsonTemp.UnitOfPackag = ""; ; jsonTemp.UnitOfValuation = ""; jsonTemp.StartDate = ""; ; jsonTemp.EndDate = ""; ; jsonTemp.PinyinSearchCode = arr[3]; jsonTemp.Instructions = ""; ; jsonTemp.ExceptContent = ""; ; jsonTemp.Connotation = ""; ; jsonTemp.ValidFlag = "1"; jsonTemp.Note = "";; jsonTemp.VersionNO = ""; jsonTemp.VersionName = ""; jsonTemp.UseFlag = 1; jsonTemp.DrugSafetyStandardCode = ""; jsonTemp.ApprovalNO = ""; jsonTemp.SpecialFlag = ""; jsonTemp.LimitFlag = ""; jsonTemp.LimitRange = ""; jsonTemp.UniqueRecordNO = ""; jsonTemp.Manufacturers = ""; jsonTemp.Company = ""; return jsonTemp; } /// /// 从TXT导出目录到医保平台IRIS /// /// /// /// /// /// public JObject insertDirectoryToMIIrisByTxt(string txtPath, int size, int direcType, Sunny.UI.UIProcessBar processBar,out string currentMaxVerNO) { int errorCount = 0; string errorMsg = ""; currentMaxVerNO = ""; JObject joRtn = new JObject(); int defaultColumns = 0; switch (direcType) { case 0: { defaultColumns = 31; break; } case 1: { defaultColumns = 6; break; } //case 6: // { // defaultColumns = 8; // break; // } //case 7: // { // defaultColumns = 8; // break; // } } try { /*据说速度更快 * https://www.cnblogs.com/eniac12/p/4398310.html * using (StreamReader sr = File.OpenText(fileName)) { string s = String.Empty; while ((s = sr.ReadLine()) != null) { //do what you have to here } } Convert.ToString(a) */ long lSize = new FileInfo(txtPath).Length; if (lSize == 0) { joRtn = JsonHelper.setExceptionJson(-99999999, "检查到文件大小为0", null); return joRtn; } string[] lines = System.IO.File.ReadAllLines(txtPath,Encoding.GetEncoding("GB2312")); dynamic jaParams = new JArray(); int rows = lines.Length; processBar.Maximum = rows; for (int i = 0; i < rows; i++) { processBar.Value = i + 1; Application.DoEvents(); string lineTmp = lines[i]; string[] arr = lineTmp.Split('\t'); //判断是不是除外内容里的\r\n if (arr.Length < defaultColumns) { continue; } //判断是哪种目录类型 switch (direcType) { //s收费项目 case 0: { if (i == rows - 1) { currentMaxVerNO = arr[0]; } jaParams.Add(GetMIDirectorynByTxt(arr)); break; } case 1: { jaParams.Add(GetMIDiseByTxt(arr)); break; } case 6://自付比例 { if (i == rows - 1) { currentMaxVerNO = arr[0]; } jaParams.Add(GetMIDirSelfPersentInfoByTxt(arr)); break; } case 7://医保限价 { if (i == rows - 1) { currentMaxVerNO = arr[0]; } jaParams.Add(GetMIDirLimitPriceByTxt(arr)); break; } } //每50行提交一次给后台 int currentRows = i + 1; if ((currentRows % size == 0) && (i != 0)) { switch (direcType) { case 6: { joRtn = mis.UpdateSelfPercent(jaParams); break; } case 7: { joRtn = mis.UpdateLimitPrice(jaParams); break; } default: { joRtn = mis.insertDirectory(jaParams); break; } } if (joRtn["errorCode"].ToString() != "0") { errorCount = errorCount + 1; errorMsg = "\r\n" + errorMsg + joRtn["errorMessage"].ToString(); } jaParams = new JArray(); } if ((currentRows == rows) && (currentRows % size != 0)) { switch (direcType) { case 6: { joRtn = mis.UpdateSelfPercent(jaParams); break; } case 7: { joRtn = mis.UpdateLimitPrice(jaParams); break; } default: { joRtn = mis.insertDirectory(jaParams); break; } } if (joRtn["errorCode"].ToString() != "0") { errorCount = errorCount + 1; errorMsg = "\r\n" + errorMsg + joRtn["errorMessage"].ToString(); } jaParams = new JArray(); } } joRtn = JsonHelper.setExceptionJson(0 - errorCount, errorMsg, null); return joRtn; } catch (Exception ex) { joRtn = JsonHelper.setExceptionJson(-1, "insertDirectoryToMIIrisByTxt", ex.Message); return joRtn; } finally { Global.writeLog("PTMedicalInsurance.Business.MI.insertDirectoryToMIIrisByTxt", txtPath,joRtn.ToString()); } } /// /// 字典导入 /// /// /// /// /// public JObject importDictionary(Sunny.UI.UIProcessBar uiProcessBar, JArray jaList) { int errorCount = 0; JObject joRtn = new JObject(); string errorMsg = "", outParam = "",errMsgList =""; Boolean bFail = false; try { int rows = jaList.Count; uiProcessBar.Maximum = rows; for (int i = 0; i < rows; i++) { uiProcessBar.Value = i + 1; Application.DoEvents(); JObject joData = (JObject)jaList[i]; joData.Add("HospitalDr", Global.inf.hospitalDr); joData.Add("InterfaceDr", Global.inf.interfaceDr); joRtn = mis.insertDictionarys(joData); if (JsonHelper.parseIrisRtnValue(joRtn, out errorMsg) != 0) { bFail = true; errMsgList = errMsgList + errorMsg; } } if (bFail) return JsonHelper.setExceptionJson(-1, "importDictionary", errMsgList); else return JsonHelper.setExceptionJson(0, "", ""); } catch (Exception ex) { joRtn = JsonHelper.setExceptionJson(-1, "importDictinary", ex.Message); outParam = joRtn.ToString(); return joRtn; } } } }