123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- 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();
- /// <summary>
- /// 读取TXT后,Array中的空值会返回NULL,将其转换为"".应有其他方式处理,后面再优化
- /// 明天试试Convert.ToString(a)
- /// </summary>
- /// <param name="arrayValue"></param>
- /// <returns></returns>
- 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;
- }
- }
- /// <summary>
- /// 从TXT文件中获取医保目录,并组装成JSON
- /// </summary>
- /// <param name="arr"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 从TXT文件中获取医保目录自付比例信息,并组装成JSON
- /// </summary>
- /// <param name="arr"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 从TXT文件中获取医保目录限价信息,并组装成JSON
- /// </summary>
- /// <param name="arr"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 从TXT文件中获取医保诊断,并组装成JSON
- /// </summary>
- /// <param name="arr"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 从TXT导出目录到医保平台IRIS
- /// </summary>
- /// <param name="txtPath"></param>
- /// <param name="singleRows"></param>
- /// <param name="direcType"></param>
- /// <param name="processBar"></param>
- /// <returns></returns>
- 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());
- }
- }
- /// <summary>
- /// 字典导入
- /// </summary>
- /// <param name="uiProcessBar"></param>
- /// <param name="jaList"></param>
- /// <param name="type"></param>
- /// <returns></returns>
- 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;
- }
- }
- }
- }
|