10 changed files with 759 additions and 116 deletions
-
17src/Shentun.Peis.Application.Contracts/PatientRegisters/PatientRegisterNoInputDto.cs
-
6src/Shentun.Peis.Application.Contracts/PatientRegisters/PatientRegisterOrNoDto.cs
-
108src/Shentun.Peis.Application/DiagnosisFunctions/CodeBuilder.cs
-
80src/Shentun.Peis.Application/DiagnosisFunctions/DiagnosisFunctionAppService.cs
-
121src/Shentun.Peis.Application/PatientRegisters/PatientRegisterAppService.cs
-
125src/Shentun.Peis.Domain/CacheService.cs
-
7src/Shentun.Peis.Domain/CompileHelper.cs
-
29src/Shentun.Peis.Domain/RegisterCheckAsbitems/RegisterCheckAsbitemManager.cs
-
153test/Shentun.Peis.Application.Tests/DiagnosisFunctionAppServiceTest.cs
-
229test/Shentun.Peis.Application.Tests/PatientRegisterAppServiceTest.cs
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.Peis.PatientRegisters |
|||
{ |
|||
public class PatientRegisterNoInputDto |
|||
{ |
|||
|
|||
public string PatientRegisterNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 档案号
|
|||
/// </summary>
|
|||
public string PatientNo { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,108 @@ |
|||
using Microsoft.CodeAnalysis.CSharp; |
|||
using Microsoft.CodeAnalysis.Emit; |
|||
using Microsoft.CodeAnalysis; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
namespace Shentun.Peis.DiagnosisFunctions |
|||
{ |
|||
public class CodeBuilder |
|||
{ |
|||
private static List<MetadataReference> _references = new List<MetadataReference>(); |
|||
/// <summary>
|
|||
/// 编译前的初始化,只需要一次
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
static CodeBuilder() |
|||
{ |
|||
_references = new List<MetadataReference>(); |
|||
|
|||
// 元数据引用
|
|||
if (_references == null || _references.Count == 0) |
|||
{ |
|||
_references = new List<MetadataReference>() |
|||
{ |
|||
MetadataReference.CreateFromFile(typeof(System.Uri).Assembly.Location), |
|||
MetadataReference.CreateFromFile(typeof(System.Linq.Enumerable).Assembly.Location), |
|||
MetadataReference.CreateFromFile(typeof(object).Assembly.Location), |
|||
MetadataReference.CreateFromFile(typeof(System.IO.File).Assembly.Location), |
|||
MetadataReference.CreateFromFile(Assembly.Load("System.Runtime").Location), |
|||
MetadataReference.CreateFromFile(Assembly.Load("System.Collections").Location), |
|||
MetadataReference.CreateFromFile(Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory+"Shentun.Peis.Application.dll").Location), |
|||
}; |
|||
} |
|||
//Assembly as1 = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "mscorlib.dll");
|
|||
//MetadataReference metadataReference = _references.Find((o => o.Display.Contains("mscorlib.dll")));
|
|||
//if (_references.Find((o => o.Display.Contains("mscorlib.dll"))) == null)
|
|||
//{
|
|||
// _references.Add(MetadataReference.CreateFromFile(as1.Location));
|
|||
//}
|
|||
} |
|||
|
|||
//public CodeBuilder()
|
|||
//{
|
|||
//}
|
|||
//public Assembly CreateCode(string code)
|
|||
//{
|
|||
// //var domain = new NatashaDomain("key");
|
|||
// //var domain = DomainManagement.Random();
|
|||
// NatashaManagement.Preheating();
|
|||
// Path.GetRandomFileName();
|
|||
// using (DomainManagement.Create("myDomain").CreateScope())
|
|||
// {
|
|||
// AssemblyCSharpBuilder builder = new AssemblyCSharpBuilder();
|
|||
// builder.Add(code);
|
|||
// var func = builder.GetDelegateFromShortName<Func<string>>("Test", "GetName");
|
|||
// }
|
|||
|
|||
// return myAssembly;
|
|||
//}
|
|||
public Assembly GenerateAssemblyFromCode(string code, params Assembly[] referencedAssemblies) |
|||
{ |
|||
Assembly assembly = null; |
|||
|
|||
// 丛代码中转换表达式树
|
|||
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(code); |
|||
// 随机程序集名称
|
|||
//string assemblyName = Path.GetRandomFileName();
|
|||
var assemblyName = "_" + Guid.NewGuid().ToString("D"); |
|||
//assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
|
|||
//assemblyName = "Shentun.Peis.Application";
|
|||
var syntaxTrees = new SyntaxTree[] { syntaxTree }; |
|||
// 引用
|
|||
var references = _references;// referencedAssemblies.Select(x => MetadataReference.CreateFromFile(x.Location));
|
|||
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); |
|||
|
|||
// 创建编译对象
|
|||
CSharpCompilation compilation = CSharpCompilation.Create(assemblyName, syntaxTrees, references, options); |
|||
|
|||
using (var ms = new MemoryStream()) |
|||
{ |
|||
// 将编译好的IL代码放入内存流
|
|||
EmitResult result = compilation.Emit(ms); |
|||
|
|||
// 编译失败,提示
|
|||
if (!result.Success) |
|||
{ |
|||
IEnumerable<Diagnostic> failures = result.Diagnostics.Where(diagnostic => |
|||
diagnostic.IsWarningAsError || |
|||
diagnostic.Severity == DiagnosticSeverity.Error); |
|||
foreach (Diagnostic diagnostic in failures) |
|||
{ |
|||
Console.Error.WriteLine("{0}: {1}", diagnostic.Id, diagnostic.GetMessage()); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
// 编译成功,从内存中加载编译好的程序集
|
|||
ms.Seek(0, SeekOrigin.Begin); |
|||
assembly = Assembly.Load(ms.ToArray()); |
|||
} |
|||
} |
|||
return assembly; |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,153 @@ |
|||
using NPOI.POIFS.Properties; |
|||
using Shentun.Peis.CustomerOrgs; |
|||
using Shentun.Peis.DiagnosisFunctions; |
|||
using Shentun.Peis.Models; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using TencentCloud.Ame.V20190916.Models; |
|||
using Volo.Abp.Domain.Repositories; |
|||
using Volo.Abp.Uow; |
|||
using Xunit; |
|||
using Xunit.Abstractions; |
|||
|
|||
namespace Shentun.Peis |
|||
{ |
|||
public class DiagnosisFunctionAppServiceTest : PeisApplicationTestBase |
|||
{ |
|||
private readonly IRepository<CustomerOrg, Guid> _repository; |
|||
private readonly DiagnosisFunctionAppService _appService; |
|||
private readonly ITestOutputHelper _output; |
|||
private readonly IUnitOfWorkManager _unitOfWorkManager; |
|||
public DiagnosisFunctionAppServiceTest(ITestOutputHelper testOutputHelper) |
|||
{ |
|||
_output = testOutputHelper; |
|||
_unitOfWorkManager = GetRequiredService<IUnitOfWorkManager>(); |
|||
_repository = GetRequiredService<IRepository<CustomerOrg, Guid>>(); |
|||
_appService = GetRequiredService<DiagnosisFunctionAppService>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void GetItemResult() |
|||
{ |
|||
PatientDiagnosisInputArg patient = new PatientDiagnosisInputArg(); |
|||
patient.AsbitemId = Guid.NewGuid(); |
|||
patient.SexName = "男"; |
|||
patient.Age = 30; |
|||
patient.Items = new List<ItemDiagnosisInputArg>() |
|||
{ |
|||
new ItemDiagnosisInputArg() |
|||
{ |
|||
ItemId = Guid.NewGuid(), |
|||
ItemName = "身高", |
|||
Result = "122" |
|||
}, |
|||
new ItemDiagnosisInputArg() |
|||
{ |
|||
ItemId = Guid.NewGuid(), |
|||
ItemName = "体重", |
|||
Result = "221" |
|||
}, |
|||
new ItemDiagnosisInputArg() |
|||
{ |
|||
ItemId = Guid.NewGuid(), |
|||
ItemName = "体重指数", |
|||
} |
|||
}; |
|||
var result = GetItemResultSample(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; |
|||
";
|
|||
|
|||
|
|||
|
|||
result = _appService.GetItemResult(patient, code); |
|||
_output.WriteLine("动态结果:" + result); |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
public string GetItemResultSample(PatientDiagnosisInputArg patient) |
|||
{ |
|||
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; |
|||
} |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue