From aeba4ae9363dcf508c5b8a3300aa01dbebc0444d Mon Sep 17 00:00:00 2001
From: "DESKTOP-G961P6V\\Zhh" <839860190@qq.com>
Date: Fri, 12 Apr 2024 17:55:28 +0800
Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E7=BB=93=E6=9E=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../GetDiagnosisResultRequestDto.cs | 2 +-
.../DiagnosisFunctions/CodeBuilder.cs | 2 +-
.../DiagnosisFunctions/DiagnosisBuilder.cs | 192 ++++++++++++++++++
.../DiagnosisFunctionAppService.cs | 127 ++++--------
.../DiagnosisFunctionAppServiceTest.cs | 117 +++++++++--
5 files changed, 342 insertions(+), 98 deletions(-)
create mode 100644 src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisBuilder.cs
diff --git a/src/Shentun.Peis.Application.Contracts/DiagnosisFunctions/GetDiagnosisResultRequestDto.cs b/src/Shentun.Peis.Application.Contracts/DiagnosisFunctions/GetDiagnosisResultRequestDto.cs
index 42f0f4c..4e6a583 100644
--- a/src/Shentun.Peis.Application.Contracts/DiagnosisFunctions/GetDiagnosisResultRequestDto.cs
+++ b/src/Shentun.Peis.Application.Contracts/DiagnosisFunctions/GetDiagnosisResultRequestDto.cs
@@ -31,7 +31,7 @@ namespace Shentun.Peis.DiagnosisFunctions
///
/// 项目ID Item表 不是RegisterCheckItem
///
- public Guid? ItemId { get; set; }
+ public Guid ItemId { get; set; }
///
/// 项目结果
diff --git a/src/Shentun.Peis.Application/DiagnosisFunctions/CodeBuilder.cs b/src/Shentun.Peis.Application/DiagnosisFunctions/CodeBuilder.cs
index ef19b51..09acd89 100644
--- a/src/Shentun.Peis.Application/DiagnosisFunctions/CodeBuilder.cs
+++ b/src/Shentun.Peis.Application/DiagnosisFunctions/CodeBuilder.cs
@@ -59,7 +59,7 @@ namespace Shentun.Peis.DiagnosisFunctions
// return myAssembly;
//}
- public Assembly GenerateAssemblyFromCode(string code, params Assembly[] referencedAssemblies)
+ public Assembly GenerateAssemblyFromCode(string code)
{
Assembly assembly = null;
diff --git a/src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisBuilder.cs b/src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisBuilder.cs
new file mode 100644
index 0000000..ee26726
--- /dev/null
+++ b/src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisBuilder.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;
+ }
+ ///
+ /// 获取计算项目结果
+ ///
+ ///
+ ///
+ ///
+ public string GetItemCalculateResult(PatientItemCalculateInput patient, string codeInput)
+ {
+ return GetResult(codeInput, "ItemCalculateResult", "PatientItemCalculateInput", patient);
+
+ }
+ ///
+ /// 获取项目诊断结果
+ ///
+ ///
+ ///
+ ///
+ public string GetItemDiagnosisResult(PatientItemDiagnosisInput patient, string codeInput)
+ {
+ return GetResult(codeInput, "ItemDiagnosisResult", "PatientItemDiagnosisInput", patient);
+ }
+ ///
+ /// 获取组合项目诊断结果
+ ///
+ ///
+ ///
+ ///
+ public string GetAsbitemDiagnosisResult(PatientAsbitemDiagnosisInput patient, string codeInput)
+ {
+ return GetResult(codeInput, "AsbitemDiagnosisResult", "PatientAsbitemDiagnosisInput", patient);
+ }
+
+ }
+
+ ///
+ /// 计算项目输入参数类
+ ///
+ public class PatientItemCalculateInput
+ {
+ public string SexName { get; set; }
+ public short? Age { get; set; }
+ ///
+ /// 计算项目ID
+ ///
+ public Guid ItemId { get; set; }
+ ///
+ /// 计算项目名称
+ ///
+ public string ItemName { get; set; }
+ public List Items { get; set; } = new List();
+
+ }
+ ///
+ /// 项目诊断输入参数类
+ ///
+ public class PatientItemDiagnosisInput
+ {
+ ///
+ /// 性别名称
+ ///
+ public string SexName { get; set; }
+ ///
+ /// 年龄
+ ///
+ public short? Age { get; set; }
+ ///
+ /// 诊断项目ID
+ ///
+ public Guid ItemId { get; set; }
+ ///
+ /// 诊断项目名称
+ ///
+ public List Items { get; set; } = new List();
+
+ }
+ ///
+ /// 组合项目诊断输入参数类
+ ///
+ public class PatientAsbitemDiagnosisInput
+ {
+ ///
+ /// 性别名称
+ ///
+ public string SexName { get; set; }
+ ///
+ /// 年龄
+ ///
+ public short? Age { get; set; }
+ ///
+ /// 组合项目ID
+ ///
+ public Guid AsbitemId { get; set; }
+ ///
+ /// 组合项目名称
+ ///
+ public string AsbitemName { get; set; }
+ public List Items { get; set; } = new List();
+
+ }
+ ///
+ /// 项目结果
+ ///
+ public class ItemResultInput
+ {
+ public Guid ItemId { get; set; }
+ public string ItemName { get; set; }
+ public string Result { get; set; }
+ }
+}
diff --git a/src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs b/src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs
index 465d093..338636f 100644
--- a/src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs
+++ b/src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs
@@ -33,7 +33,7 @@ namespace Shentun.Peis.DiagnosisFunctions
private readonly IRepository _itemResultTemplateRepository;
private readonly IRepository _itemResultMatchRepository;
private readonly IRepository _suggestionRepository;
-
+ private readonly CacheService _cacheService;
public DiagnosisFunctionAppService(
IRepository patientRegisterRepository,
@@ -46,7 +46,9 @@ namespace Shentun.Peis.DiagnosisFunctions
IRepository diagnosisRepository,
IRepository itemResultTemplateRepository,
IRepository itemResultMatchRepository,
- IRepository suggestionRepository)
+ IRepository suggestionRepository,
+ CacheService cacheService)
+
{
this._patientRegisterRepository = patientRegisterRepository;
this._registerAsbitemRepository = registerAsbitemRepository;
@@ -59,6 +61,7 @@ namespace Shentun.Peis.DiagnosisFunctions
this._itemResultTemplateRepository = itemResultTemplateRepository;
this._itemResultMatchRepository = itemResultMatchRepository;
this._suggestionRepository = suggestionRepository;
+ _cacheService = cacheService;
}
@@ -355,18 +358,48 @@ namespace Shentun.Peis.DiagnosisFunctions
private async Task GetCalculationFunctionAsync(GetDiagnosisResultRequestDto input)
{
//根据检查单ID查询
- var query = (from a in await _registerCheckItemRepository.GetQueryableAsync()
- join b in await _itemRepository.GetQueryableAsync() on a.ItemId equals b.Id
- where a.RegisterCheckId == input.RegisterCheckId
- select b).ToList();
+ var list = (
+ from patientRegister in await _patientRegisterRepository.GetQueryableAsync()
+ join registerCheck in await _registerCheckRepository.GetQueryableAsync()
+ on patientRegister.Id equals registerCheck.PatientRegisterId
+ join registerCheckItem in await _registerCheckItemRepository.GetQueryableAsync()
+ on registerCheck.Id equals registerCheckItem.RegisterCheckId
+ join item in await _itemRepository.GetQueryableAsync()
+ on registerCheckItem.ItemId equals item.Id
+ where registerCheck.Id == input.RegisterCheckId
+ select new
+ {
+ PatientRegister = patientRegister,
+ Item = item
+ }
+ ).ToList();
+
+ var diagnosisBuilder = new DiagnosisBuilder();
+ var patientItemCalculateInput = new PatientItemCalculateInput()
+ {
+ SexName = _cacheService.GetSexNameAsync(list[0].PatientRegister.SexId).Result,
+ Age = list[0].PatientRegister.Age
+ };
+ foreach (var item in input.Items)
+ {
+ var itemResult = new ItemResultInput()
+ {
+ ItemId = item.ItemId,
+ Result = item.Result
+ };
+ itemResult.ItemName = list.Where(o => o.Item.Id == item.ItemId).First().Item.DisplayName;
+ patientItemCalculateInput.Items.Add(itemResult);
+ }
- foreach (var item in query)
+ foreach (var item in list)
{
- if (item.IsCalculationItem == 'Y' && !string.IsNullOrEmpty(item.CalculationFunction))
+ if (item.Item.IsCalculationItem == 'Y' && !string.IsNullOrEmpty(item.Item.CalculationFunction))
{
//计算函数
//计算结果
- string CalculationFunctionValue = GetCodeResult(input, item.CalculationFunction, query);
+
+ string CalculationFunctionValue = diagnosisBuilder.GetItemCalculateResult(patientItemCalculateInput, item.Item.CalculationFunction);
+ //CalculationFunctionValue = GetCodeResult(input, item.CalculationFunction, list);
input.Items.Where(m => m.ItemId == item.Id).FirstOrDefault().Result = CalculationFunctionValue; //赋值
@@ -853,84 +886,12 @@ namespace Shentun.Peis.DiagnosisFunctions
return tempcode;
}
- public string GetItemResult(PatientDiagnosisInputArg patient, string 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 DiagnosisResultInAsbitemHeight
- {
- public string GetDiagnosisResult(PatientDiagnosisInputArg patient)
- {
- "
- + codeInput + @"
-
- }
- }
-";
-
- CompileHelper compileHelper = new CompileHelper();
- CodeBuilder codeBuilder = new CodeBuilder();
- Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
-
-
- var assembly = codeBuilder.GenerateAssemblyFromCode(code, Assembly.Load(new AssemblyName("System.Runtime")), typeof(object).Assembly);
- //var assembly = compileHelper.GenerateAssemblyFromCode(code, assemblies);
- // var assembly = codeBuilder.GenerateAssemblyFromCode(code, assemblies);
- //var assembly = codeBuilder.CreateCode(code);
- if (assembly != null)
- {
-
- // 反射获取程序集中 的类
- Type type = assembly.GetType("DiagnosisResultInAsbitemHeight");
-
- // 创建该类的实例
- object obj = Activator.CreateInstance(type);
- object[] objects = { patient };
- ;
- var msg = type.InvokeMember("GetDiagnosisResult",
- BindingFlags.Default | BindingFlags.InvokeMethod,
- null,
- obj,
- objects);
- if(msg == null)
- {
- return "";
- }
- if (!string.IsNullOrEmpty(msg.ToString()))
- {
- result = msg.ToString();
- }
- }
-
- return result;
- }
+
}
- public class PatientDiagnosisInputArg
- {
- public string SexName { get; set; }
- public short Age { get; set; }
- public Guid AsbitemId { get; set; }
- public string AsbitemName { get; set; }
- public List Items { get; set; } = new List();
-
- }
+
- public class ItemDiagnosisInputArg
- {
- public Guid ItemId { get; set; }
- public string ItemName { get; set; }
- public string Result { get; set; }
- }
}
diff --git a/test/Shentun.Peis.Application.Tests/DiagnosisFunctionAppServiceTest.cs b/test/Shentun.Peis.Application.Tests/DiagnosisFunctionAppServiceTest.cs
index d27426e..53e1f02 100644
--- a/test/Shentun.Peis.Application.Tests/DiagnosisFunctionAppServiceTest.cs
+++ b/test/Shentun.Peis.Application.Tests/DiagnosisFunctionAppServiceTest.cs
@@ -28,35 +28,36 @@ namespace Shentun.Peis
_repository = GetRequiredService>();
_appService = GetRequiredService();
}
-
+ ///
+ /// 体重指数测试结果
+ ///
[Fact]
- public void GetItemResult()
+ public void GetItemCalculateResultTzzsTest()
{
- PatientDiagnosisInputArg patient = new PatientDiagnosisInputArg();
- patient.AsbitemId = Guid.NewGuid();
+ PatientItemCalculateInput patient = new PatientItemCalculateInput();
patient.SexName = "男";
patient.Age = 30;
- patient.Items = new List()
+ patient.Items = new List()
{
- new ItemDiagnosisInputArg()
+ new ItemResultInput()
{
ItemId = Guid.NewGuid(),
ItemName = "身高",
Result = "122"
},
- new ItemDiagnosisInputArg()
+ new ItemResultInput()
{
ItemId = Guid.NewGuid(),
ItemName = "体重",
Result = "221"
},
- new ItemDiagnosisInputArg()
+ new ItemResultInput()
{
ItemId = Guid.NewGuid(),
ItemName = "体重指数",
}
};
- var result = GetItemResultSample(patient);
+ var result = GetItemCalculateResultTzzs(patient);
_output.WriteLine("结果:"+result);
string code = @"
string result = """";
@@ -99,16 +100,20 @@ namespace Shentun.Peis
return result;
";
-
- result = _appService.GetItemResult(patient, code);
+ DiagnosisBuilder diagnosisBuilder = new DiagnosisBuilder();
+ result = diagnosisBuilder.GetItemCalculateResult(patient, code);
_output.WriteLine("动态结果:" + result);
}
-
- public string GetItemResultSample(PatientDiagnosisInputArg patient)
+ ///
+ /// 体重指数
+ ///
+ ///
+ ///
+ public string GetItemCalculateResultTzzs(PatientItemCalculateInput patient)
{
string result = "";
decimal sg = 0;
@@ -149,5 +154,91 @@ namespace Shentun.Peis
result = (tz /((sg/100) * (sg / 100))).ToString("0.00");
return result;
}
+
+ ///
+ /// 乙肝五项
+ ///
+ [Fact]
+ public void GetAsbitemDiagnosisResultTest()
+ {
+ var patient = new PatientAsbitemDiagnosisInput();
+ patient.SexName = "男";
+ patient.Age = 30;
+ patient.Items = new List()
+ {
+ new ItemResultInput()
+ {
+ ItemId = Guid.NewGuid(),
+ ItemName = "身高",
+ Result = "122"
+ },
+ new ItemResultInput()
+ {
+ ItemId = Guid.NewGuid(),
+ ItemName = "体重",
+ Result = "221"
+ },
+ new ItemResultInput()
+ {
+ ItemId = Guid.NewGuid(),
+ ItemName = "体重指数",
+ }
+ };
+ var result = GetAsbitemDiagnosisResult(patient);
+ _output.WriteLine("结果:" + result);
+ string code = @"
+ string result = """";
+ decimal sg = 0;
+ decimal tz = 0;
+ foreach (var item in patient.Items)
+ {
+ if (item.ItemName == ""身高"")
+ {
+ if (decimal.TryParse(item.Result, out sg))
+ {
+ if (sg == 0)
+ {
+ return null;
+ }
+ }
+ else
+ {
+ return null;
+ }
+
+ }
+ if (item.ItemName == ""体重"")
+ {
+ if (decimal.TryParse(item.Result, out tz))
+ {
+ if (tz == 0)
+ {
+ return null;
+ }
+ }
+ else
+ {
+ return null;
+ }
+
+ }
+ }
+ result = (tz /((sg/100) * (sg / 100))).ToString(""0.00"");
+ return result;
+ ";
+
+
+ DiagnosisBuilder diagnosisBuilder = new DiagnosisBuilder();
+ result = diagnosisBuilder.GetAsbitemDiagnosisResult(patient, code);
+ _output.WriteLine("动态结果:" + result);
+
+
+ }
+
+ public string GetAsbitemDiagnosisResult(PatientAsbitemDiagnosisInput patient)
+ {
+ string result = "";
+ return result;
+ }
}
}