5 changed files with 342 additions and 98 deletions
-
2src/Shentun.Peis.Application.Contracts/DiagnosisFunctions/GetDiagnosisResultRequestDto.cs
-
2src/Shentun.Peis.Application/DiagnosisFunctions/CodeBuilder.cs
-
192src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisBuilder.cs
-
127src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs
-
117test/Shentun.Peis.Application.Tests/DiagnosisFunctionAppServiceTest.cs
@ -0,0 +1,192 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Reflection; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Shentun.Peis.DiagnosisFunctions |
||||
|
{ |
||||
|
public class DiagnosisBuilder |
||||
|
{ |
||||
|
private string GetResult(string codeInput, string className, string patientClassName, object patient) |
||||
|
{ |
||||
|
if (string.IsNullOrWhiteSpace(className)) |
||||
|
{ |
||||
|
throw new Exception("className不能为空"); |
||||
|
} |
||||
|
if (string.IsNullOrWhiteSpace(patientClassName)) |
||||
|
{ |
||||
|
throw new Exception("patientClassName不能为空"); |
||||
|
} |
||||
|
if (patient == null) |
||||
|
{ |
||||
|
throw new Exception("patient不能为空"); |
||||
|
} |
||||
|
if (string.IsNullOrWhiteSpace(codeInput)) |
||||
|
{ |
||||
|
throw new Exception("codeInput不能为空"); |
||||
|
} |
||||
|
string result = ""; |
||||
|
|
||||
|
string code = @"
|
||||
|
using System; |
||||
|
using System.IO; |
||||
|
using System.Collections; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Collections.Concurrent; |
||||
|
using System.Linq; |
||||
|
using Shentun.Peis.DiagnosisFunctions; |
||||
|
|
||||
|
public class " + className + @" |
||||
|
{ |
||||
|
public string GetResult(" + patientClassName + @" patient) |
||||
|
{ |
||||
|
"
|
||||
|
+ codeInput + @"
|
||||
|
|
||||
|
} |
||||
|
} |
||||
|
";
|
||||
|
|
||||
|
CodeBuilder codeBuilder = new CodeBuilder(); |
||||
|
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); |
||||
|
|
||||
|
|
||||
|
var assembly = codeBuilder.GenerateAssemblyFromCode(code); |
||||
|
if (assembly != null) |
||||
|
{ |
||||
|
|
||||
|
// 反射获取程序集中 的类
|
||||
|
Type type = assembly.GetType(className); |
||||
|
|
||||
|
// 创建该类的实例
|
||||
|
object obj = Activator.CreateInstance(type); |
||||
|
object[] objects = { patient }; |
||||
|
; |
||||
|
var msg = type.InvokeMember("GetResult", |
||||
|
BindingFlags.Default | BindingFlags.InvokeMethod, |
||||
|
null, |
||||
|
obj, |
||||
|
objects); |
||||
|
if (msg == null) |
||||
|
{ |
||||
|
return ""; |
||||
|
} |
||||
|
if (!string.IsNullOrEmpty(msg.ToString())) |
||||
|
{ |
||||
|
result = msg.ToString(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 获取计算项目结果
|
||||
|
/// </summary>
|
||||
|
/// <param name="patient"></param>
|
||||
|
/// <param name="codeInput"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public string GetItemCalculateResult(PatientItemCalculateInput patient, string codeInput) |
||||
|
{ |
||||
|
return GetResult(codeInput, "ItemCalculateResult", "PatientItemCalculateInput", patient); |
||||
|
|
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 获取项目诊断结果
|
||||
|
/// </summary>
|
||||
|
/// <param name="patient"></param>
|
||||
|
/// <param name="codeInput"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public string GetItemDiagnosisResult(PatientItemDiagnosisInput patient, string codeInput) |
||||
|
{ |
||||
|
return GetResult(codeInput, "ItemDiagnosisResult", "PatientItemDiagnosisInput", patient); |
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 获取组合项目诊断结果
|
||||
|
/// </summary>
|
||||
|
/// <param name="patient"></param>
|
||||
|
/// <param name="codeInput"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public string GetAsbitemDiagnosisResult(PatientAsbitemDiagnosisInput patient, string codeInput) |
||||
|
{ |
||||
|
return GetResult(codeInput, "AsbitemDiagnosisResult", "PatientAsbitemDiagnosisInput", patient); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 计算项目输入参数类
|
||||
|
/// </summary>
|
||||
|
public class PatientItemCalculateInput |
||||
|
{ |
||||
|
public string SexName { get; set; } |
||||
|
public short? Age { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 计算项目ID
|
||||
|
/// </summary>
|
||||
|
public Guid ItemId { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 计算项目名称
|
||||
|
/// </summary>
|
||||
|
public string ItemName { get; set; } |
||||
|
public List<ItemResultInput> Items { get; set; } = new List<ItemResultInput>(); |
||||
|
|
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 项目诊断输入参数类
|
||||
|
/// </summary>
|
||||
|
public class PatientItemDiagnosisInput |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 性别名称
|
||||
|
/// </summary>
|
||||
|
public string SexName { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 年龄
|
||||
|
/// </summary>
|
||||
|
public short? Age { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 诊断项目ID
|
||||
|
/// </summary>
|
||||
|
public Guid ItemId { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 诊断项目名称
|
||||
|
/// </summary>
|
||||
|
public List<ItemResultInput> Items { get; set; } = new List<ItemResultInput>(); |
||||
|
|
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 组合项目诊断输入参数类
|
||||
|
/// </summary>
|
||||
|
public class PatientAsbitemDiagnosisInput |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 性别名称
|
||||
|
/// </summary>
|
||||
|
public string SexName { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 年龄
|
||||
|
/// </summary>
|
||||
|
public short? Age { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 组合项目ID
|
||||
|
/// </summary>
|
||||
|
public Guid AsbitemId { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 组合项目名称
|
||||
|
/// </summary>
|
||||
|
public string AsbitemName { get; set; } |
||||
|
public List<ItemResultInput> Items { get; set; } = new List<ItemResultInput>(); |
||||
|
|
||||
|
} |
||||
|
/// <summary>
|
||||
|
/// 项目结果
|
||||
|
/// </summary>
|
||||
|
public class ItemResultInput |
||||
|
{ |
||||
|
public Guid ItemId { get; set; } |
||||
|
public string ItemName { get; set; } |
||||
|
public string Result { get; set; } |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue