wsd_djy/WebSiteCode/Cmdjy/CmdjyHisFront/Bll/PostHelper.cs

112 lines
4.1 KiB
C#
Raw Normal View History

2019-03-26 08:46:52 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CommonClass.Factory;
using CmdjyHisFront.Dal;
using HisInterfaceModels;
using CommonHelper;
using Newtonsoft.Json;
2019-03-26 11:09:57 +08:00
using CmdjyHisFront.Dal.Tables;
2019-03-26 08:46:52 +08:00
namespace CmdjyHisFront.Bll
{
public interface IPostHelper
{
void PostPrescription();
2019-03-26 11:09:57 +08:00
void PostPrescriptionById(int id);
2019-03-26 08:46:52 +08:00
void PostDrug();
2019-03-26 11:09:57 +08:00
void PostDrugByDrugId(int id);
void PostDrugByPrescriptionId(int id);
2019-03-26 08:46:52 +08:00
}
public class PostHelper:IPostHelper, IRegisterBaseInterface
{
public Lazy<HisFrontDbContext> Db { get; set; }
public void PostDrug() {
2019-03-26 11:09:57 +08:00
var db = this.Db.Value;
var qu = db.DrugInfo.Join(db.DrugInfoLogs,a => a.Id,b => b.HisDrugInfoId,(a,b) => new { info = a,log = b,})
.Where();
2019-03-26 08:46:52 +08:00
}
public void PostPrescription() {
throw new NotImplementedException();
}
2019-03-26 11:09:57 +08:00
public void PostPrescriptionById(int id) {
var qu = this.Db.Value.PrescriptionInfo.Where(m => m.Id == id);
if(!qu.Any()) {
throw new Exception($"处方没有找到,编号{id}。");
}
var data = new HisPrescriptionInfo();
data.CopyFrom(qu.First());
var result = prescription(data);
var model = new DjyPrescriptionInfoLog();
if(int.TryParse(result.PrescriptionId,out var ipid)) {
model.PrescriptionId = ipid;
}
model.HisPrescriptionInfoId = id;
model.PostDatatime = DateTime.Now;
model.ResultCode = (int)result.Code;
model.ResultMsg = result.Msg;
this.Db.Value.Entry(model).State = System.Data.Entity.EntityState.Added;
this.Db.Value.SaveChanges();
}
public void PostDrugByDrugId(int id) {
var db = this.Db.Value;
var qu = db.DrugInfo.Where(m => m.Id == id);
if(!qu.Any()) {
throw new Exception($"药品没有找到,编号{id}");
}
var data = new HisDrugInfo();
data.CopyFrom(qu.First());
var result = drug(data);
var model = new DjyDrugInfoLog();
if(int.TryParse(result.DrugId,out var idid)) {
model.DrugId = idid;
}
model.HisDrugInfoId = id;
model.PostDatatime = DateTime.Now;
model.ResultCode = (int)result.Code;
model.ResultMsg = result.Msg;
db.Entry(model).State = System.Data.Entity.EntityState.Added;
db.SaveChanges();
}
public void PostDrugByPrescriptionId(int id) {
var db = this.Db.Value;
var qu = db.DrugInfo.Where(m => m.PrescriptionId == id);
foreach(var item in qu) {
var data = new HisDrugInfo();
data.CopyFrom(item);
var result = drug(data);
var model = new DjyDrugInfoLog();
if(int.TryParse(result.DrugId,out var idid)) {
model.DrugId = idid;
}
model.HisDrugInfoId = id;
model.PostDatatime = DateTime.Now;
model.ResultCode = (int)result.Code;
model.ResultMsg = result.Msg;
db.Entry(model).State = System.Data.Entity.EntityState.Added;
db.SaveChanges();
}
}
2019-03-26 08:46:52 +08:00
private HisPrescriptionResult prescription(HisPrescriptionInfo info) {
using(var server = new HisServer.HisInterfaceSoapClient()) {
var msg = JsonConvert.SerializeObject(info);
return JsonConvert.DeserializeObject<HisPrescriptionResult>(msg);
}
}
private HisDrugResult drug(HisDrugInfo info) {
using(var server = new HisServer.HisInterfaceSoapClient()) {
var msg = JsonConvert.SerializeObject(info);
return JsonConvert.DeserializeObject<HisDrugResult>(msg);
}
}
}
}