| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- using Microsoft.CodeDom.Providers.DotNetCompilerPlatform;
- using Newtonsoft.Json;
- using RMYY_CallCenter_Api.Utility;
- using System;
- using System.CodeDom;
- using System.CodeDom.Compiler;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Reflection;
- using System.Text;
- using System.Web;
- using System.Web.Mvc;
- using System.Web.Services.Description;
- using System.Xml;
- using System.Xml.Linq;
- namespace RMYY_CallCenter_Api.Controllers
- {
- [AllowAnonymous]
- public class PatientController : BaseController
- {
-
- // private static string url = $"http://172.16.0.177:8081/winempi/webapi/";
- // private static string url1 = "http://172.16.0.197:10045/winempi/webapi/";
- private string url = ConfigHelper.GetValue("PatientURL");
- private string wsdlURL = ConfigHelper.GetValue("wsdlURL");
- public class Patient
- {
- public string zsyh { set; get; }//主索引号
- public string hzxm { set; get; }//患者姓名
- public string csrq { set; get; }//出生日期
- public string xbdm { set; get; }//性别代码
- public string xbmc { set; get; }//性别名称
- public string hydm { set; get; }//婚姻代码
- public string hymc { set; get; }//婚姻名称
- public string zjhm { set; get; }//身份证号码
- public string zjlx { set; get; }//身份证类型
- public string lxdh { set; get; }//联系电话
- public string mz { set; get; }//民族
- public string gj { set; get; }//国籍
- public string jtdz { set; get; }//家庭地址
- public string cResult { set; get; }//返回结果描述
- public string ncount { set; get; }//符合查询的数量
- }
-
- public ActionResult GetModelList(string zsyh="",string hzxm="",string sfzh=""
- ,string zlkh="",string jzlx="",string jzh="",string lxdh="")
- {
- Dictionary<string, string> values = new Dictionary<string, string>();
- values.Add("zsyh", zsyh);//主索引号
- values.Add("hzxm", hzxm);//患者姓名
- values.Add("sfzh", sfzh);//身份证号
- values.Add("zlkh", zlkh);//诊疗卡号
- values.Add("jzlx", jzlx);//就诊类型
- values.Add("jzh", jzh);//就诊号
- values.Add("lxdh", lxdh);//联系电话
- try
- {
- var responseString = HttpMethods.HttpPost(url + "QueryPatient", values.ToJson(), "application/json;charset=UTF-8");
- LogHelper.Warn("responseString"+ responseString);
- List<Patient> jo = JsonConvert.DeserializeObject<List<Patient>>(responseString);
- var obj = new
- {
- rows = jo
- };
- return Content(obj.ToJson());
- }
- catch(Exception e)
- {
- return Error(e.Message);
- }
- }
- string SOAPAction = ConfigHelper.GetValue("SOAPAction");
- public ActionResult GetRcord(string starttime, string endtime, string PatientClass, string GlobalPID, string Facility)
- {
- // string url = wsdlURL;
- string arg = "action=QueryPatientVisitByID&inxml="+ LoadXmls(starttime, endtime, PatientClass, GlobalPID, Facility);
- Dictionary<string, string> values = new Dictionary<string, string>();
- values.Add("action", "QueryPatientVisitByID");//主索引号
- values.Add("inxml", LoadXmls(starttime, endtime, PatientClass, GlobalPID, Facility));//患者姓名
- var responseString = HttpMethods.HttpPost(url + "controller", values.ToJson (), "text/xml;charset=utf-8");
- return Success("", responseString);
- Hashtable header = new Hashtable();
- header.Add("SOAPAction", SOAPAction);
- string contenttype = "text/xml;charset=utf-8";
- try
- {
- string filexml = Http(url, "post", contenttype, header, LoadXmls(starttime, endtime, PatientClass, GlobalPID, Facility));
- // LogHelper.Warn("responseString" + responseString);
- // List<Patient> jo = JsonConvert.DeserializeObject<List<Patient>>(responseString);
- //var obj = new
- //{
- // rows = jo
- //};
- // return Content(obj.ToJson());
- return Success("", filexml);
- }
- catch (Exception e)
- {
- return Error(e.Message);
- }
- // string contenttype = "text/xml;charset=utf-8";
- // Hashtable header = new Hashtable();
- // header.Add("action", "QueryPatientVisitByID");
- // header.Add("inxml", LoadXmls(starttime, endtime, PatientClass, GlobalPID));
- //try
- //{
- // // string filexml = Http(url, "post", contenttype, header, null);
- // var filexml = InvokeWebService(url, "controller", arg);
- // return Success("", filexml);
- // // XmlDocument xmlDoc = new XmlDocument();
- // // xmlDoc.LoadXml(filexml);//Load加载XML文件,LoadXML加载XML字符串
- // //string value = xmlDoc.DocumentElement["soap:Body"]["SearchWeekWorkPlanResponse"]["SearchWeekWorkPlanResult"].InnerText;
- // //XDocument doc = XDocument.Parse(value);
- // //var xmlDocument = new XmlDocument();
- // //using (var xmlReader = doc.CreateReader())
- // //{
- // // xmlDocument.Load(xmlReader);
- // //}
- // //var model = Newtonsoft.Json.JsonConvert.SerializeXmlNode(xmlDocument);
- // // return Content(model);
- //}
- //catch (Exception e)
- //{
- // return Error(e.ToString());
- //}
- }
- /// <summary>
- /// 接口入参拼接PatientClassI-入院,O-门诊,E-急诊
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public string LoadXmls(string starttime,string endtime,string PatientClass,string GlobalPID,string Facility)
- {
-
- StringBuilder stringBuilder = new StringBuilder();
- // stringBuilder.Append(@"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:tem='http://tempuri.org/'>
- // <soapenv:Header />
- // <soapenv:Body >
- //<tem:controller >
- // <!--Optional:-->
- // <action>QueryPatientVisitByID</action>
- // <tem:xml > ");
- stringBuilder.Append($"<ConfigHeader><Facility>41604745</Facility><Application>41604745</Application></ConfigHeader>");
- stringBuilder.Append($"<QueryParameter>");
- stringBuilder.Append($"<FromLimit></FromLimit><ToLimit></ToLimit>");
- stringBuilder.Append($"<FromDateTime>{starttime}</FromDateTime><ToDateTime>{endtime}</ToDateTime>");
- stringBuilder.Append($"<PatientClass>{PatientClass}</PatientClass>");//PatientClassI-入院,O-门诊,E-急诊
- stringBuilder.Append(@"<VisitNumbers>");
- stringBuilder.Append($"<CardID></CardID>");
- stringBuilder.Append($"<DomainCode></DomainCode>");
- stringBuilder.Append($"<Facility>{Facility}</Facility>");//院区代码
- stringBuilder.Append(@"</VisitNumbers>");
- stringBuilder.Append($"<GlobalPID>{GlobalPID}</GlobalPID>");//患者主索引号
- //stringBuilder.Append(@"<PatientIDs\PatientID>");
- //stringBuilder.Append($"<CardID></CardID>");
- //stringBuilder.Append($"<DomainCode></DomainCode>");
- //stringBuilder.Append($"<Facility>{Facility}</Facility>");//院区代码
- //stringBuilder.Append(@"<PatientIDs\PatientID>");
- stringBuilder.Append($"</QueryParameter>");
- // stringBuilder.Append(@"</tem:xml>
- // </tem:controller>
- // </soapenv:Body>
- //</soapenv:Envelope> ");
- return stringBuilder.ToString();
- }
- /// <summary>
- /// 实例化WebServices
- /// </summary>
- /// <param name="url">WebServices地址</param>
- /// <param name="methodname">调用的方法</param>
- /// <param name="args">把webservices里需要的参数按顺序放到这个object[]里</param>
- public static object InvokeWebService(string url, string methodname, object[] args)
- {
- //这里的namespace是需引用的webservices的命名空间,我没有改过,也可以使用。也可以加一个参数从外面传进来。
- string @namespace = "client";
- try
- {
- //获取WSDL
- WebClient wc = new WebClient();
- Stream stream = wc.OpenRead(url);
- ServiceDescription sd = ServiceDescription.Read(stream);
- string classname = sd.Services[0].Name;
- ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
- sdi.AddServiceDescription(sd, "", "");
- CodeNamespace cn = new CodeNamespace(@namespace);
- //生成客户端代理类代码
- CodeCompileUnit ccu = new CodeCompileUnit();
- ccu.Namespaces.Add(cn);
- sdi.Import(cn, ccu);
- CSharpCodeProvider csc = new CSharpCodeProvider();
- //ICodeCompiler icc = csc.CreateCompiler();
- //设定编译参数
- CompilerParameters cplist = new CompilerParameters();
- cplist.GenerateExecutable = false; //动态编译后的程序集不生成可执行文件
- cplist.GenerateInMemory = true; //动态编译后的程序集只存在于内存中,不在硬盘的文件上
- cplist.ReferencedAssemblies.Add("System.dll");
- cplist.ReferencedAssemblies.Add("System.XML.dll");
- cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
- cplist.ReferencedAssemblies.Add("System.Data.dll");
- //编译代理类
- CompilerResults cr = csc.CompileAssemblyFromDom(cplist, ccu);
- if (true == cr.Errors.HasErrors)
- {
- StringBuilder sb = new StringBuilder();
- foreach (CompilerError ce in cr.Errors)
- {
- sb.Append(ce.ToString());
- sb.Append(Environment.NewLine);
- }
- throw new Exception(sb.ToString());
- }
- //生成代理实例,并调用方法
- Assembly assembly = cr.CompiledAssembly;
- Type t = assembly.GetType(@namespace + "." + classname, true, true);
- object obj = Activator.CreateInstance(t);
- MethodInfo mi = t.GetMethod(methodname);
- //注:method.Invoke(o, null)返回的是一个Object,如果你服务端返回的是DataSet,这里也是用(DataSet)method.Invoke(o, null)转一下就行了,method.Invoke(0,null)这里的null可以传调用方法需要的参数,string[]形式的
- return mi.Invoke(obj, args);
- }
- catch (Exception e)
- {
- return e ;
- }
- }
- /// <summary>
- /// 调用soap协议接口 webservice wsdl
- /// </summary>
- /// <param name="url"></param>
- /// <param name="method"></param>
- /// <param name="contenttype"></param>
- /// <param name="header"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- public static string Http(string url, string method = "post", string contenttype = "text/xml;charset=utf-8", Hashtable header = null, string data = null)
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- request.Method = string.IsNullOrEmpty(method) ? "post" : method;
- request.ContentType = string.IsNullOrEmpty(contenttype) ? "text/xml;charset=utf-8" : contenttype;
- if (header != null)
- {
- foreach (var i in header.Keys)
- {
- request.Headers.Add(i.ToString(), header[i].ToString());
- }
- }
- if (!string.IsNullOrEmpty(data))
- {
- Stream RequestStream = request.GetRequestStream();
- byte[] bytes = Encoding.UTF8.GetBytes(data);
- RequestStream.Write(bytes, 0, bytes.Length);
- RequestStream.Close();
- }
- HttpWebResponse response;
- try
- {
- response = (HttpWebResponse)request.GetResponse();
- }
- catch (WebException ex)
- {
- response = (HttpWebResponse)ex.Response;
- }
-
- Stream ResponseStream = response.GetResponseStream();
- StreamReader StreamReader = new StreamReader(ResponseStream, Encoding.GetEncoding("utf-8"));
- string re = StreamReader.ReadToEnd();
- StreamReader.Close();
- ResponseStream.Close();
- return re;
- }
- }
- }
|