完成HIS调用webservice

This commit is contained in:
falcon 2019-03-01 15:52:36 +08:00
parent 7c5e81c1af
commit 8730d5366d
5 changed files with 80 additions and 11 deletions

View File

@ -153,6 +153,8 @@
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Dal\Wappers\HisDrugInfoWapper.cs" />
<Compile Include="Dal\Wappers\HisPrescriptyInfoWapper.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\TestController.cs" />
<Compile Include="Dal\DjyDbContext.cs" />
@ -211,6 +213,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
<Folder Include="Bll\" />
<Folder Include="Models\" />
<Folder Include="Views\Test\" />
</ItemGroup>

View File

@ -13,7 +13,7 @@ namespace Cmdjy.Dal
public partial class DjyDbContext:DbContext
{
public DjyDbContext() : base("DjyDbContext") {
Database.SetInitializer<DjyDbContext>(null);
//Database.SetInitializer<DjyDbContext>(null);
}
}
/// <summary>

View File

@ -0,0 +1,18 @@
namespace Cmdjy.Dal.Wappers
{
/// <summary>
/// 药品信息墙纸
/// </summary>
public class HisDrugInfoWapper:Dal.Tables.HisDrugInfo
{
public HisDrugInfoWapper(ws.HisDrugInfo s) {
if(s == null) return;
foreach(var p in s.GetType().GetProperties()) {
var tp = this.GetType().GetProperty(p.Name);
if(tp != null && tp.CanWrite && p.CanRead) {
tp.SetValue(this,p.GetValue(s));
}
}
}
}
}

View File

@ -0,0 +1,15 @@
namespace Cmdjy.Dal.Wappers
{
public class HisPrescriptyInfoWapper:Dal.Tables.HisPrescriptionInfo
{
public HisPrescriptyInfoWapper(ws.HisPrescriptionInfo s) {
if(s == null) return;
foreach(var p in s.GetType().GetProperties()) {
var tp = this.GetType().GetProperty(p.Name);
if(tp != null && tp.CanWrite && p.CanRead) {
tp.SetValue(this,p.GetValue(s));
}
}
}
}
}

View File

@ -4,6 +4,9 @@ using System.Linq;
using System.Web;
using System.Web.Services;
using Newtonsoft.Json;
using Cmdjy.Dal;
using Cmdjy.Dal.Wappers;
using System.Data.Entity;
namespace Cmdjy.ws
{
@ -20,21 +23,51 @@ namespace Cmdjy.ws
[WebMethod(Description = "医疗机构上传处方信息")]
public string PostPrescriptionInfo(HisPrescriptionInfo info) {
var json = JsonConvert.SerializeObject(info);
var result = new HisPrescriptionResult {
Code = ResultCode.Success,PrescriptionId = "1",
Msg = json,
};
HisPrescriptionResult result = null;
using(var db = new DjyDbContext()) {
var en = new HisPrescriptyInfoWapper(info) as Dal.Tables.HisPrescriptionInfo;
en.RawAddress = this.Context.Request.UserHostAddress;
en.CreateDatetime = DateTime.Now;
db.Entry(en).State = EntityState.Added;
try {
db.SaveChanges();
result = new HisPrescriptionResult {
Code = ResultCode.Success,PrescriptionId = en.Id.ToString(),
Msg = "保存成功",
};
}
catch(Exception ex) {
result = new HisPrescriptionResult {
Code = ResultCode.Exception,PrescriptionId = "0",
Msg = ex.ToString(),
};
}
}
return JsonConvert.SerializeObject(result);
}
[WebMethod(Description = "医疗机构上传药品信息")]
public string PostDrugInfo(HisDrugInfo info) {
var json = JsonConvert.SerializeObject(info);
var result = new HisDrugResult {
Code = ResultCode.Success,DrugId = "1",
Msg = json,
};
HisDrugResult result = null;
using(var db = new DjyDbContext()) {
var en = new HisDrugInfoWapper(info) as Dal.Tables.HisDrugInfo;
en.RawAddress = this.Context.Request.UserHostAddress;
en.CreateDatetime = DateTime.Now;
db.Entry(en).State = EntityState.Added;
try {
db.SaveChanges();
result = new HisDrugResult {
Code = ResultCode.Success,DrugId = en.Id.ToString(),
Msg = "保存成功",
};
}
catch(Exception ex) {
result = new HisDrugResult {
Code = ResultCode.Exception,DrugId = "0",
Msg = ex.ToString(),
};
}
}
return JsonConvert.SerializeObject(result);
}
}