using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PTMedicalInsurance.Business;
using PTMedicalInsurance.Helper;
using PTMedicalInsurance.Variables;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PTMedicalInsurance.FormSetter;
using PTMedicalInsurance.Common;
using PTMedicalInsurance.Forms.BasicDatas;
namespace PTMedicalInsurance.Forms
{
public partial class BasicData : Form
{
//设置实例
CenterBusiness cBus = new CenterBusiness();
HisMainBusiness hBus = new HisMainBusiness();
HisIrisServices hIS = new HisIrisServices();
MIIrisServices mIS = new MIIrisServices();
InvokeHelper invoker = new InvokeHelper();
private bool isStopLoopDownload = false;
DataTable dtExport;
public BasicData()
{
InitializeComponent();
this.tcBasicData.TabPages[3].Parent = null;
rbgDirecType.SelectedIndex = 0;
rbgDirecType_C.SelectedIndex = 0;
rbgDirecType.SelectedIndex = 8;
rbgDownItemType_4.SelectedIndex = 0;
rbgInsuDirecType_C.SelectedIndex = 0;
rbSingleDown.Checked = true;
this.rbgDirecType.ValueChanged += new Sunny.UI.UIRadioButtonGroup.OnValueChanged(this.rbgDirecType_ValueChanged);
this.pgDownload.PageChanged += new Sunny.UI.UIPagination.OnPageChangeEventHandler(this.pgDownload_PageChanged);
this.pgCenterDirect.PageChanged += new Sunny.UI.UIPagination.OnPageChangeEventHandler(this.pgCenterDirect_PageChanged);
this.pgHISDirect.PageChanged += new Sunny.UI.UIPagination.OnPageChangeEventHandler(this.pgHISDirect_PageChanged);
Font rowFont = new Font("UTF-8", 8);
Font columnFont = new Font("UTF-8", 9);
rbAll.Checked = true;
this.rbAll.ValueChanged += new Sunny.UI.UIRadioButton.OnValueChanged(this.rbAll_ValueChanged);
GridViewSetter gvs = new GridViewSetter();
gvs.SetHeaderTextOfInsuDir(dgvInsuDirInfo);
gvs.SetHeaderTextOfMapping_HisDirectory(dgvHISDirectory);
}
#region 函数封装
private void queryInsuDirectory(int currentPage, int pageSize, int directoryType, int interfaceDr, string code)
{
try
{
string dirCode = "";
string dirName = "";
string verNO = "";
string approvalNO = "";
Sunny.UI.UIDataGridView dgv;
Sunny.UI.UIPagination pg;
if (tcBasicData.SelectedIndex == 1)
{
dirCode = tbDirectoryCode.Text;
dirName = tbDircetoryName.Text;
verNO = tbDirectoryVerNO.Text;
approvalNO = "";
dgv = dgvDirectoy;
pg = pgDownload;
}
else
{
dirName = tbCenterDirectoryFilter.Text;
dirCode = tbInsuCode.Text;
dgv = dgvCenterDirectory;
approvalNO = tbApprovalNO.Text;
pg = pgCenterDirect;
}
JObject joInput = new JObject {
{ "currentPage" , currentPage },
{ "pageSize" , pageSize },
{ "serviceCode" , code },
{ "directoryType" , directoryType },
{ "directoryCode" , dirCode },
{ "directoryName" , dirName },
{ "approvalNO" , approvalNO },
{ "verNO" , verNO },
{ "directoryDr" , interfaceDr }
};
JObject joRtn = mIS.getMIDirectoryByPagination(joInput);
if (joRtn["errorCode"].ToString() != "0")
{
MessageBox.Show("IRIS数据返回错误:" + joRtn["errorMessage"].ToString());
return;
}
if (joRtn["result"]["rows"] == null)
{
MessageBox.Show("该节点不存在");
return;
}
if (joRtn["result"]["total"].ToString() == "0")
{
MessageBox.Show("未查询到数据");
dgv.DataSource = null;
return;
}
DataTable dt = (DataTable)joRtn["result"]["rows"].ToObject(typeof(DataTable));
int totalCount = int.Parse(joRtn["result"]["total"].ToString());
pg.TotalCount = totalCount;
pg.PageSize = pageSize;
dgv.DataSource = dt;
dgv.Columns[0].ReadOnly = true;
}
catch (Exception ex)
{
MessageBox.Show("查询异常:" + ex.Message);
}
}
private void setHeaderTxt(int directoryType, Sunny.UI.UIDataGridView dgv)
{
GridViewSetter gvdSetter = new GridViewSetter();
switch (directoryType)
{
case 0://药品
{
gvdSetter.SetHeaderTextOfDrug(dgv);
break;
}
case 1://诊疗
{
gvdSetter.SetHeaderTextOfMedicalService(dgv);
break;
}
case 2://材料
{
gvdSetter.SetHeaderTextOfMaterials(dgv);
break;
}
case 3://疾病诊断
{
gvdSetter.SetHeaderTextOfDiagnose(dgv);
break;
}
case 4://手术
{
gvdSetter.SetHeaderTextOfDiagnose(dgv);
break;
}
case 5://慢性病
{
gvdSetter.SetHeaderTextOfDiagnose(dgv);
break;
}
case 6://DRGs
{
gvdSetter.SetHeaderTextOfDiagnose(dgv);
break; ;
}
case 7://日间手术
{
gvdSetter.SetHeaderTextOfDiagnose(dgv);
break; ;
}
case 8://字典表
{
gvdSetter.SetHeaderTextOfDictionary(dgv);
break;
}
case 9://中药饮片
{
gvdSetter.SetHeaderTextOfDiagnose(dgv);
break;
}
case 10://医疗机构制剂
{
gvdSetter.SetHeaderTextOfDiagnose(dgv);
break;
}
case 11://民族药品
{
gvdSetter.SetHeaderTextOfDiagnose(dgv);
break;
}
case 12://肿瘤形态学
{
gvdSetter.SetHeaderTextOfDiagnose(dgv);
break;
}
case 13://中医疾病目录
{
gvdSetter.SetHeaderTextOfDiagnose(dgv);
break;
}
case 14://中医证候目录
{
gvdSetter.SetHeaderTextOfDiagnose(dgv);
break;
}
}
}
private void queryHISInsuDirectory(int directoryType, int pageIndex, int count, Sunny.UI.UIDataGridView dgv, int interfaceDr)
{
string code = "09010042";
if (tcBasicData.SelectedIndex == 1)
{
if (rbgDirecType.SelectedIndex == 8)
{ code = "09010043"; }
}
queryInsuDirectory(pageIndex, count, directoryType + 1, interfaceDr, code);
if (tcBasicData.SelectedIndex == 1)
{
setHeaderTxt(directoryType, dgv);
}
else
{
setHeaderTxt(directoryType, dgv);
}
}
private int queryHISDirectory(int currentPage, int pageSize, out string errMsg)
{
errMsg = "";
string directoryType = string.Empty;
switch (rbgDirecType_C.SelectedIndex)
{
case 0:
{
directoryType = "drugs";
break;
}
case 1:
{
directoryType = "diagnosi";
break;
}
case 2:
{
directoryType = "consumables";
break;
}
}
JObject joHISRtn = new JObject();
JObject joRtn = new JObject();
InvokeHelper invoker = new InvokeHelper();
string flag = "";
//全部是先调HIS,然后再匹配医保平台的对照关系
if (rbAll.Checked)
{
JArray jaPagination = new JArray();
JArray jaParams = new JArray();
flag = "All";
dynamic joParam = new JObject();
joParam.code = "";
joParam.descripts = "";
joParam.FindType = new JArray();
joParam.TypeID = "";
joParam.alias = tbHISDirectoryFilter.Text;
joParam.include = "Hosp";
joParam.groupID = "324";
joParam.hospID = Global.inf.hisHospitalDr;
joParam.interfaceDr = Global.inf.interfaceDr;
joParam.type = directoryType;
joParam.flag = flag;
joParam.specInput = "";
jaParams.Add(joParam);
dynamic joPagination = new JObject();
joPagination.pageSize = pageSize;
//joPagination.pageSize = 2;
joPagination.currentPage = currentPage;
joPagination.sortColumn = "Code";
joPagination.sortOrder = "asc";
jaPagination.Add(joPagination);
//该服务需要改写,需要跟(CloudMedicalInsurancePlatform.Tables.MapRelation)进行关联
//joInParams.code = "09010038";
if (hIS.getHISDir(jaPagination, jaParams, out joHISRtn, out errMsg) != 0)
{
return -1;
}
joRtn = mIS.ConvertHISDir(joHISRtn);
if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
{
return -1;
}
}
//已对照是先调云医保,然后再匹配HIS
if (rbMaped.Checked)
{
JArray jaPagination = new JArray();
JArray jaParams = new JArray();
flag = "Maped";
dynamic joParam = new JObject();
joParam.alias = tbHISDirectoryFilter.Text;
joParam.InsuAlias = tbMappedInfo.Text;
joParam.HospitalDr = Global.inf.hospitalDr;
joParam.InterfaceDr = Global.inf.interfaceDr;
joParam.hisType = directoryType;
jaParams.Add(joParam);
dynamic joPagination = new JObject();
joPagination.pageSize = pageSize;
joPagination.currentPage = currentPage;
joPagination.sortColumn = "HisCode";
joPagination.sortOrder = "asc";
jaPagination.Add(joPagination);
JObject joMIRtn = mIS.GetMappedHISDir(jaPagination, jaParams);
if (JsonHelper.parseIrisRtnValue(joMIRtn, out errMsg) != 0)
{
return -1;
}
JArray jaMaped = JArray.FromObject(joMIRtn["result"]["Data"]);
if (jaMaped.Count < 1)
{
errMsg = "未查询到对照数据!";
dgvHISDirectory.DataSource = null;
return -1;
}
//传给HIS,进行匹配
joParam = new JObject();
joParam.TotalCount = joMIRtn["result"]["TotalCount"];
joParam.type = directoryType;
joParam.flag = flag;
joParam.hospID = Global.inf.hisHospitalDr;
joParam.interfaceDr = Global.inf.interfaceDr;
joParam.alias = tbHISDirectoryFilter.Text;
joParam.include = "Hosp";
joParam.groupID = "324";
joParam.compareArr = joMIRtn["result"]["Data"];
jaParams = new JArray();
jaParams.Add(joParam);
if (hIS.getHISDir(jaPagination, jaParams, out joRtn, out errMsg) != 0)
{
return -1;
}
else
{
JArray jaData = JArray.Parse(JsonHelper.getDestValue(joRtn, "result.Data"));
for (int i = 0; i < jaData.Count; i++)
{
jaData[i]["flag"] = new JObject();
jaData[i]["flag"] = "已对照";
}
joRtn["result"]["Data"] = jaData;
Global.writeLog(joRtn.ToString());
}
}
//未对照
if (rbNoMaped.Checked)
{
JArray jaPagination = new JArray();
JArray jaParams = new JArray();
flag = "All";
dynamic joParam = new JObject();
joParam.code = "";
joParam.descripts = "";
joParam.FindType = new JArray();
joParam.TypeID = "";
joParam.alias = tbHISDirectoryFilter.Text;
joParam.include = "Hosp";
joParam.groupID = "324";
joParam.hospID = Global.inf.hisHospitalDr;
joParam.interfaceDr = Global.inf.interfaceDr;
joParam.type = directoryType;
joParam.flag = flag;
joParam.specInput = "";
jaParams.Add(joParam);
dynamic joPagination = new JObject();
joPagination.pageSize = pageSize; //pageSize;
//joPagination.pageSize = 2;
joPagination.currentPage = currentPage;
joPagination.sortColumn = "Code";
joPagination.sortOrder = "asc";
jaPagination.Add(joPagination);
//1.获取全部HIS目录
if (hIS.getHISDir(jaPagination, jaParams, out joHISRtn, out errMsg) != 0)
{
return -1;
}
joRtn = mIS.GetNoMappHISDir(joHISRtn);
if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
{
return -1;
}
}
DataTable dt = (DataTable)joRtn["result"]["Data"].ToObject(typeof(DataTable));
dtExport = dt;
int totalCount = int.Parse(joRtn["result"]["TotalCount"].ToString());
pgHISDirect.TotalCount = totalCount;
pgHISDirect.PageSize = 50;
dgvHISDirectory.DataSource = null;
dgvHISDirectory.DataSource = dt;
dgvHISDirectory.Columns[0].ReadOnly = true;
return 0;
}
private void queryCenterDirectory_09010012(int currentPage, int pageSize)
{
string directoryType = string.Empty;
switch (rbgDirecType_C.SelectedIndex)
{
case 0:
{
directoryType = "drugs";
break;
}
case 1:
{
directoryType = "diagnosi";
break;
}
case 2:
{
directoryType = "consumables";
break;
}
}
dynamic joInParams = new JObject();
joInParams.pagination = new JArray() as dynamic;
joInParams.session = new JArray() as dynamic;
JArray jaParams = new JArray();
dynamic joParams = new JObject();
joParams.code = "";
joParams.descripts = "";
joParams.FindType = new JArray();
joParams.TypeID = "";
joParams.alias = "";
joParams.include = "Hosp";
joParams.groupID = "324";
joParams.hospID = "25";
joParams.type = directoryType;
joParams.specInput = "";
jaParams.Add(joParams);
joInParams.Add("params", JArray.FromObject(jaParams));
dynamic joSession = new JObject();
joSession.userID = "";
joSession.locID = "";
joSession.groupID = "";
joSession.hospID = "";
joSession.sessionID = "";
joSession.hospCode = "";
joSession.language = "";
joSession.hostName = "";
joSession.ipv4 = "";
joSession.ipv6 = "";
joSession.mac = "";
joInParams.session.Add(joSession);
dynamic joPagination = new JObject();
joPagination.pageSize = pageSize;
joPagination.currentPage = currentPage;
joPagination.sortColumn = "Code";
joPagination.sortOrder = "asc";
joInParams.pagination.Add(joPagination);
joInParams.code = "09010012";
string sInput = joInParams.ToString();
string sRtn = invoker.invokeInsuService(joInParams, "");
JObject jsonRtn = JObject.Parse(sRtn);
if (jsonRtn["result"]["Data"] == null)
{
MessageBox.Show("该节点不存在");
return;
}
JObject joRtn = JObject.Parse(sRtn);
DataTable dt = (DataTable)joRtn["result"]["Data"].ToObject(typeof(DataTable));
int totalCount = int.Parse(joRtn["result"]["TotalCount"].ToString());
pgCenterDirect.TotalCount = totalCount;
pgCenterDirect.PageSize = 50;
dgvCenterDirectory.DataSource = dt;
}
private void Mapping()
{
JObject joRtn = new JObject();
JObject joIn = new JObject();
int iRtn = -1;
try
{
int iHis = dgvHISDirectory.CurrentRow.Index;
if (dgvCenterDirectory.CurrentRow == null)
{
MessageBox.Show("请查询中心目录");
return;
}
int iCenter = dgvCenterDirectory.CurrentRow.Index;
DataTable dtHis = (DataTable)dgvHISDirectory.DataSource;
DataTable dtCenter = (DataTable)dgvCenterDirectory.DataSource;
dgvHISDirectory.Rows[iHis].Cells["insuCode"].Value = dgvCenterDirectory.Rows[iCenter].Cells["Code"].Value.ToString();
dgvHISDirectory.Rows[iHis].Cells["insuName"].Value = dgvCenterDirectory.Rows[iCenter].Cells["Name"].Value.ToString();
int hisType = rbgDirecType_C.SelectedIndex + 1;
string hisTypeName = rbgDirecType_C.Items[hisType - 1].ToString(); ;
JArray jaParams = new JArray();
dynamic jsonTemp = new JObject();
if (dtHis.Rows[iHis]["MapID"].ToString() == "0")
{
jsonTemp.ID = "";
}
else
{
jsonTemp.ID = dtHis.Rows[iHis]["MapID"];
}
jsonTemp.HospitalDr = Global.inf.hospitalDr;
jsonTemp.updateUserID = Global.user.ID;
jsonTemp.InterfaceDr = Global.inf.interfaceDr;
jsonTemp.HISCode = dgvHISDirectory.Rows[iHis].Cells["itemCode"].Value;
jsonTemp.HISName = dgvHISDirectory.Rows[iHis].Cells["itemDesc"].Value;
jsonTemp.ChargeItemDr = dtHis.Rows[iHis]["ID"];
jsonTemp.DiretoryDr = dtCenter.Rows[iCenter]["medInsuDirectoryID"];
//1.已对照 2.已对照但未上传 3 已对照且已上传
jsonTemp.State = 1;
jsonTemp.HisType = hisType;
jsonTemp.HisTypeName = hisTypeName;
jsonTemp.InsuCode = dgvCenterDirectory.Rows[dgvCenterDirectory.CurrentRow.Index].Cells["Code"].Value;
jsonTemp.InsuName = dgvCenterDirectory.Rows[dgvCenterDirectory.CurrentRow.Index].Cells["Name"].Value;
jsonTemp.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
jaParams.Add(jsonTemp);
joIn = new JObject();
joIn.Add(new JProperty("params", jaParams));
joIn.Add("code", "09010040");
InvokeHelper invoker = new InvokeHelper();
joRtn = invoker.invokeInsuService(joIn.ToString(), "插入对照信息");
//JObject joRtn = JObject.Parse(irisRtn);
iRtn = (int)joRtn["errorCode"];
if (iRtn == 0)
{
dgvHISDirectory.Rows[iHis].Cells["flag"].Value = "已对照";
}
else
{
dgvHISDirectory.Rows[iHis].Cells["flag"].Value = "对照失败";
}
}
finally
{
invoker.saveYHLog("数据对照", joIn.ToString(),DateTime.Now.ToString("yyyyMMddHHmmssnnn") ,"",joRtn.ToString(),iRtn,$"{Global.user.ID}:{Global.user.name}");
Global.writeLog($"数据对照({Global.user.ID}:{Global.user.name})", joIn.ToString(),joRtn.ToString());
}
}
private void CancleMapping()
{
int iHis = dgvHISDirectory.CurrentRow.Index;
DataTable dtHis = (DataTable)dgvHISDirectory.DataSource;
JArray jaParams = new JArray();
dynamic jsonTemp = new JObject();
jsonTemp.ID = dtHis.Rows[iHis]["MapID"];
jsonTemp.HospitalDr = Global.inf.hospitalDr;
jsonTemp.updateUserID = Global.user.ID;
jsonTemp.InterfaceDr = Global.inf.interfaceDr;
jsonTemp.HISCode = dgvHISDirectory.Rows[iHis].Cells["itemCode"].Value;
jsonTemp.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
jaParams.Add(jsonTemp);
JObject joIn = new JObject();
joIn.Add(new JProperty("params", jaParams));
joIn.Add("code", "09010041");
InvokeHelper invoker = new InvokeHelper();
JObject joRtn = invoker.invokeInsuService(joIn.ToString(), "取消对照");
if ((int)joRtn["errorCode"] == 0)
{
dgvHISDirectory.Rows[iHis].Cells["insuCode"].Value = "";
dgvHISDirectory.Rows[iHis].Cells["insuName"].Value = "";
dgvHISDirectory.Rows[iHis].Cells["flag"].Value = "未对照";
dtHis.Rows[iHis]["MapID"] = 0;
}
else
{
dgvHISDirectory.Rows[iHis].Cells["flag"].Value = "取消失败";
}
}
///
/// 医保目录单个版本号的下载
///
///
///
///
///
///
public int SingleDownload(out string errorMessage, out string currentMaxVerNO)
{
errorMessage = "";
currentMaxVerNO = "";
PTMedicalInsurance.Business.HIS.DownLoad hDL = new Business.HIS.DownLoad();
try
{
if (isStopLoopDownload)
{
errorMessage = "操作员主动停止下载";
return -1;
}
return hDL.DownloadMIDiretoryBySpecifyVerNO(tbVer_4.Text, rbgDownItemType_4.SelectedIndex, pbDownload_4, out errorMessage, out currentMaxVerNO);
}
catch (Exception ex)
{
errorMessage = "SingleDownload提示:" + ex.Message;
return -1;
}
}
///
/// 自动下载医保目录,直到最新版本(返回报错)
///
///
///
///
///
public int AutoDownload(int directoryType,out string errorMessage)
{
int iResult = 0;
errorMessage = "";
string currentMaxVerNO;
try
{
while (iResult == 0)
{
JObject joMaxVerNO = mIS.getDirectoryMaxVersionNO(directoryType);
string ver = joMaxVerNO["result"]["MaxVersionNO"].ToString();
tbVer_4.Text = ver;
//iResult = JsonHelper.parseIrisRtnValue(joMaxVerNO, out errorMessage);
iResult = SingleDownload(out errorMessage, out currentMaxVerNO);
}
return iResult;
}
catch (Exception ex)
{
errorMessage = ex.Message;
return -1;
}
}
public int loopDownloadBySpecVerNO(out string errorMessage)
{
int iResult = 0;
errorMessage = "";
string currentMaxVerNO;
try
{
while (iResult == 0)
{
//tbVer_4.Text = ver;
//iResult = JsonHelper.parseIrisRtnValue(joMaxVerNO, out errorMessage);
iResult = SingleDownload(out errorMessage, out currentMaxVerNO);
tbVer_4.Text = currentMaxVerNO;
}
return iResult;
}
catch (Exception ex)
{
errorMessage = ex.Message;
return -1;
}
}
#endregion
private void Form1_Load(object sender, EventArgs e)
{
//rbgDirecType.ValueChanged += new Sunny.UI.UIRadioButtonGroup.OnValueChanged(rbgDirecType_ValueChanged);
this.WindowState = FormWindowState.Maximized;
}
private void btnDownload_Click(object sender, EventArgs e)
{
}
private void btnQuery_Click(object sender, EventArgs e)
{
queryHISInsuDirectory(rbgDirecType.SelectedIndex, 1, 20, dgvDirectoy, Global.inf.interfaceDr);
}
private void btnQueryHISDirectory_Click(object sender, EventArgs e)
{
this.dgvHISDirectory.SelectionChanged -= this.dgvHISDirectory_SelectionChanged;
string errMsg;
int iCount = 50;
if (rbNoMaped.Checked) iCount = 5000;
if (queryHISDirectory(1, iCount, out errMsg) != 0)
{
MessageBox.Show(errMsg);
return;
}
this.dgvHISDirectory.SelectionChanged += this.dgvHISDirectory_SelectionChanged;
}
private void btnQueryCenterDirectory_Click(object sender, EventArgs e)
{
queryHISInsuDirectory(rbgInsuDirecType_C.SelectedIndex, 1, 50, dgvCenterDirectory, Global.inf.interfaceDr);
}
private void pgDownload_PageChanged(object sender, object pagingSource, int pageIndex, int count)
{
queryHISInsuDirectory(rbgDirecType.SelectedIndex, pageIndex, count, dgvDirectoy, Global.inf.interfaceDr);
}
private void pgHISDirect_PageChanged(object sender, object pagingSource, int pageIndex, int count)
{
string errMsg;
if (queryHISDirectory(pageIndex, 50, out errMsg) != 0)
{
MessageBox.Show(errMsg);
return;
}
}
private void pgCenterDirect_PageChanged(object sender, object pagingSource, int pageIndex, int count)
{
queryHISInsuDirectory(rbgDirecType_C.SelectedIndex, pageIndex, count, dgvCenterDirectory, Global.inf.interfaceDr);
}
private void rbgDirecType_ValueChanged(object sender, int index, string text)
{
btnQuery_Click(null, new EventArgs());
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
CancleMapping();
}
private void tsmiMapping_Click(object sender, EventArgs e)
{
Mapping();
}
private void dgvHISDirectory_DoubleClick(object sender, EventArgs e)
{
}
private void dgvDirectoy_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
//自动编号,与数据无关
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
dgvDirectoy.RowHeadersWidth - 4,
e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics,
(e.RowIndex + 1).ToString(),
dgvDirectoy.RowHeadersDefaultCellStyle.Font,
rectangle,
dgvDirectoy.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
private void rbAll_ValueChanged(object sender, bool value)
{
if (rbAll.Checked)
{
btnQueryHISDirectory_Click(null, new EventArgs());
}
}
private void rbMaped_CheckedChanged(object sender, EventArgs e)
{
if (rbMaped.Checked)
{
string errMsg;
if (queryHISDirectory(1, 50, out errMsg) != 0)
{
MessageBox.Show(errMsg);
return;
}
}
}
private void btAddDir_Click(object sender, EventArgs e)
{
if (rbgDirecType.SelectedIndex == 8)
{
string errMsg = "";
AddSingleDictionary addDictionary = new AddSingleDictionary();
if (addDictionary.ShowDialog() == DialogResult.OK)
{
if (UpdateDictionaryBySelf(addDictionary, out errMsg) != 0)
{
MessageBox.Show(errMsg);
}
else
{
MessageBox.Show("新增成功!");
}
}
}
else
{
AddSingleDirectory addDirectory = new AddSingleDirectory(rbgDirecType.SelectedIndex);
if (addDirectory.ShowDialog() == DialogResult.OK)
{
JObject joRtn = mIS.UpdateDirectoryBySelf(addDirectory.joPamam);
string error = "";
if (JsonHelper.parseIrisRtnValue(joRtn, out error) != 0)
{
MessageBox.Show("新增失败:" + error);
}
else
{
MessageBox.Show("新增成功");
}
}
}
}
private void btEditDir_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)dgvDirectoy.DataSource;
if ((dt == null) || (dt.Rows.Count < 1))
{
MessageBox.Show("表中无数据,请检查!");
return;
}
DataRow dr = dt.Rows[dgvDirectoy.CurrentRow.Index];
if (rbgDirecType.SelectedIndex == 8)
{
string errMsg;
AddSingleDictionary addDictionary = new AddSingleDictionary(dr);
if (addDictionary.ShowDialog() == DialogResult.OK)
{
if (UpdateDictionaryBySelf(addDictionary, out errMsg) != 0)
{
MessageBox.Show(errMsg);
}
else
{
MessageBox.Show("修改成功!");
}
}
}
else
{
AddSingleDirectory addDirectory = new AddSingleDirectory(rbgDirecType.SelectedIndex, dr);
if (addDirectory.ShowDialog() == DialogResult.OK)
{
JObject joRtn = mIS.UpdateDirectoryBySelf(addDirectory.joPamam);
string error = "";
if (JsonHelper.parseIrisRtnValue(joRtn, out error) != 0)
{
MessageBox.Show("修改失败:" + error);
}
else
{
MessageBox.Show("修改成功");
}
}
}
}
private void rbgDownType_3_ValueChanged(object sender, int index, string text)
{
DataGridView dgs = new DataGridView();
GridViewSetter gvs = new GridViewSetter();
//gvs.SetHeaderTextOfMoreInfo()
}
private void btDownload_4_Click(object sender, EventArgs e)
{
isStopLoopDownload = false;
string errMsg = "";
string currentMaxVerNO;
if (rbSingleDown.Checked)
{
if (SingleDownload(out errMsg, out currentMaxVerNO) != 0)
{
MessageBox.Show("下载失败:" + errMsg);
}
}
else if (rbAutoDown.Checked)
{
if (AutoDownload(rbgDownItemType_4.SelectedIndex,out errMsg) != 0)
{
MessageBox.Show("下载失败:" + errMsg);
}
}
else
{
if (loopDownloadBySpecVerNO(out errMsg) != 0)
{
MessageBox.Show("下载失败:" + errMsg);
}
}
}
private void dgvDownload_4_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void dgvDirectoy_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void btnExport_Click(object sender, EventArgs e)
{
this.pgHISDirect.PageChanged -= new Sunny.UI.UIPagination.OnPageChangeEventHandler(this.pgHISDirect_PageChanged);
// 创建 DataLoader 并传递 queryExportData 方法
DataLoader _dataLoader;
_dataLoader = new DataLoader((out string errMsg) => queryExportData_CallBack(out errMsg), this);
_dataLoader.StartQueryExportData((result, errMsg) =>
{
// 在这里处理结果和错误信息
if (result == 0)
{
MessageBox.Show(errMsg);
}
else
{
MessageBox.Show(errMsg);
}
});
}
private int queryExportData(out string errMsg)
{
errMsg = "";
int currentPage = 1; int pageSize = 50;
string directoryType = string.Empty;
switch (rbgDirecType_C.SelectedIndex)
{
case 0:
{
directoryType = "drugs";
break;
}
case 1:
{
directoryType = "diagnosi";
break;
}
case 2:
{
directoryType = "consumables";
break;
}
}
JObject joHISRtn = new JObject();
JObject joRtn = new JObject();
string flag = "";
//全部是先调HIS,然后再匹配医保平台的对照关系
if (rbAll.Checked)
{
JArray jaPagination = new JArray();
JArray jaParams = new JArray();
flag = "All";
dynamic joParam = new JObject();
joParam.code = "";
joParam.descripts = "";
joParam.FindType = new JArray();
joParam.TypeID = "";
joParam.alias = tbHISDirectoryFilter.Text;
joParam.include = "Hosp";
joParam.groupID = "324";
joParam.hospID = Global.inf.hisHospitalDr;
joParam.interfaceDr = Global.inf.interfaceDr;
joParam.type = directoryType;
joParam.flag = flag;
//joParam.specInput = txtSpecFilter.Text.Trim();
jaParams.Add(joParam);
dynamic joPagination = new JObject();
joPagination.pageSize = pageSize;
//joPagination.pageSize = 2;
joPagination.currentPage = currentPage;
joPagination.sortColumn = "Code";
joPagination.sortOrder = "asc";
jaPagination.Add(joPagination);
//该服务需要改写,需要跟(CloudMedicalInsurancePlatform.Tables.MapRelation)进行关联
//joInParams.code = "09010038";
if (hIS.getHISDir(jaPagination, jaParams, out joHISRtn, out errMsg) != 0)
{
return -1;
}
int count = int.Parse(JsonHelper.getDestValue(joHISRtn, "result.TotalCount"));
if (count > pageSize)
{
joPagination["pageSize"] = count;
jaPagination = new JArray();
jaPagination.Add(joPagination);
if (hIS.getHISDir(jaPagination, jaParams, out joHISRtn, out errMsg) != 0)
{
return -1;
}
}
int defaultCount = 200;
dtExport = null;
if (count > defaultCount)
{
JArray jaHisDir = JArray.Parse(JsonHelper.getDestValue(joHISRtn, "result.Data"));
JArray jaTmp = new JArray();
for (int i = 0; i < count; i++)
{
JObject joTmp = (JObject)jaHisDir[i];
foreach (var property in joTmp.Properties())
{
if (property.Value.Type == JTokenType.Integer || property.Value.Type == JTokenType.Float)
{
property.Value = new JValue(property.Value.ToString());
}
}
jaTmp.Add(joTmp);
if ((((i + 1) % defaultCount) == 0) || (i + 1 == count))
{
JObject joConvert = new JObject();
joConvert.Add("errorCode", 0);
joConvert.Add("errorMessage", "查询成功");
JObject joResult = new JObject();
if ((i % defaultCount) == 0)
{
joResult.Add("TotalCount", defaultCount);
}
else
{
joResult.Add("TotalCount", (i + 1) % defaultCount);
}
joResult.Add("Data", jaTmp);
joConvert.Add("result", joResult);
joRtn = mIS.ConvertHISDir(joConvert);
if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
{
return -1;
}
else
{
DataTable dtTmp = (DataTable)joRtn["result"]["Data"].ToObject(typeof(DataTable));
if (dtExport == null)
{
dtExport = dtTmp.Clone();
dtExport.Merge(dtTmp);
}
else
{
dtExport.Merge(dtTmp);
}
jaTmp = new JArray();
}
}
}
}
else
{
joRtn = mIS.ConvertHISDir(joHISRtn);
if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
{
return -1;
}
dtExport = (DataTable)joRtn["result"]["Data"].ToObject(typeof(DataTable));
}
}
//已对照是先调云医保,然后再匹配HIS
if (rbMaped.Checked)
{
JArray jaPagination = new JArray();
JArray jaParams = new JArray();
flag = "Maped";
dynamic joParam = new JObject();
joParam.alias = tbHISDirectoryFilter.Text;
joParam.HospitalDr = Global.inf.hospitalDr;
joParam.InterfaceDr = Global.inf.interfaceDr;
joParam.hisType = directoryType;
jaParams.Add(joParam);
dynamic joPagination = new JObject();
joPagination.pageSize = pageSize;
joPagination.currentPage = currentPage;
joPagination.sortColumn = "HisCode";
joPagination.sortOrder = "asc";
jaPagination.Add(joPagination);
JObject joMIRtn = mIS.GetMappedHISDir(jaPagination, jaParams);
if (JsonHelper.parseIrisRtnValue(joMIRtn, out errMsg) != 0)
{
return -1;
}
//传给HIS,进行匹配
joParam = new JObject();
joParam.TotalCount = joMIRtn["result"]["TotalCount"];
joParam.type = directoryType;
joParam.flag = flag;
joParam.hospID = Global.inf.hisHospitalDr;
joParam.interfaceDr = Global.inf.interfaceDr;
joParam.alias = tbHISDirectoryFilter.Text;
joParam.include = "Hosp";
joParam.groupID = "324";
joParam.compareArr = joMIRtn["result"]["Data"];
jaParams = new JArray();
jaParams.Add(joParam);
if (hIS.getHISDir(jaPagination, jaParams, out joRtn, out errMsg) != 0)
{
return -1;
}
}
//if (rbNoMaped.Checked) { flag = "NoMaped"; }
if (rbNoMaped.Checked)
{
JArray jaPagination = new JArray();
JArray jaParams = new JArray();
flag = "All";
dynamic joParam = new JObject();
joParam.code = "";
joParam.descripts = "";
joParam.FindType = new JArray();
joParam.TypeID = "";
joParam.alias = tbHISDirectoryFilter.Text;
joParam.include = "Hosp";
joParam.groupID = "324";
joParam.hospID = Global.inf.hisHospitalDr;
joParam.interfaceDr = Global.inf.interfaceDr;
joParam.type = directoryType;
joParam.flag = flag;
joParam.specInput = "";
jaParams.Add(joParam);
dynamic joPagination = new JObject();
joPagination.pageSize = pageSize;
//joPagination.pageSize = 2;
joPagination.currentPage = currentPage;
joPagination.sortColumn = "Code";
joPagination.sortOrder = "asc";
jaPagination.Add(joPagination);
//1.获取全部HIS目录
if (hIS.getHISDir(jaPagination, jaParams, out joHISRtn, out errMsg) != 0)
{
return -1;
}
joRtn = mIS.GetNoMappHISDir(joHISRtn);
if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
{
return -1;
}
}
return 0;
}
private int queryExportData_CallBack(out string errMsg)
{
if (queryExportData(out errMsg) != 0)
{
return -1;
}
//test.Stop();
this.Invoke((MethodInvoker)delegate {
this.pgHISDirect.PageChanged += new Sunny.UI.UIPagination.OnPageChangeEventHandler(this.pgHISDirect_PageChanged);
});
if (dtExport.Rows.Count > 0)
{
string directoryType = string.Empty;
string sBZ = "";
switch (rbgDirecType_C.SelectedIndex)
{
case 0:
{
directoryType = "药品";
break;
}
case 1:
{
directoryType = "诊疗";
break;
}
case 2:
{
directoryType = "材料";
break;
}
}
if (rbAll.Checked) sBZ = "全部";
else
if (rbMaped.Checked) sBZ = "已对照";
else
if (rbNoMaped.Checked) sBZ = "未对照";
string LSH = DateTime.Now.ToString("yyyy-MM-dd"); //DateTime.Now.ToString("MMddHHmmssffff");
string filename = LSH + "(" + directoryType + ")医保目录" + sBZ + "信息.xls";
string sFliePathName = Global.curEvt.path + "\\MapRelation\\" + filename;
//string sFliePathName = @"D:\" + LSH + "(" + directoryType + ")医保目录" + sBZ + "信息.xls";
//如果不存在目录,则创建目录
if (!Directory.Exists(Global.curEvt.path + "\\MapRelation"))
{
//创建文件夹
DirectoryInfo dirInfo = Directory.CreateDirectory(Global.curEvt.path + "\\MapRelation");
}
//如存在同名文件不询问直接删除
if (File.Exists(sFliePathName))
{
File.Delete(sFliePathName);
}
//新版方法,用的EPPLUS,方便
ExportToExcel.ExportDataTableToExcel(dtExport, sFliePathName);
if (true)
{
errMsg = ($"导出成功,文件保存路径:{sFliePathName}");
return 0;
}
else
{
errMsg = ("导出失败!");
return -1;
}
}
else
{
errMsg = "查询数据集为空!";
return -1;
}
}
private void dgvHISDirectory_RowEnter(object sender, DataGridViewCellEventArgs e)
{
tbCenterDirectoryFilter.Text = "%" + dgvHISDirectory.SelectedRows[0].Cells["itemDesc"].Value.ToString() + "%";
tbApprovalNO.Text = dgvHISDirectory.SelectedRows[0].Cells["pprovalNo"].Value.ToString();
}
private void dgvHISDirectory_SelectionChanged(object sender, EventArgs e)
{
int i = dgvHISDirectory.CurrentRow.Index;
if (dgvHISDirectory.Rows[i].Cells["insuCode"].Value.ToString() != "")
{
tbInsuCode.Text = dgvHISDirectory.Rows[i].Cells["insuCode"].Value.ToString();
tbCenterDirectoryFilter.Text = "";
tbApprovalNO.Text = "";
}
else
{
tbInsuCode.Text = "";
tbCenterDirectoryFilter.Text = "%" + dgvHISDirectory.Rows[i].Cells["itemDesc"].Value.ToString() + "%";
tbApprovalNO.Text = "%" + dgvHISDirectory.Rows[i].Cells["pprovalNo"].Value.ToString() + "%";
}
}
private void btStopLoopDownload_Click(object sender, EventArgs e)
{
isStopLoopDownload = true;
}
private void tsmShowAuxInfo_Click(object sender, EventArgs e)
{
if (dgvDirectoy.CurrentRow != null)
{
// 获取当前行中 "code" 列的单元格值,并转换为字符串
string code = dgvDirectoy.CurrentRow.Cells["code"].Value?.ToString() ?? string.Empty;
LimitPriceAndSelfpayPropInfo frm = new LimitPriceAndSelfpayPropInfo(code);
frm.Show();
}
else
{
// 没有选中的行,处理这种情况
MessageBox.Show("请选择一行。");
}
}
public int UpdateDictionaryBySelf(AddSingleDictionary addDic, out string errMsg)
{
string outParam = "", HBDictionaryDr = "";
JObject joRtn;
JObject jo = addDic.joPamam;
try
{
//if (JsonHelper.getDestValue(jo, "operateType") == "0")
//{
//插入并获取字典主表的DR
JObject joDic = JObject.FromObject(jo["dicObj"]);
joRtn = mIS.insertDictionary(joDic);
if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
{
return -1;
}
else
{
HBDictionaryDr = JsonHelper.getDestValue(joRtn, "data.HBDictionaryDr");
if (HBDictionaryDr == "")
{
errMsg = "HBDictionaryDr返回值为空";
return -1;
}
}
//插入明细表
JObject joDicDetail = JObject.FromObject(jo["detailObj"]);
joDicDetail.Add("HBDictionaryDr", HBDictionaryDr);
JArray jaParams = new JArray();
jaParams.Add(joDicDetail);
joRtn = mIS.insertDictionaryDataDetail(jaParams);
if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
{
return -1;
}
else
{
return 0;
}
}
catch (Exception ex)
{
errMsg = ex.Message;
return -1;
}
}
}
}