Browse Source

计算结果

bjmzak
DESKTOP-G961P6V\Zhh 2 years ago
parent
commit
aeba4ae936
  1. 2
      src/Shentun.Peis.Application.Contracts/DiagnosisFunctions/GetDiagnosisResultRequestDto.cs
  2. 2
      src/Shentun.Peis.Application/DiagnosisFunctions/CodeBuilder.cs
  3. 192
      src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisBuilder.cs
  4. 123
      src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs
  5. 117
      test/Shentun.Peis.Application.Tests/DiagnosisFunctionAppServiceTest.cs

2
src/Shentun.Peis.Application.Contracts/DiagnosisFunctions/GetDiagnosisResultRequestDto.cs

@ -31,7 +31,7 @@ namespace Shentun.Peis.DiagnosisFunctions
/// <summary> /// <summary>
/// 项目ID Item表 不是RegisterCheckItem /// 项目ID Item表 不是RegisterCheckItem
/// </summary> /// </summary>
public Guid? ItemId { get; set; }
public Guid ItemId { get; set; }
/// <summary> /// <summary>
/// 项目结果 /// 项目结果

2
src/Shentun.Peis.Application/DiagnosisFunctions/CodeBuilder.cs

@ -59,7 +59,7 @@ namespace Shentun.Peis.DiagnosisFunctions
// return myAssembly; // return myAssembly;
//} //}
public Assembly GenerateAssemblyFromCode(string code, params Assembly[] referencedAssemblies)
public Assembly GenerateAssemblyFromCode(string code)
{ {
Assembly assembly = null; Assembly assembly = null;

192
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;
}
/// <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; }
}
}

123
src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs

@ -33,7 +33,7 @@ namespace Shentun.Peis.DiagnosisFunctions
private readonly IRepository<ItemResultTemplate, Guid> _itemResultTemplateRepository; private readonly IRepository<ItemResultTemplate, Guid> _itemResultTemplateRepository;
private readonly IRepository<ItemResultMatch, Guid> _itemResultMatchRepository; private readonly IRepository<ItemResultMatch, Guid> _itemResultMatchRepository;
private readonly IRepository<Suggestion, Guid> _suggestionRepository; private readonly IRepository<Suggestion, Guid> _suggestionRepository;
private readonly CacheService _cacheService;
public DiagnosisFunctionAppService( public DiagnosisFunctionAppService(
IRepository<PatientRegister, Guid> patientRegisterRepository, IRepository<PatientRegister, Guid> patientRegisterRepository,
@ -46,7 +46,9 @@ namespace Shentun.Peis.DiagnosisFunctions
IRepository<Diagnosis, Guid> diagnosisRepository, IRepository<Diagnosis, Guid> diagnosisRepository,
IRepository<ItemResultTemplate, Guid> itemResultTemplateRepository, IRepository<ItemResultTemplate, Guid> itemResultTemplateRepository,
IRepository<ItemResultMatch, Guid> itemResultMatchRepository, IRepository<ItemResultMatch, Guid> itemResultMatchRepository,
IRepository<Suggestion, Guid> suggestionRepository)
IRepository<Suggestion, Guid> suggestionRepository,
CacheService cacheService)
{ {
this._patientRegisterRepository = patientRegisterRepository; this._patientRegisterRepository = patientRegisterRepository;
this._registerAsbitemRepository = registerAsbitemRepository; this._registerAsbitemRepository = registerAsbitemRepository;
@ -59,6 +61,7 @@ namespace Shentun.Peis.DiagnosisFunctions
this._itemResultTemplateRepository = itemResultTemplateRepository; this._itemResultTemplateRepository = itemResultTemplateRepository;
this._itemResultMatchRepository = itemResultMatchRepository; this._itemResultMatchRepository = itemResultMatchRepository;
this._suggestionRepository = suggestionRepository; this._suggestionRepository = suggestionRepository;
_cacheService = cacheService;
} }
@ -355,18 +358,48 @@ namespace Shentun.Peis.DiagnosisFunctions
private async Task GetCalculationFunctionAsync(GetDiagnosisResultRequestDto input) private async Task GetCalculationFunctionAsync(GetDiagnosisResultRequestDto input)
{ {
//根据检查单ID查询 //根据检查单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; //赋值 input.Items.Where(m => m.ItemId == item.Id).FirstOrDefault().Result = CalculationFunctionValue; //赋值
@ -853,84 +886,12 @@ namespace Shentun.Peis.DiagnosisFunctions
return tempcode; 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<ItemDiagnosisInputArg> Items { get; set; } = new List<ItemDiagnosisInputArg>();
}
public class ItemDiagnosisInputArg
{
public Guid ItemId { get; set; }
public string ItemName { get; set; }
public string Result { get; set; }
}
} }

