using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Newtonsoft.Json;
using System.Windows.Forms;
using PTMedInsuInterface.Common;
using PTMedInsuInterface.Helper;
using PTMedInsuInterface.Business;
using PTMedInsuInterface.Variables;
using System.Net.Http;
namespace PTMedInsuInterface
{
public class InsuBusiness: IInsuBusiness
{
string errorCode = "0", errorMessage = "成功", result = "{}";
string Test = "000000";
private InvokeHelper invoker = new InvokeHelper();
private HisIrisServices hIS = new HisIrisServices();
private MIIrisServices mIS = new MIIrisServices();
private ShellBusiness sBus = new ShellBusiness();
private bool isServiceSeflMachine = false;
private string isNeedRedirect = "0";
public InsuBusiness()
{
sBus.getCurrentEnvironmentInfo();
}
#region 主要交易
///
/// 初始化,前端传过来接口DR,根据DR获取接口完整信息传给业务DLL
///
///
///
//public string Init(string InParam)
//{
// JObject joRtn = new JObject();
// try
// {
// if (!sBus.isExistConfig())
// {
// return JsonHelper.setExceptionJson(-1, "Init(getPlatformHospitalDr)异常", "未找到配置文件INSUConfigure.ini").ToString();
// }
// //获取Iris配置
// sBus.getHisConfingue(out Global.hisConfig);
// //获取云医保配置
// sBus.getInsuConfingue(out Global.insuConfig);
// //设置DLL 命名空间,
// sBus.getDLLInfo(out Global.dll);
// JObject joInparam = JObject.Parse(InParam);
// string hospID = JsonHelper.getDestValue(joInparam, "hospID");
// Global.inf.hisHospitalDr=Global.inf.hospitalDr = Convert.ToInt32(hospID);
// string hospDr = "";
// if (Global.curEvt.MIVer == "2")
// {
// if (mIS.getPlatformHospitalDr(hospID, out hospDr) != 0)
// {
// return JsonHelper.setExceptionJson(-1, "Init(getPlatformHospitalDr)异常", hospDr).ToString();
// }
// if (hospDr == "")
// {
// return JsonHelper.setExceptionJson(-1, "Init", "医院ID不能为空!").ToString();
// }
// Global.inf.hospitalDr = Convert.ToInt32(hospDr);
// }
// else
// hospDr = hospID;
// string interfaceDr = JsonHelper.getDestValue(joInparam, "interfaceDr");
// //如果为空则取insuAdmObj里的interfaceDr
// if (interfaceDr == "")
// {
// interfaceDr = JsonHelper.getDestValue(joInparam, "insuAdmObj.interfaceDr");
// }
// //获取接口信息
// if (interfaceDr == "")
// {
// ShellBusiness shell = new ShellBusiness();
// JObject joInterfaceResult = shell.showInterfaceChooseForm();
// if (joInterfaceResult["errorCode"].ToString() != "0")
// {
// joRtn = JsonHelper.setExceptionJson(-100, "showInterfaceChooseForm", joInterfaceResult["errorMessage"].ToString());
// return joRtn.ToString();
// }
// else
// {
// JObject joInterface = JObject.FromObject(joInterfaceResult["result"]);
// sBus.getDLLInfo(joInterface);
// joRtn = (JObject)joInterfaceResult.DeepClone();
// }
// }
// else
// {
// joRtn = mIS.getspecifiedInterface(int.Parse(hospDr), int.Parse(interfaceDr));
// if (JsonHelper.parseIrisRtnValue(joRtn,out errorMessage) != 0)
// {
// return joRtn.ToString();
// }
// else
// {
// JObject joInterface = JObject.FromObject(joRtn["result"]);
// sBus.getDLLInfo(joInterface);
// }
// }
// joRtn.Add("hisIrisUrl", Global.hisConfig.ip + "//" + Global.hisConfig.url);
// joRtn.Add("insuIrisUrl", Global.insuConfig.ip + "//" + Global.insuConfig.url);
// return joRtn.ToString();
// }
// catch (Exception e)
// {
// joRtn = JsonHelper.setExceptionJson(-1, "Init", e.Message );
// return joRtn.ToString();
// }
// finally
// {
// Global.writeLog("Init", InParam, joRtn.ToString());
// }
//}
public string Init(string InParam)
{
Global.writeLog($"入参:{InParam}");
JObject joRtn = new JObject();
try
{
if (!sBus.isExistConfig())
{
return JsonHelper.setExceptionJson(-1, "Init(getPlatformHospitalDr)异常", "未找到配置文件INSUConfigure.ini").ToString();
}
//获取Iris配置
sBus.getHisConfingue(out Global.hisConfig);
//获取云医保配置
sBus.getInsuConfingue(out Global.insuConfig);
//设置DLL 命名空间,
sBus.getDLLInfo(out Global.dll);
JObject joInparam = JObject.Parse(InParam);
string hospID = JsonHelper.getDestValue(joInparam, "hospID");
Global.inf.hisHospitalDr = Global.inf.hospitalDr = Convert.ToInt32(hospID);
string hospDr = "";
if (Global.curEvt.MIVer.Trim() == "2")
{
if (mIS.getPlatformHospitalDr(hospID, out hospDr) != 0)
{
return JsonHelper.setExceptionJson(-1, "Init(getPlatformHospitalDr)异常", hospDr).ToString();
}
if (hospDr == "")
{
return JsonHelper.setExceptionJson(-1, "Init", "医院ID不能为空!").ToString();
}
Global.inf.hospitalDr = Convert.ToInt32(hospDr);
}
else
hospDr = hospID;
string interfaceDr = JsonHelper.getDestValue(joInparam, "interfaceDr");
//如果为空则取insuAdmObj里的interfaceDr
if (interfaceDr == "")
{
interfaceDr = JsonHelper.getDestValue(joInparam, "insuAdmObj.interfaceDr");
}
//获取接口信息
if (interfaceDr == "")
{
//如果是自助机,则选择自助机的接口
if (isServiceSeflMachine)
{
joRtn = mIS.getSelfServiceInterface();
isNeedRedirect = "1";
}
else
{
ShellBusiness shell = new ShellBusiness();
joRtn = shell.showInterfaceChooseForm();
}
}
else
{
joRtn = mIS.getspecifiedInterface(int.Parse(hospDr), int.Parse(interfaceDr));
}
if (JsonHelper.parseIrisRtnValue(joRtn, out errorMessage) != 0)
{
return joRtn.ToString();
}
else
{
JObject joInterface = JObject.FromObject(joRtn["result"]);
sBus.getDLLInfo(joInterface);
}
joRtn.Add("hisIrisUrl", Global.hisConfig.ip + "//" + Global.hisConfig.url);
joRtn.Add("insuIrisUrl", Global.insuConfig.ip + "//" + Global.insuConfig.url);
return joRtn.ToString();
}
catch (Exception e)
{
joRtn = JsonHelper.setExceptionJson(-1, "Init", e.Message);
return joRtn.ToString();
}
finally
{
Global.writeLog("Init", InParam, joRtn.ToString());
}
}
public string GetPatientInfo(string InParam)
{
Global.writeLog_debug($"调用单例模式类,程序应用域(shell):{AppDomain.CurrentDomain.FriendlyName}--{AppDomain.CurrentDomain.Id}");
//return JsonHelper.setIrisReturnValue(-1,"测试",null).ToString();
return Transact("GetPatientInfo", InParam);
}
public string Register(string InParam)
{
return Transact("Register", InParam);
}
public string FeeUpload(string InParam)
{
return Transact("FeeUpload", InParam);
}
public string Settlement(string InParam)
{
return Transact("Settlement", InParam);
}
public string AgentFun(string InParam)
{
return Transact("AgentFun", InParam);
}
public string PlatformDirectConnect(string InParam)
{
string outParam = string.Empty;
JObject joRtn = new JObject();
JObject joInparam = new JObject();
try
{
//获取Iris配置
sBus.getHisConfingue(out Global.hisConfig);
//获取云医保配置
sBus.getInsuConfingue(out Global.insuConfig);
joInparam = JObject.Parse(InParam);
string interfaceInfo = JsonHelper.getDestValue(joInparam, "interfaceinfo");
JObject joInterfaceInfo;
if (interfaceInfo == "")
{ joInterfaceInfo = null; }
else
{ joInterfaceInfo = JObject.Parse(interfaceInfo); }
if (joInterfaceInfo != null)
{
Global.dll.name = JsonHelper.getDestValue(joInterfaceInfo, "dLLName");
Global.dll.nameSpace = "PTMedicalInsurance";
}
else
{
string hospID = JsonHelper.getDestValue(joInparam, "hospID");
string interfaceDr = JsonHelper.getDestValue(joInparam, "interfaceDr");
joInterfaceInfo = mIS.getspecifiedInterface(int.Parse(hospID), int.Parse(interfaceDr));
if (JsonHelper.parseIrisRtnValue(joInterfaceInfo, out errorMessage) != 0)
{
joRtn = JsonHelper.setExceptionJson(-100, "PlatformDirectConnect", errorMessage);
outParam = joRtn.ToString();
return outParam;
}
else
{
Global.dll.name = JsonHelper.getDestValue(joInterfaceInfo, "result.DLLName");
Global.dll.nameSpace = "PTMedicalInsurance";
joInparam.Add("interfaceinfo", JObject.Parse(JsonHelper.getDestValue(joInterfaceInfo, "result")));
}
}
InvokeHelper bus = new InvokeHelper();
joRtn = bus.InvokeBusinessDLL("PlatformDirectConnect", joInparam.ToString());
outParam = joRtn.ToString();
return outParam;
}
catch (Exception ex)
{
joRtn = JsonHelper.setExceptionJson(-100, "PlatformDirectConnect", ex.Message);
outParam = joRtn.ToString();
return outParam;
}
finally
{
Global.writeLog("PlatformDirectConnect", InParam, outParam);
}
}
public string SelfServiceMachine(string InParam)
{
isServiceSeflMachine = true;
return Transact("SelfServiceMachine", InParam);
}
#endregion
#region 私有交易
///
/// 交易封装
///
private string Transact(string transName,string inParam)
{
string outParam = string.Empty, errorMsg = "", businessType = "";
JObject joRtn ;
JObject joInparam;
try
{
joInparam = JObject.Parse(inParam);
businessType = JsonHelper.getDestValue(joInparam, "businessType");
string initRtn = Init(inParam);
JObject joInit = JObject.Parse(initRtn);
if (JsonHelper.parseIrisRtnValue(joInit, out errorMsg) != 0)
{
outParam = JsonHelper.setExceptionJson(-100, "初始化失败", errorMsg).ToString();
return outParam;
}
JObject joInterface = JObject.FromObject(joInit["result"]);
//组织业务DLL入参
JObject joBusInparam= JObject.FromObject(joInparam.DeepClone());
joBusInparam.Add("interfaceinfo", joInterface);
if (isServiceSeflMachine)
{
joBusInparam.Add("isNeedRedirect", isNeedRedirect);
}
InvokeHelper bus = new InvokeHelper();
JObject joPaitientInfo = bus.InvokeBusinessDLL(transName, joBusInparam.ToString());
if (joPaitientInfo["errorCode"].ToString() != "0")
{
outParam = joPaitientInfo.ToString();
return outParam;
}
else
{
joRtn = new JObject();
dynamic joResult = new JObject();
//List lst = new List { "Settlement", "SelfServiceMachine" };
//if (lst.Contains(transName)) //不这样写的话,住院结算后HIS前端一直转圈
//{
// joRtn = joPaitientInfo;
//}
//else
//{
// joResult.patientInfo = joPaitientInfo["result"];
// joResult.interfaceInfo = joInit;
// joRtn.Add("result", JObject.FromObject(joResult));
// joRtn.Add("errorCode", 0);
// joRtn.Add("errorMessage", "");
//}
List lst = new List { "GetPatientInfo" };
if (lst.Contains(transName) || lst.Contains(businessType)) //不这样写的话,住院结算后HIS前端一直转圈
{
joResult.patientInfo = joPaitientInfo["result"];
joResult.interfaceInfo = joInit;
joRtn.Add("result", JObject.FromObject(joResult));
joRtn.Add("errorCode", 0);
joRtn.Add("errorMessage", "");
}
else
{
joRtn = joPaitientInfo;
}
outParam = joRtn.ToString();
return outParam;
}
}
catch (Exception ex)
{
String innerMessage = (ex.InnerException != null)
? ex.InnerException.Message
: "";
joRtn = JsonHelper.setExceptionJson(-100, transName, "aa"+ex.Message + innerMessage);
outParam = joRtn.ToString();
return outParam;
}
finally
{
Global.writeLog(transName, inParam, outParam);
}
}
#endregion
}
}