117
test/Shentun.Peis.Application.Tests/DiagnosisFunctionAppServiceTest.cs

@ -28,35 +28,36 @@ namespace Shentun.Peis
_repository = GetRequiredService<IRepository<CustomerOrg, Guid>>(); _repository = GetRequiredService<IRepository<CustomerOrg, Guid>>();
_appService = GetRequiredService<DiagnosisFunctionAppService>(); _appService = GetRequiredService<DiagnosisFunctionAppService>();
} }
/// <summary>
/// 体重指数测试结果
/// </summary>
[Fact] [Fact]
public void GetItemResult()
public void GetItemCalculateResultTzzsTest()
{ {
PatientDiagnosisInputArg patient = new PatientDiagnosisInputArg();
patient.AsbitemId = Guid.NewGuid();
PatientItemCalculateInput patient = new PatientItemCalculateInput();
patient.SexName = "男"; patient.SexName = "男";
patient.Age = 30; patient.Age = 30;
patient.Items = new List<ItemDiagnosisInputArg>()
patient.Items = new List<ItemResultInput>()
{ {
new ItemDiagnosisInputArg()
new ItemResultInput()
{ {
ItemId = Guid.NewGuid(), ItemId = Guid.NewGuid(),
ItemName = "身高", ItemName = "身高",
Result = "122" Result = "122"
}, },
new ItemDiagnosisInputArg()
new ItemResultInput()
{ {
ItemId = Guid.NewGuid(), ItemId = Guid.NewGuid(),
ItemName = "体重", ItemName = "体重",
Result = "221" Result = "221"
}, },
new ItemDiagnosisInputArg()
new ItemResultInput()
{ {
ItemId = Guid.NewGuid(), ItemId = Guid.NewGuid(),
ItemName = "体重指数", ItemName = "体重指数",
} }
}; };
var result = GetItemResultSample(patient);
var result = GetItemCalculateResultTzzs(patient);
_output.WriteLine("结果:"+result); _output.WriteLine("结果:"+result);
string code = @" string code = @"
string result = """"; string result = """";
@ -100,15 +101,19 @@ namespace Shentun.Peis
"; ";
result = _appService.GetItemResult(patient, code);
DiagnosisBuilder diagnosisBuilder = new DiagnosisBuilder();
result = diagnosisBuilder.GetItemCalculateResult(patient, code);
_output.WriteLine("动态结果:" + result); _output.WriteLine("动态结果:" + result);
} }
public string GetItemResultSample(PatientDiagnosisInputArg patient)
/// <summary>
/// 体重指数
/// </summary>
/// <param name="patient"></param>
/// <returns></returns>
public string GetItemCalculateResultTzzs(PatientItemCalculateInput patient)
{ {
string result = ""; string result = "";
decimal sg = 0; decimal sg = 0;
@ -149,5 +154,91 @@ namespace Shentun.Peis
result = (tz /((sg/100) * (sg / 100))).ToString("0.00"); result = (tz /((sg/100) * (sg / 100))).ToString("0.00");
return result; return result;
} }
/// <summary>
/// 乙肝五项
/// </summary>
[Fact]
public void GetAsbitemDiagnosisResultTest()
{
var patient = new PatientAsbitemDiagnosisInput();
patient.SexName = "男";
patient.Age = 30;
patient.Items = new List<ItemResultInput>()
{
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;
}
} }
} }
Loading…
Cancel
Save