You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1915 lines
81 KiB
1915 lines
81 KiB
using Azure;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.CodeAnalysis;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using NPOI.DDF;
|
|
using NPOI.POIFS.Properties;
|
|
using NUglify.Helpers;
|
|
using Shentun.Peis.Enums;
|
|
using Shentun.Peis.FollowUps;
|
|
using Shentun.Peis.ItemResultMatchs;
|
|
using Shentun.Peis.Models;
|
|
using Shentun.Peis.PatientRegisters;
|
|
using Shentun.Peis.RegisterCheckItems;
|
|
using Shentun.Peis.Sexs;
|
|
using Shentun.Peis.SumDiagnosises;
|
|
using Shentun.Peis.SysParmValues;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Application.Services;
|
|
using Volo.Abp.Domain.Repositories;
|
|
using Volo.Abp.Uow;
|
|
using Volo.Abp.Users;
|
|
using Xceed.Document.NET;
|
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
|
|
|
|
|
namespace Shentun.Peis.DiagnosisFunctions
|
|
{
|
|
[ApiExplorerSettings(GroupName = "Work")]
|
|
[Authorize]
|
|
public class DiagnosisFunctionAppService : ApplicationService
|
|
{
|
|
private readonly IRepository<PatientRegister, Guid> _patientRegisterRepository;
|
|
private readonly IRepository<RegisterCheckAsbitem, Guid> _registerAsbitemRepository;
|
|
private readonly IRepository<Asbitem, Guid> _asbitemRepository;
|
|
private readonly IRepository<Item, Guid> _itemRepository;
|
|
private readonly IRepository<Unit, Guid> _unitRepository;
|
|
private readonly IRepository<AsbitemDetail> _asbitemDetailRepository;
|
|
private readonly IRepository<RegisterCheck, Guid> _registerCheckRepository;
|
|
private readonly IRepository<RegisterCheckItem> _registerCheckItemRepository;
|
|
private readonly IRepository<Diagnosis, Guid> _diagnosisRepository;
|
|
private readonly IRepository<ItemResultTemplate, Guid> _itemResultTemplateRepository;
|
|
private readonly IRepository<ItemResultMatch, Guid> _itemResultMatchRepository;
|
|
private readonly IRepository<Suggestion, Guid> _suggestionRepository;
|
|
private readonly CacheService _cacheService;
|
|
private SysParmValueManager _sysParmValueManager;
|
|
private RegisterCheckItemManager _registerCheckItemManager;
|
|
private string _isAddAbnormalResult;
|
|
private string _isAddReferenceRange;
|
|
private string _isAutoAddSuffix;
|
|
private string _lowerSuffix;
|
|
private string _highSuffix;
|
|
string[] _numArry = { "①", "②", "③", "④", "⑤", "⑥", "⑦", "⑧", "⑨", "⑩",
|
|
"⑪", "⑫", "⑬", "⑭", "⑮", "⑯", "⑰", "⑱", "⑲", "⑳" };
|
|
|
|
private readonly IRepository<CriticalFollowValue, Guid> _criticalFollowValueRepository;
|
|
private readonly ICurrentUser _currentUser;
|
|
private readonly IRepository<FollowUp, Guid> _followUpRepository;
|
|
private readonly FollowUpAppService _followUpAppService;
|
|
|
|
public DiagnosisFunctionAppService(
|
|
IRepository<PatientRegister, Guid> patientRegisterRepository,
|
|
IRepository<RegisterCheckAsbitem, Guid> registerAsbitemRepository,
|
|
IRepository<Asbitem, Guid> asbitemRepository,
|
|
IRepository<Item, Guid> itemRepository,
|
|
IRepository<AsbitemDetail> asbitemDetailRepository,
|
|
IRepository<RegisterCheck, Guid> registerCheckRepository,
|
|
IRepository<RegisterCheckItem> registerCheckItemRepository,
|
|
IRepository<Diagnosis, Guid> diagnosisRepository,
|
|
IRepository<ItemResultTemplate, Guid> itemResultTemplateRepository,
|
|
IRepository<ItemResultMatch, Guid> itemResultMatchRepository,
|
|
IRepository<Suggestion, Guid> suggestionRepository,
|
|
IRepository<Unit, Guid> unitRepository,
|
|
CacheService cacheService,
|
|
SysParmValueManager sysParmValueManager,
|
|
RegisterCheckItemManager registerCheckItemManager,
|
|
IRepository<CriticalFollowValue, Guid> criticalFollowValueRepository,
|
|
ICurrentUser currentUser,
|
|
IRepository<FollowUp, Guid> followUpRepository,
|
|
FollowUpAppService followUpAppService)
|
|
|
|
{
|
|
this._patientRegisterRepository = patientRegisterRepository;
|
|
this._registerAsbitemRepository = registerAsbitemRepository;
|
|
this._asbitemRepository = asbitemRepository;
|
|
this._itemRepository = itemRepository;
|
|
this._asbitemDetailRepository = asbitemDetailRepository;
|
|
this._registerCheckRepository = registerCheckRepository;
|
|
this._registerCheckItemRepository = registerCheckItemRepository;
|
|
this._diagnosisRepository = diagnosisRepository;
|
|
this._itemResultTemplateRepository = itemResultTemplateRepository;
|
|
this._itemResultMatchRepository = itemResultMatchRepository;
|
|
this._suggestionRepository = suggestionRepository;
|
|
_cacheService = cacheService;
|
|
_sysParmValueManager = sysParmValueManager;
|
|
_registerCheckItemManager = registerCheckItemManager;
|
|
_unitRepository = unitRepository;
|
|
_criticalFollowValueRepository = criticalFollowValueRepository;
|
|
_currentUser = currentUser;
|
|
_followUpRepository = followUpRepository;
|
|
_followUpAppService = followUpAppService;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 生成小结
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/DiagnosisFunction/GetDoctorCheckDiagnosisResultAsync")]
|
|
public async Task<GetDiagnosisResultDto> GetDoctorCheckDiagnosisResultAsync(GetDiagnosisResultRequestDto input)
|
|
{
|
|
var reslist = new List<GetDiagnosisResult_Detail>();
|
|
var suggestionlist = new List<GetDiagnosisSuggestion_Detail>();
|
|
|
|
|
|
//根据检查单ID查询
|
|
var query = (from registerCheck in await _registerCheckRepository.GetQueryableAsync()
|
|
join registerAsbitem in await _registerAsbitemRepository.GetQueryableAsync() on registerCheck.Id equals registerAsbitem.RegisterCheckId
|
|
join registerCheckItem in await _registerCheckItemRepository.GetQueryableAsync() on registerCheck.Id equals registerCheckItem.RegisterCheckId
|
|
join asbitem in await _asbitemRepository.GetQueryableAsync() on registerAsbitem.AsbitemId equals asbitem.Id
|
|
join item in (await _itemRepository.GetQueryableAsync()).Include(x => x.ReferenceRanges).Include(x => x.ItemResultMatches).Include(x => x.ItemResultTemplates)
|
|
on registerCheckItem.ItemId equals item.Id
|
|
join unit in await _unitRepository.GetQueryableAsync()
|
|
on item.UnitId equals unit.Id into unitExist
|
|
from unitHaveEmpty in unitExist.DefaultIfEmpty()
|
|
join patientRegister in await _patientRegisterRepository.GetQueryableAsync() on registerCheck.PatientRegisterId equals patientRegister.Id
|
|
where registerCheck.Id == input.RegisterCheckId
|
|
select new
|
|
{
|
|
registerCheck,
|
|
registerAsbitem,
|
|
registerCheckItem,
|
|
asbitem,
|
|
item,
|
|
unitHaveEmpty,
|
|
patientRegister
|
|
}).AsNoTracking().ToList();
|
|
|
|
var resultDto = new GetDiagnosisResultDto
|
|
{
|
|
DiagnosisResultDetails = reslist,
|
|
DiagnosisSuggestionDetails = suggestionlist,
|
|
};
|
|
if (query.Count() == 0)
|
|
{
|
|
return resultDto;
|
|
}
|
|
await LoadSysParm(query[0].patientRegister.MedicalCenterId);
|
|
/*处理逻辑:
|
|
* 1、处理组合项目诊断函数,如果继续处理走下一步,只处理不合并组合项目的,合并组合项目的不支持
|
|
* 2、处理项目诊断函数,如果继续处理走下一步
|
|
* 3、如果是数字型结果,并且有参考范围则处理数字型参考范围,处理完毕后后续几步不处理
|
|
* 4、如果是字符型结果则从结果模板和结果匹配中去找到对应的诊断,如果都没有生成诊断,则根据结果直接生成诊断
|
|
* 5、如果没有诊断,返回组合项目默认结果
|
|
* */
|
|
//设置基本参数
|
|
var doctorCheckDiagnosisInput = new DoctorCheckDiagnosisInput()
|
|
{
|
|
SexId = query[0].patientRegister.SexId,
|
|
SexName = _cacheService.GetSexNameAsync(query[0].patientRegister.SexId).Result,
|
|
Age = query[0].patientRegister.Age
|
|
};
|
|
foreach (var item in query)
|
|
{
|
|
//组合项目参数
|
|
if (doctorCheckDiagnosisInput.Asbitems.Where(o => o.AsbitemId == item.asbitem.Id).Count() == 0)
|
|
{
|
|
var asbitemInput = new AsbitemInput()
|
|
{
|
|
RegisterCheckId = item.registerCheck.Id,
|
|
AsbitemId = item.asbitem.Id,
|
|
AsbitemName = item.asbitem.DisplayName,
|
|
IsDiagnosisFunction = item.asbitem.IsDiagnosisFunction,
|
|
DiagnosisFunction = item.asbitem.DiagnosisFunction,
|
|
IsContinueProcess = item.asbitem.IsContinueProcess,
|
|
DefaultResult = item.asbitem.DefaultResult,
|
|
CriticalValueFunction = item.asbitem.CriticalValueFunction,
|
|
FollowUpFunction = item.asbitem.FollowUpFunction,
|
|
IsCriticalValueFunction = item.asbitem.IsCriticalValueFunction,
|
|
IsFollowUpFunction = item.asbitem.IsFollowUpFunction
|
|
};
|
|
doctorCheckDiagnosisInput.Asbitems.Add(asbitemInput);
|
|
}
|
|
//项目参数
|
|
if (doctorCheckDiagnosisInput.Items.Where(o => o.ItemId == item.item.Id).Count() == 0)
|
|
{
|
|
var inputItem = input.Items.Where(o => o.ItemId == item.item.Id).FirstOrDefault();
|
|
var inputResult = "";
|
|
if (inputItem != null)
|
|
{
|
|
inputResult = inputItem.Result;
|
|
}
|
|
var itemInput = new ItemInput()
|
|
{
|
|
RegisterCheckId = item.registerCheck.Id,
|
|
ItemId = item.item.Id,
|
|
ItemName = item.item.DisplayName,
|
|
Unit = (item.unitHaveEmpty == null) ? "" : item.unitHaveEmpty.DisplayName,
|
|
IsDiagnosisFunction = item.item.IsDiagnosisFunction,
|
|
DiagnosisFunction = item.item.DiagnosisFunction,
|
|
IsContinueProcess = item.item.IsContinueProcess,
|
|
IsNameIntoSummary = item.item.IsNameIntoSummary,
|
|
IsProduceSummary = item.item.IsProduceSummary,
|
|
ReferenceRangeTypeFlag = item.item.ReferenceRangeTypeFlag,
|
|
DefaultResult = item.item.DefaultResult,
|
|
Result = inputResult,
|
|
DisplayOrder = item.item.DisplayOrder,
|
|
ItemResultMatches = item.item.ItemResultMatches.ToList(),
|
|
ItemResultTemplates = item.item.ItemResultTemplates.ToList(),
|
|
ReferenceRanges = item.item.ReferenceRanges.ToList(),
|
|
CriticalValueFunction = item.item.CriticalValueFunction,
|
|
FollowUpFunction = item.item.FollowUpFunction,
|
|
IsFollowUpFunction = item.item.IsFollowUpFunction,
|
|
IsCriticalValueFunction = item.item.IsCriticalValueFunction
|
|
};
|
|
doctorCheckDiagnosisInput.Items.Add(itemInput);
|
|
}
|
|
}
|
|
doctorCheckDiagnosisInput.Items = doctorCheckDiagnosisInput.Items.OrderBy(o => o.DisplayOrder).ToList();
|
|
|
|
//处理组合项目诊断函数
|
|
List<string> diagnosisList = new List<string>();
|
|
List<string> asbitemDiagnosisList;
|
|
var isContinueProcess = GetAsbitemDiagnosisByFunction(doctorCheckDiagnosisInput, out asbitemDiagnosisList);
|
|
diagnosisList.AddRange(asbitemDiagnosisList);
|
|
if (isContinueProcess)
|
|
{
|
|
//处理项目诊断
|
|
var itemDiagnosisList = await GetItemDiagnosis(doctorCheckDiagnosisInput);
|
|
var itemDiagnosisStringList = GetItemDiagnosisStringList(itemDiagnosisList);
|
|
diagnosisList.AddRange(itemDiagnosisStringList);
|
|
|
|
}
|
|
//设置返回值
|
|
//去掉空结果数据
|
|
diagnosisList = diagnosisList.Where(o => !string.IsNullOrWhiteSpace(o)).ToList();
|
|
//去掉重复结果数据
|
|
diagnosisList = diagnosisList.Distinct().ToList();
|
|
if (!diagnosisList.Any())
|
|
{
|
|
//设置组合项目默认小结
|
|
diagnosisList.Add(doctorCheckDiagnosisInput.Asbitems[0].DefaultResult);
|
|
}
|
|
foreach (var diagnosis in diagnosisList)
|
|
{
|
|
var getDiagnosisResult_Detail = new GetDiagnosisResult_Detail()
|
|
{
|
|
DiagnosisResult = diagnosis
|
|
};
|
|
resultDto.DiagnosisResultDetails.Add(getDiagnosisResult_Detail);
|
|
}
|
|
|
|
#region 处理危急值函数
|
|
|
|
List<GetCriticalResultDto> criticalResultDtoList = new List<GetCriticalResultDto>();
|
|
|
|
var isCritical = await GetPatientRegisterIsCriticalAsync(doctorCheckDiagnosisInput, resultDto, criticalResultDtoList);
|
|
var isFollowUp = await GetPatientRegisterIsFollowUpAsync(doctorCheckDiagnosisInput, resultDto, criticalResultDtoList);
|
|
await HandCriticalResult(criticalResultDtoList, query[0].patientRegister.Id);
|
|
|
|
#endregion
|
|
|
|
return resultDto;
|
|
|
|
}
|
|
|
|
#region 小结方法
|
|
|
|
private List<string> GetItemDiagnosisStringList(List<DoctorCheckItemDiagnosisResult> itemDiagnosisList)
|
|
{
|
|
var diagnosisList = new List<string>();
|
|
foreach (var itemDiagnosis in itemDiagnosisList)
|
|
{
|
|
if (!itemDiagnosis.ItemDiagnosisTypeResults.Any())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
string diagnosis = "";
|
|
foreach (var itemDiagnosisType in itemDiagnosis.ItemDiagnosisTypeResults)
|
|
{
|
|
if (itemDiagnosisType.DiagnosisType == '1')
|
|
{
|
|
//数字型检验参考范围
|
|
diagnosisList.AddRange(itemDiagnosisType.Diagnosis);
|
|
}
|
|
else
|
|
{
|
|
itemDiagnosisType.Diagnosis = itemDiagnosisType.Diagnosis.Where(o => !string.IsNullOrWhiteSpace(o)).ToList();
|
|
if (itemDiagnosisType.Diagnosis.Count() > _numArry.Count())
|
|
{
|
|
throw new UserFriendlyException($"诊断数量超过{_numArry.Count()}个,不支持");
|
|
}
|
|
if (itemDiagnosisType.Diagnosis.Count() == 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
for (int i = 0; i < itemDiagnosisType.Diagnosis.Count(); i++)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(itemDiagnosisType.Diagnosis[i]))
|
|
{
|
|
continue;
|
|
}
|
|
if (itemDiagnosisType.Diagnosis.Count() == 1)
|
|
{
|
|
diagnosis = diagnosis + itemDiagnosisType.Diagnosis[i] + ";";
|
|
}
|
|
else
|
|
{
|
|
diagnosis = diagnosis + _numArry[i] + itemDiagnosisType.Diagnosis[i] + ";";
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(diagnosis))
|
|
{
|
|
if (itemDiagnosis.IsNameIntoSummary == 'Y' && !diagnosis.StartsWith(itemDiagnosis.ItemName))
|
|
{
|
|
diagnosis = itemDiagnosis.ItemName + ":" + diagnosis;
|
|
}
|
|
|
|
diagnosisList.Add(diagnosis);
|
|
}
|
|
|
|
}
|
|
|
|
return diagnosisList;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加载系统参数
|
|
/// </summary>
|
|
/// <param name="medicalCenterId"></param>
|
|
/// <returns></returns>
|
|
private async Task LoadSysParm(Guid medicalCenterId)
|
|
{
|
|
_isAddAbnormalResult = await _sysParmValueManager.GetSysParmValueAsync(
|
|
medicalCenterId, "doctor_check_lis_summary_mode_add_abnormal_result");
|
|
_isAddReferenceRange = await _sysParmValueManager.GetSysParmValueAsync(
|
|
medicalCenterId, "doctor_check_lis_summary_mode_add_reference_range");
|
|
_isAutoAddSuffix = await _sysParmValueManager.GetSysParmValueAsync(
|
|
medicalCenterId, "doctor_check_lis_summary_mode_auto_add_suffix");
|
|
_lowerSuffix = await _sysParmValueManager.GetSysParmValueAsync(
|
|
medicalCenterId, "doctor_check_lis_summary_mode_lower_suffix");
|
|
_highSuffix = await _sysParmValueManager.GetSysParmValueAsync(
|
|
medicalCenterId, "doctor_check_lis_summary_mode_high_suffix");
|
|
}
|
|
/// <summary>
|
|
/// 获取组合项目诊断通过诊断函数
|
|
/// </summary>
|
|
/// <param name="doctorCheckDiagnosisInput"></param>
|
|
/// <param name="diagnosisList"></param>
|
|
/// <returns></returns>
|
|
private bool GetAsbitemDiagnosisByFunction(DoctorCheckDiagnosisInput doctorCheckDiagnosisInput, out List<string> diagnosisList)
|
|
{
|
|
var patientAsbitemDiagnosisInput = new PatientAsbitemDiagnosisInput()
|
|
{
|
|
SexName = doctorCheckDiagnosisInput.SexName,
|
|
Age = doctorCheckDiagnosisInput.Age
|
|
};
|
|
|
|
foreach (var item in doctorCheckDiagnosisInput.Items)
|
|
{
|
|
var itemResult = new ItemResultInput()
|
|
{
|
|
ItemId = item.ItemId,
|
|
ItemName = item.ItemName,
|
|
Result = item.Result
|
|
};
|
|
patientAsbitemDiagnosisInput.Items.Add(itemResult);
|
|
}
|
|
var diagnosisBuilder = new DiagnosisBuilder();
|
|
diagnosisList = new List<string>();
|
|
bool isContinueProcess = true;
|
|
foreach (var asbitem in doctorCheckDiagnosisInput.Asbitems)
|
|
{
|
|
if (asbitem.IsDiagnosisFunction == 'Y' && !string.IsNullOrWhiteSpace(asbitem.DiagnosisFunction))
|
|
{
|
|
var diagnosis = diagnosisBuilder.GetAsbitemDiagnosisResult(patientAsbitemDiagnosisInput, asbitem.DiagnosisFunction);
|
|
diagnosisList.Add(diagnosis);
|
|
if (asbitem.IsContinueProcess != 'Y')
|
|
{
|
|
//有一个不允许继续处理,则不允许继续处理
|
|
isContinueProcess = false;
|
|
}
|
|
}
|
|
}
|
|
return isContinueProcess;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获取项目诊断
|
|
/// </summary>
|
|
/// <param name="doctorCheckDiagnosisInput"></param>
|
|
/// <returns></returns>
|
|
private async Task<List<DoctorCheckItemDiagnosisResult>> GetItemDiagnosis(DoctorCheckDiagnosisInput doctorCheckDiagnosisInput)
|
|
{
|
|
var patientItemDiagnosisInput = new PatientItemDiagnosisInput()
|
|
{
|
|
SexName = doctorCheckDiagnosisInput.SexName,
|
|
Age = doctorCheckDiagnosisInput.Age
|
|
};
|
|
|
|
var diagnosisBuilder = new DiagnosisBuilder();
|
|
var diagnosisList = new List<DoctorCheckItemDiagnosisResult>();
|
|
foreach (var item in doctorCheckDiagnosisInput.Items)
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(item.Result))
|
|
{
|
|
continue;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(item.DefaultResult) && item.Result == item.DefaultResult)
|
|
{
|
|
continue;
|
|
}
|
|
if (item.IsProduceSummary != 'Y')
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var doctorCheckItemDiagnosisResult = new DoctorCheckItemDiagnosisResult()
|
|
{
|
|
IsNameIntoSummary = item.IsNameIntoSummary,
|
|
ItemName = item.ItemName,
|
|
};
|
|
diagnosisList.Add(doctorCheckItemDiagnosisResult);
|
|
if (item.IsDiagnosisFunction == 'Y' && !string.IsNullOrWhiteSpace(item.DiagnosisFunction))
|
|
{
|
|
var itemResult = new ItemResultInput()
|
|
{
|
|
ItemId = item.ItemId,
|
|
ItemName = item.ItemName,
|
|
Result = item.Result
|
|
};
|
|
patientItemDiagnosisInput.Item = itemResult;
|
|
|
|
//通过计算获取诊断
|
|
var diagnosis = diagnosisBuilder.GetItemDiagnosisResult(patientItemDiagnosisInput, item.DiagnosisFunction);
|
|
|
|
var itemDiagnosisTypeResult = new ItemDiagnosisTypeResult()
|
|
{
|
|
DiagnosisType = '0'
|
|
};
|
|
itemDiagnosisTypeResult.Diagnosis.Add(diagnosis);
|
|
doctorCheckItemDiagnosisResult.ItemDiagnosisTypeResults.Add(itemDiagnosisTypeResult);
|
|
|
|
|
|
}
|
|
if (item.IsDiagnosisFunction == 'Y' && item.IsContinueProcess != 'Y')
|
|
{
|
|
continue;
|
|
}
|
|
//通过参考范围获取诊断
|
|
if (item.ReferenceRangeTypeFlag == ItemReferenceRangeTypeFlag.Number)
|
|
{
|
|
var referenceRangeDiagnosis = await GetItemDiagnosisByReferenceRanges(doctorCheckDiagnosisInput.SexId, doctorCheckDiagnosisInput.Age, item);
|
|
if (!string.IsNullOrWhiteSpace(referenceRangeDiagnosis))
|
|
{
|
|
var itemDiagnosisTypeResult = new ItemDiagnosisTypeResult()
|
|
{
|
|
DiagnosisType = '1'
|
|
};
|
|
itemDiagnosisTypeResult.Diagnosis.Add(referenceRangeDiagnosis);
|
|
doctorCheckItemDiagnosisResult.ItemDiagnosisTypeResults.Add(itemDiagnosisTypeResult);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
//通过结果模板获取诊断
|
|
var templateList = await GetItemDiagnosisByTemplate(item);
|
|
var itemDiagnosisTypeResult = new ItemDiagnosisTypeResult()
|
|
{
|
|
DiagnosisType = '2'
|
|
};
|
|
|
|
itemDiagnosisTypeResult.Diagnosis.AddRange(templateList);
|
|
|
|
//通过匹配关系获取诊断
|
|
var matcheList = await GetItemDiagnosisByMatche(item);
|
|
itemDiagnosisTypeResult.Diagnosis.AddRange(matcheList);
|
|
if (!templateList.Any() && !matcheList.Any())
|
|
{
|
|
//获取异常结果
|
|
itemDiagnosisTypeResult.Diagnosis.Add(item.Result);
|
|
|
|
}
|
|
//去掉重复诊断
|
|
itemDiagnosisTypeResult.Diagnosis = itemDiagnosisTypeResult.Diagnosis.Distinct().ToList();
|
|
doctorCheckItemDiagnosisResult.ItemDiagnosisTypeResults.Add(itemDiagnosisTypeResult);
|
|
|
|
|
|
}
|
|
|
|
}
|
|
return diagnosisList;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 通过参考范围获取项目诊断列表
|
|
/// </summary>
|
|
/// <param name="sexId"></param>
|
|
/// <param name="age"></param>
|
|
/// <param name="itemInput"></param>
|
|
/// <returns></returns>
|
|
private async Task<string> GetItemDiagnosisByReferenceRanges(char sexId, short? age, ItemInput itemInput)
|
|
{
|
|
var diagnosisList = new List<string>();
|
|
if (string.IsNullOrWhiteSpace(itemInput.Result))
|
|
{
|
|
return null;
|
|
}
|
|
decimal resultDecimal;
|
|
if (!decimal.TryParse(itemInput.Result, out resultDecimal))
|
|
{
|
|
return null;
|
|
}
|
|
var referenceRangeList = itemInput.ReferenceRanges.Where(o => o.ReferenceRangeTypeFlag == ItemReferenceRangeTypeFlag.Number).ToList();
|
|
if (!referenceRangeList.Any())
|
|
{
|
|
return null;
|
|
}
|
|
if (age == null)
|
|
{
|
|
age = 30;
|
|
}
|
|
var referenceRange = referenceRangeList.Where(o => o.ForSexId == sexId && age >= o.AgeLowerLimit && age <= o.AgeUpperLimit).FirstOrDefault();
|
|
if (referenceRange == null)
|
|
{
|
|
referenceRange = referenceRangeList.Where(o => o.ForSexId == ForSexFlag.All && age >= o.AgeLowerLimit && age <= o.AgeUpperLimit).FirstOrDefault();
|
|
if (referenceRange == null)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
string diagnosis = null;
|
|
// var pos = referenceRange.ReferenceRangeValue.IndexOf("-");
|
|
string resultStatusId = _registerCheckItemManager.GetNumberResultStatusId(itemInput.Result, referenceRange.ReferenceRangeValue);
|
|
if (resultStatusId == ResultStatusFlag.Low)
|
|
{
|
|
diagnosis = await GetNumberDiagnosis(itemInput.ItemName, itemInput.Result, itemInput.Unit, true, referenceRange);
|
|
}
|
|
else if (resultStatusId == ResultStatusFlag.High)
|
|
{
|
|
diagnosis = await GetNumberDiagnosis(itemInput.ItemName, itemInput.Result, itemInput.Unit, false, referenceRange);
|
|
}
|
|
|
|
return diagnosis;
|
|
}
|
|
|
|
|
|
private async Task<string> GetNumberDiagnosis(string itemName, string result, string unit, bool isLower,
|
|
ReferenceRange referenceRange)
|
|
{
|
|
string diagnosis = null;
|
|
if (isLower)
|
|
{
|
|
//偏低诊断
|
|
if (referenceRange.LowerDiagnosisId != null && referenceRange.LowerDiagnosisId != Guid.Empty)
|
|
{
|
|
var diagnosisEntity = await _diagnosisRepository.FindAsync(o => o.Id == referenceRange.LowerDiagnosisId);
|
|
if (diagnosisEntity != null)
|
|
{
|
|
diagnosis = diagnosisEntity.DisplayName + "↓";
|
|
}
|
|
else
|
|
{
|
|
if (_isAutoAddSuffix == "Y")
|
|
{
|
|
diagnosis = itemName + _lowerSuffix + "↓";
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if (_isAutoAddSuffix == "Y")
|
|
{
|
|
diagnosis = itemName + _lowerSuffix + "↓";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//偏高诊断
|
|
if (referenceRange.UpperDiagnosisId != null && referenceRange.UpperDiagnosisId != Guid.Empty)
|
|
{
|
|
var diagnosisEntity = await _diagnosisRepository.FindAsync(o => o.Id == referenceRange.UpperDiagnosisId);
|
|
if (diagnosisEntity != null)
|
|
{
|
|
diagnosis = diagnosisEntity.DisplayName + "↑";
|
|
}
|
|
else
|
|
{
|
|
if (_isAutoAddSuffix == "Y")
|
|
{
|
|
diagnosis = itemName + _highSuffix + "↑";
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if (_isAutoAddSuffix == "Y")
|
|
{
|
|
diagnosis = itemName + _highSuffix + "↑";
|
|
}
|
|
}
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(diagnosis))
|
|
{
|
|
if (_isAddAbnormalResult == "Y")
|
|
{
|
|
if (string.IsNullOrEmpty(unit))
|
|
{
|
|
unit = "";
|
|
}
|
|
diagnosis = diagnosis + $"(结果:{result} {unit},参考范围: {referenceRange.ReferenceRangeValue})";
|
|
}
|
|
}
|
|
return diagnosis;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过模板获取诊断
|
|
/// </summary>
|
|
/// <param name="itemInput"></param>
|
|
/// <returns></returns>
|
|
private async Task<List<string>> GetItemDiagnosisByTemplate(ItemInput itemInput)
|
|
{
|
|
List<string> diagnosisList = new List<string>();
|
|
//将结果解析到数组中
|
|
string[] resultArry = GetResultArry(itemInput.Result);
|
|
//结果模板中的结果去掉数字,* /等符号
|
|
foreach (var template in itemInput.ItemResultTemplates)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(template.Result))
|
|
{
|
|
|
|
//template.Result = Regex.Replace(template.Result, @"\d+", "").Replace("*", "").Replace("/", "").Replace(" ", "");
|
|
}
|
|
}
|
|
foreach (var resultSplit in resultArry)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(resultSplit) || resultSplit.StartsWith("余未见异常"))
|
|
{
|
|
continue;
|
|
}
|
|
var templatesList = itemInput.ItemResultTemplates.Where(o => o.Result == resultSplit && o.IsResultIntoSummary == 'Y').ToList();
|
|
foreach (var template in templatesList)
|
|
{
|
|
if (template != null && template.DiagnosisId != null && template.DiagnosisId != Guid.Empty)
|
|
{
|
|
var temp_diagnosis = await _diagnosisRepository.FirstOrDefaultAsync(m => m.Id == template.DiagnosisId);
|
|
if (temp_diagnosis != null)
|
|
{
|
|
diagnosisList.Add(temp_diagnosis.DisplayName);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
diagnosisList.Add(resultSplit);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
return diagnosisList.Distinct().ToList();
|
|
}
|
|
/// <summary>
|
|
/// 获取项目诊断通过匹配关系
|
|
/// </summary>
|
|
/// <param name="itemInput"></param>
|
|
/// <returns></returns>
|
|
private async Task<List<string>> GetItemDiagnosisByMatche(ItemInput itemInput)
|
|
{
|
|
List<string> diagnosisList = new List<string>();
|
|
//将结果解析到数组中
|
|
string[] resultArry = GetResultArry(itemInput.Result);
|
|
|
|
foreach (var resultSplit in resultArry)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(resultSplit) || resultSplit.StartsWith("余未见异常"))
|
|
{
|
|
continue;
|
|
}
|
|
var templatesList = itemInput.ItemResultMatches.Where(o => resultSplit.Contains(o.Result)).ToList();
|
|
foreach (var template in templatesList)
|
|
{
|
|
if (template != null && template.DiagnosisId != Guid.Empty)
|
|
{
|
|
var temp_diagnosis = await _diagnosisRepository.FirstOrDefaultAsync(m => m.Id == template.DiagnosisId);
|
|
if (temp_diagnosis != null)
|
|
{
|
|
diagnosisList.Add(temp_diagnosis.DisplayName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
return diagnosisList.Distinct().ToList();
|
|
}
|
|
/// <summary>
|
|
/// 去掉结果中的数字符号和分号
|
|
/// </summary>
|
|
/// <param name="result"></param>
|
|
/// <returns></returns>
|
|
private string[] GetResultArry(string result)
|
|
{
|
|
result = result.Trim().Replace(";", ";");
|
|
foreach (var num in _numArry)
|
|
{
|
|
result = result.Replace(num, "");
|
|
}
|
|
//将结果通过英文;解析到数组中
|
|
string[] resultArry = result.Split(";");
|
|
return resultArry;
|
|
}
|
|
#region 执行项目计算函数
|
|
|
|
/// <summary>
|
|
/// 生成计算函数值
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/diagnosisfunction/getcalculationfunctionresult")]
|
|
public async Task<GetDiagnosisResultRequestDto> GetCalculationFunctionResultAsync(GetDiagnosisResultRequestDto input)
|
|
{
|
|
await GetItemResultByCalculationFunctionAsync(input);
|
|
return input;
|
|
}
|
|
|
|
private async Task GetItemResultByCalculationFunctionAsync(GetDiagnosisResultRequestDto input)
|
|
{
|
|
//根据检查单ID查询
|
|
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 list)
|
|
{
|
|
if (item.Item.IsCalculationItem == 'Y' && !string.IsNullOrEmpty(item.Item.CalculationFunction))
|
|
{
|
|
//计算函数
|
|
//计算结果
|
|
|
|
string CalculationFunctionValue = diagnosisBuilder.GetItemCalculateResult(patientItemCalculateInput, item.Item.CalculationFunction);
|
|
//CalculationFunctionValue = GetCodeResult(input, item.CalculationFunction, list);
|
|
|
|
input.Items.Where(m => m.ItemId == item.Item.Id).FirstOrDefault().Result = CalculationFunctionValue; //赋值
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 执行项目 诊断函数
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <param name="item_datas"></param>
|
|
/// <param name="patientRegister_data"></param>
|
|
/// <param name="diagnosisTrips"></param>
|
|
/// <returns></returns>
|
|
private async Task<List<GetDiagnosisResult_Detail>> GetDiagnosisResultInItemAsync(GetDiagnosisResultRequestDto input, List<Item> item_datas, PatientRegister patientRegister_data, List<string> diagnosisTrips)
|
|
{
|
|
var reslist = new List<GetDiagnosisResult_Detail>();
|
|
|
|
if (input.Items.Count > 0)
|
|
{
|
|
foreach (var item_data in item_datas)
|
|
{
|
|
if (item_data.IsDiagnosisFunction == 'Y' && !string.IsNullOrEmpty(item_data.DiagnosisFunction))
|
|
{
|
|
var DiagnosisFunctionResult_Item = GetCodeResult(input, item_data.DiagnosisFunction, item_datas);
|
|
|
|
if (!string.IsNullOrEmpty(DiagnosisFunctionResult_Item))
|
|
{
|
|
reslist.Add(new GetDiagnosisResult_Detail
|
|
{
|
|
DiagnosisResult = DiagnosisFunctionResult_Item
|
|
});
|
|
}
|
|
|
|
//是否继续执行参考范围规则
|
|
if (item_data.IsContinueProcess == 'Y' && item_data.IsProduceSummary == 'Y')
|
|
{
|
|
string itemResult_Request = input.Items.Where(m => m.ItemId == item_data.Id).FirstOrDefault().Result; //项目结果
|
|
|
|
//执行参考范围
|
|
string referenceRangesResult = await GetDiagnosisResultInReferenceRangesAsync(item_data, itemResult_Request, patientRegister_data, diagnosisTrips);
|
|
if (!string.IsNullOrEmpty(referenceRangesResult))
|
|
{
|
|
if (item_data.IsNameIntoSummary == 'Y')
|
|
DiagnosisFunctionResult_Item = item_data.DisplayName + DiagnosisFunctionResult_Item;
|
|
reslist.Add(new GetDiagnosisResult_Detail { DiagnosisResult = referenceRangesResult });
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return reslist;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 执行项目 参考范围获取结果
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="itemResult"></param>
|
|
/// <param name="patientRegister_data"></param>
|
|
/// <param name="diagnosisTrips"></param>
|
|
/// <returns></returns>
|
|
private async Task<string> GetDiagnosisResultInReferenceRangesAsync(Item item, string itemResult, PatientRegister patientRegister_data, List<string> diagnosisTrips)
|
|
{
|
|
|
|
string referenceRangesResult = "";
|
|
string diagnosisTrip = ""; //诊断提示,参考范围性别、年龄 异常时出现
|
|
|
|
var item_ReferenceRangeList = item.ReferenceRanges.Where(m => m.ReferenceRangeTypeFlag == item.ReferenceRangeTypeFlag).ToList();
|
|
if (item_ReferenceRangeList.Any() && item.ReferenceRangeTypeFlag == ItemReferenceRangeTypeFlag.Number)
|
|
{
|
|
//数字参考范围
|
|
|
|
|
|
List<ReferenceRange> referenceRanges = new List<ReferenceRange>();
|
|
|
|
if (patientRegister_data.Age != null)
|
|
{
|
|
referenceRanges = item_ReferenceRangeList.Where(m => m.AgeLowerLimit <= patientRegister_data.Age
|
|
&& m.AgeUpperLimit >= patientRegister_data.Age).ToList();
|
|
|
|
}
|
|
else
|
|
{
|
|
//if (string.IsNullOrEmpty(DiagnosisTrip))
|
|
//{
|
|
// DiagnosisTrip += "未登记年龄";
|
|
//}
|
|
//else
|
|
//{
|
|
// DiagnosisTrip += ",未登记年龄";
|
|
//}
|
|
|
|
diagnosisTrip = "未登记年龄";
|
|
|
|
//找出默认的0-200
|
|
referenceRanges = item_ReferenceRangeList.Where(m => m.AgeLowerLimit == 0
|
|
&& m.AgeUpperLimit == 200).ToList();
|
|
}
|
|
|
|
if (referenceRanges.Any())
|
|
{
|
|
//比对性别
|
|
var referenceRanges2 = referenceRanges.Where(m => patientRegister_data.SexId != null && m.ForSexId == patientRegister_data.SexId).ToList();
|
|
|
|
if (!referenceRanges2.Any())
|
|
{
|
|
//未找到,去匹配适用性别为A的
|
|
referenceRanges2 = referenceRanges.Where(m => m.ForSexId == ForSexFlag.All).ToList();
|
|
|
|
if (referenceRanges2.Any())
|
|
{
|
|
//数字参考范围类型
|
|
referenceRangesResult = await GetDiagnosisResultInNumRangeAsync(item, itemResult, referenceRanges2[0]);
|
|
}
|
|
}
|
|
}
|
|
|
|
//////符合条件的参考范围
|
|
//var item_ReferenceRange = item_ReferenceRangeList.Where(m =>
|
|
//(m.ForSexId.ToString() == ForSexFlag.All || (patientRegister_data.SexId != null && m.ForSexId == patientRegister_data.SexId))
|
|
// && patientRegister_data.Age != null
|
|
// && m.AgeLowerLimit <= patientRegister_data.Age
|
|
// && m.AgeUpperLimit >= patientRegister_data.Age).ToList();
|
|
|
|
//if (item_ReferenceRange.Count > 0)
|
|
//{
|
|
// if (item_ReferenceRange.Count == 1)
|
|
// {
|
|
// //数字参考范围类型
|
|
// result = await GetDiagnosisResultInNumRangeAsync(item, itemResult, item_ReferenceRange[0]);
|
|
// }
|
|
|
|
//}
|
|
}
|
|
else
|
|
{
|
|
//无参考范围或者字符参考范围
|
|
referenceRangesResult = await GetDiagnosisResultInItemResultTemplateAsync(item, itemResult);
|
|
if (string.IsNullOrEmpty(referenceRangesResult))
|
|
{
|
|
//未匹配上,继续
|
|
referenceRangesResult = await GetDiagnosisResultInItemResultMatchAsync(item, itemResult);
|
|
|
|
if (string.IsNullOrEmpty(referenceRangesResult))
|
|
{
|
|
//未匹配上,继续
|
|
//对比项目默认结果,如果不是默认结果则直接用结果做为小结。
|
|
if (item.DefaultResult != itemResult)
|
|
{
|
|
referenceRangesResult = itemResult;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(diagnosisTrip))
|
|
diagnosisTrips.Add(diagnosisTrip);
|
|
|
|
|
|
return referenceRangesResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据项目结果模板生成
|
|
/// 检查项目结果模板,如果和项目结果模板一致,则根据对应的诊断生成小结 完全匹配
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task<string> GetDiagnosisResultInItemResultTemplateAsync(Item item, string itemResult)
|
|
{
|
|
string result = "";
|
|
var temp_itemResultTemplate = await _itemResultTemplateRepository.FirstOrDefaultAsync(m => m.ItemId == item.Id && m.Result == itemResult);
|
|
if (temp_itemResultTemplate != null && temp_itemResultTemplate.DiagnosisId != null && temp_itemResultTemplate.DiagnosisId != Guid.Empty)
|
|
{
|
|
var temp_diagnosis = await _diagnosisRepository.FirstOrDefaultAsync(m => m.Id == temp_itemResultTemplate.DiagnosisId);
|
|
if (temp_diagnosis != null)
|
|
{
|
|
result = temp_diagnosis.DisplayName;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 根据项目项目结果匹配(诊断匹配) 生成
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task<string> GetDiagnosisResultInItemResultMatchAsync(Item item, string itemResult)
|
|
{
|
|
string result = "";
|
|
var temp_itemResultMatch = await _itemResultMatchRepository.FirstOrDefaultAsync(m => m.ItemId == item.Id && itemResult.Contains(m.Result));
|
|
if (temp_itemResultMatch != null && temp_itemResultMatch.DiagnosisId != Guid.Empty)
|
|
{
|
|
var temp_diagnosis = await _diagnosisRepository.FirstOrDefaultAsync(m => m.Id == temp_itemResultMatch.DiagnosisId);
|
|
if (temp_diagnosis != null)
|
|
{
|
|
result = temp_diagnosis.DisplayName;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 根据数字型范围值对应的诊断匹配 生成
|
|
/// 如果在范围外又没有设置诊断,则用项目名称加偏高偏低后缀生成小结(需要根据系统参数)。
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <param name="itemResult"></param>
|
|
/// <param name="item_ReferenceRange">当前匹配的参考范围</param>
|
|
/// <returns></returns>
|
|
private async Task<string> GetDiagnosisResultInNumRangeAsync(Item item, string itemResult, ReferenceRange item_ReferenceRange)
|
|
{
|
|
|
|
string result = "";
|
|
|
|
|
|
string diagnosisFlag = "1"; //1=正常 2=偏高 0=偏低
|
|
|
|
|
|
#region 处理异常结果 > < = 剔除
|
|
|
|
itemResult = itemResult.Replace(">", "").Replace("<", "").Replace("=", "");
|
|
|
|
try
|
|
{
|
|
var tempConvert = Convert.ToDecimal(itemResult);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 匹配参考范围
|
|
|
|
string item_referenceRangeValue = item_ReferenceRange.ReferenceRangeValue;
|
|
if (item_referenceRangeValue.IndexOf("-") > -1)
|
|
{
|
|
var value_ary = item_referenceRangeValue.Split('-');
|
|
if (value_ary.Length == 2)
|
|
{
|
|
decimal minvalue = Convert.ToDecimal(value_ary[0]);
|
|
decimal maxvalue = Convert.ToDecimal(value_ary[1]);
|
|
|
|
|
|
|
|
if (Convert.ToDecimal(itemResult) > maxvalue)
|
|
{
|
|
//偏高
|
|
diagnosisFlag = "2";
|
|
}
|
|
else if (Convert.ToDecimal(itemResult) < minvalue)
|
|
{
|
|
//偏低
|
|
diagnosisFlag = "0";
|
|
}
|
|
}
|
|
}
|
|
else if (item_referenceRangeValue.IndexOf(">=") > -1)
|
|
{
|
|
if (Convert.ToDecimal(itemResult) < Convert.ToDecimal(item_referenceRangeValue.Replace(">=", "")))
|
|
{
|
|
//偏低
|
|
diagnosisFlag = "0";
|
|
}
|
|
}
|
|
else if (item_referenceRangeValue.IndexOf("<=") > -1)
|
|
{
|
|
if (Convert.ToDecimal(itemResult) > Convert.ToDecimal(item_referenceRangeValue.Replace("<=", "")))
|
|
{
|
|
//偏高
|
|
diagnosisFlag = "2";
|
|
}
|
|
}
|
|
else if (item_referenceRangeValue.IndexOf(">") > -1)
|
|
{
|
|
if (Convert.ToDecimal(itemResult) <= Convert.ToDecimal(item_referenceRangeValue.Replace(">", "")))
|
|
{
|
|
//偏低
|
|
diagnosisFlag = "0";
|
|
}
|
|
}
|
|
else if (item_referenceRangeValue.IndexOf("<") > -1)
|
|
{
|
|
if (Convert.ToDecimal(itemResult) >= Convert.ToDecimal(item_referenceRangeValue.Replace("<", "")))
|
|
{
|
|
//偏高
|
|
diagnosisFlag = "2";
|
|
}
|
|
}
|
|
|
|
|
|
if (diagnosisFlag == "2")
|
|
{
|
|
//偏高
|
|
if (item_ReferenceRange.UpperDiagnosisId != null)
|
|
{
|
|
var temp_diagnosis = await _diagnosisRepository.FirstOrDefaultAsync(m => m.Id == item_ReferenceRange.UpperDiagnosisId);
|
|
if (temp_diagnosis != null)
|
|
{
|
|
result = temp_diagnosis.DisplayName;
|
|
}
|
|
else
|
|
{
|
|
result = $"{item.DisplayName}偏高";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = $"{item.DisplayName}偏高";
|
|
}
|
|
}
|
|
else if (diagnosisFlag == "0")
|
|
{
|
|
//偏低
|
|
if (item_ReferenceRange.LowerDiagnosisId != null)
|
|
{
|
|
var temp_diagnosis = await _diagnosisRepository.FirstOrDefaultAsync(m => m.Id == item_ReferenceRange.LowerDiagnosisId);
|
|
if (temp_diagnosis != null)
|
|
{
|
|
result = temp_diagnosis.DisplayName;
|
|
}
|
|
else
|
|
{
|
|
result = $"{item.DisplayName}偏低";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = $"{item.DisplayName}偏低";
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 动态编译代码 返回string
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <param name="DiagnosisFunctionCode"></param>
|
|
/// <param name="item_datas"></param>
|
|
/// <returns></returns>
|
|
private string GetCodeResult(GetDiagnosisResultRequestDto input, string DiagnosisFunctionCode, List<Item> item_datas)
|
|
{
|
|
string result = "";
|
|
|
|
string DiagnosisFunctionCode_Replace = ReplaceFunctionLabel(input, DiagnosisFunctionCode, item_datas);
|
|
|
|
//拼接动态代码
|
|
string code = @"
|
|
|
|
public class DiagnosisResultInAsbitemHeight
|
|
{
|
|
public string AutoDiagnosisResultInAsbitemHeight()
|
|
{
|
|
var msg="""";"
|
|
+ DiagnosisFunctionCode_Replace + @"
|
|
return msg;
|
|
}
|
|
}";
|
|
|
|
CompileHelper compileHelper = new CompileHelper();
|
|
|
|
var assembly = compileHelper.GenerateAssemblyFromCode(code, Assembly.Load(new AssemblyName("System.Runtime")), typeof(object).Assembly);
|
|
|
|
if (assembly != null)
|
|
{
|
|
|
|
// 反射获取程序集中 的类
|
|
Type type = assembly.GetType("DiagnosisResultInAsbitemHeight");
|
|
|
|
// 创建该类的实例
|
|
object obj = Activator.CreateInstance(type);
|
|
|
|
var msg = type.InvokeMember("AutoDiagnosisResultInAsbitemHeight",
|
|
BindingFlags.Default | BindingFlags.InvokeMethod,
|
|
null,
|
|
obj,
|
|
null);
|
|
|
|
if (!string.IsNullOrEmpty(msg.ToString()))
|
|
{
|
|
result = msg.ToString();
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 替换函数中的标签
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <param name="DiagnosisFunctionCode"></param>
|
|
/// <param name="item_datas"></param>
|
|
/// <returns></returns>
|
|
private string ReplaceFunctionLabel(GetDiagnosisResultRequestDto input, string DiagnosisFunctionCode, List<Item> item_datas)
|
|
{
|
|
string tempcode = DiagnosisFunctionCode;
|
|
|
|
//替换诊断函数中的标签
|
|
foreach (var item in input.Items)
|
|
{
|
|
if (item.ItemId != null)
|
|
{
|
|
var itement = item_datas.Where(m => m.Id == item.ItemId).FirstOrDefault(); //查询项目信息
|
|
if (itement != null)
|
|
{
|
|
//根据项目的名称 替换对应传过来的值
|
|
tempcode = tempcode.Replace($"[{itement.DisplayName}]", item.Result);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
if (tempcode.IndexOf('[') != -1)
|
|
{
|
|
throw new UserFriendlyException("函数中有未识别的语法");
|
|
}
|
|
|
|
return tempcode;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region 危急值函数
|
|
|
|
/// <summary>
|
|
/// 获取人员是否有危急值项目
|
|
/// 【优先处理组合项目危急值函数
|
|
/// 未触发时执行项目危急值函数
|
|
/// 未触发项目检索危急值关键字
|
|
/// 未触发检索小结是否包含危急值关键字】
|
|
/// </summary>
|
|
/// <param name="doctorCheckDiagnosisInput"></param>
|
|
/// <param name="resultDto"></param>
|
|
/// <param name="criticalResultDtoList"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> GetPatientRegisterIsCriticalAsync(
|
|
DoctorCheckDiagnosisInput doctorCheckDiagnosisInput,
|
|
GetDiagnosisResultDto resultDto,
|
|
List<GetCriticalResultDto> criticalResultDtoList)
|
|
{
|
|
var isCritical = false;
|
|
|
|
isCritical = GetAsbitemCriticalFunction(doctorCheckDiagnosisInput, criticalResultDtoList);
|
|
|
|
if (isCritical)
|
|
{
|
|
return isCritical;
|
|
}
|
|
|
|
var criticalFollowValueList = await _criticalFollowValueRepository.GetListAsync(m => m.CriticalFollowValueFlag == CriticalFollowValueFlag.Critical);
|
|
|
|
//检索项目函数+关键字
|
|
isCritical = GetItemCriticalFunction(doctorCheckDiagnosisInput, criticalFollowValueList, criticalResultDtoList);
|
|
|
|
if (isCritical)
|
|
{
|
|
return isCritical;
|
|
}
|
|
|
|
//检索小结
|
|
foreach (var diagnosisResult in resultDto.DiagnosisResultDetails)
|
|
{
|
|
isCritical = criticalFollowValueList.Count(m => diagnosisResult.DiagnosisResult.Contains(m.DisplayName)) > 0 ? true : false;
|
|
if (isCritical)
|
|
break;
|
|
}
|
|
|
|
return isCritical;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取人员是否有需要随访的项目
|
|
/// 【优先处理组合项目随访函数
|
|
/// 未触发时执行项目随访函数
|
|
/// 未触发项目检索随访关键字
|
|
/// 未触发检索小结是否包含随访关键字】
|
|
/// </summary>
|
|
/// <param name="doctorCheckDiagnosisInput"></param>
|
|
/// <param name="resultDto"></param>
|
|
/// <param name="criticalResultDtoList"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> GetPatientRegisterIsFollowUpAsync(
|
|
DoctorCheckDiagnosisInput doctorCheckDiagnosisInput,
|
|
GetDiagnosisResultDto resultDto,
|
|
List<GetCriticalResultDto> criticalResultDtoList)
|
|
{
|
|
var isCritical = false;
|
|
|
|
isCritical = GetAsbitemFollowUpFunction(doctorCheckDiagnosisInput, criticalResultDtoList);
|
|
|
|
if (isCritical)
|
|
{
|
|
return isCritical;
|
|
}
|
|
|
|
var criticalFollowValueList = await _criticalFollowValueRepository.GetListAsync(m => m.CriticalFollowValueFlag == CriticalFollowValueFlag.FollowUp);
|
|
|
|
//检索项目函数+关键字
|
|
isCritical = GetItemFollowUpFunction(doctorCheckDiagnosisInput, criticalFollowValueList, criticalResultDtoList);
|
|
|
|
if (isCritical)
|
|
{
|
|
return isCritical;
|
|
}
|
|
|
|
//检索小结
|
|
foreach (var diagnosisResult in resultDto.DiagnosisResultDetails)
|
|
{
|
|
isCritical = criticalFollowValueList.Count(m => diagnosisResult.DiagnosisResult.Contains(m.DisplayName)) > 0 ? true : false;
|
|
if (isCritical)
|
|
break;
|
|
}
|
|
|
|
return isCritical;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 组合项目危急值函数
|
|
/// </summary>
|
|
/// <param name="doctorCheckDiagnosisInput"></param>
|
|
/// <param name="criticalResultDtoList"></param>
|
|
/// <returns></returns>
|
|
private bool GetAsbitemCriticalFunction(DoctorCheckDiagnosisInput doctorCheckDiagnosisInput, List<GetCriticalResultDto> criticalResultDtoList)
|
|
{
|
|
bool isCritical = false;
|
|
var patientAsbitemDiagnosisInput = new PatientAsbitemDiagnosisInput()
|
|
{
|
|
SexName = doctorCheckDiagnosisInput.SexName,
|
|
Age = doctorCheckDiagnosisInput.Age
|
|
};
|
|
|
|
foreach (var item in doctorCheckDiagnosisInput.Items)
|
|
{
|
|
var itemResult = new ItemResultInput()
|
|
{
|
|
ItemId = item.ItemId,
|
|
ItemName = item.ItemName,
|
|
Result = item.Result
|
|
};
|
|
patientAsbitemDiagnosisInput.Items.Add(itemResult);
|
|
}
|
|
var diagnosisBuilder = new DiagnosisBuilder();
|
|
|
|
foreach (var asbitem in doctorCheckDiagnosisInput.Asbitems)
|
|
{
|
|
if (asbitem.IsCriticalValueFunction == 'Y' && !string.IsNullOrWhiteSpace(asbitem.CriticalValueFunction))
|
|
{
|
|
isCritical = diagnosisBuilder.GetAsbitemCriticalResult(patientAsbitemDiagnosisInput, asbitem.DiagnosisFunction);
|
|
if (isCritical)
|
|
{
|
|
UpdateRegisterCheckCriticalResult(criticalResultDtoList, asbitem.RegisterCheckId, 'Y', 'Y', "");
|
|
//await CreateRegisterCheckCritical(asbitem.RegisterCheckId, 'Y', "");
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
UpdateRegisterCheckCriticalResult(criticalResultDtoList, asbitem.RegisterCheckId, 'N', null, "");
|
|
}
|
|
}
|
|
}
|
|
|
|
return isCritical;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 项目危急值函数
|
|
/// </summary>
|
|
/// <param name="doctorCheckDiagnosisInput"></param>
|
|
/// <param name="criticalFollowValueList"></param>
|
|
/// <param name="criticalResultDtoList"></param>
|
|
/// <returns></returns>
|
|
private bool GetItemCriticalFunction(
|
|
DoctorCheckDiagnosisInput doctorCheckDiagnosisInput,
|
|
List<CriticalFollowValue> criticalFollowValueList,
|
|
List<GetCriticalResultDto> criticalResultDtoList
|
|
)
|
|
{
|
|
bool isCritical = false;
|
|
var patientItemDiagnosisInput = new PatientItemDiagnosisInput()
|
|
{
|
|
SexName = doctorCheckDiagnosisInput.SexName,
|
|
Age = doctorCheckDiagnosisInput.Age
|
|
};
|
|
|
|
var diagnosisBuilder = new DiagnosisBuilder();
|
|
|
|
foreach (var item in doctorCheckDiagnosisInput.Items)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(item.Result))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (item.IsCriticalValueFunction == 'Y' && !string.IsNullOrWhiteSpace(item.CriticalValueFunction))
|
|
{
|
|
var itemResult = new ItemResultInput()
|
|
{
|
|
ItemId = item.ItemId,
|
|
ItemName = item.ItemName,
|
|
Result = item.Result
|
|
};
|
|
patientItemDiagnosisInput.Item = itemResult;
|
|
|
|
|
|
isCritical = diagnosisBuilder.GetItemCriticalResult(patientItemDiagnosisInput, item.CriticalValueFunction);
|
|
|
|
if (isCritical)
|
|
{
|
|
|
|
UpdateRegisterCheckItemCriticalResult(criticalResultDtoList, item.RegisterCheckId, item.ItemId, 'Y', 'Y', "");
|
|
//await CreateRegisterCheckItemCritical(item.RegisterCheckId, item.ItemId, 'Y', "");
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
UpdateRegisterCheckItemCriticalResult(criticalResultDtoList, item.RegisterCheckId, item.ItemId, 'N', null, "");
|
|
}
|
|
}
|
|
|
|
|
|
#region 执行项目参考范围
|
|
var referenceRange = item.ReferenceRanges.Where(o => o.ForSexId == doctorCheckDiagnosisInput.SexId && doctorCheckDiagnosisInput.Age >= o.AgeLowerLimit && doctorCheckDiagnosisInput.Age <= o.AgeUpperLimit).FirstOrDefault();
|
|
if (referenceRange == null)
|
|
{
|
|
referenceRange = item.ReferenceRanges.Where(o => o.ForSexId == ForSexFlag.All && doctorCheckDiagnosisInput.Age >= o.AgeLowerLimit && doctorCheckDiagnosisInput.Age <= o.AgeUpperLimit).FirstOrDefault();
|
|
if (referenceRange != null && !string.IsNullOrWhiteSpace(referenceRange.CriticalRangeValue))
|
|
{
|
|
|
|
isCritical = _registerCheckItemManager.GetNumberResultIsCritical(item.Result, referenceRange.CriticalRangeValue);
|
|
if (isCritical)
|
|
{
|
|
UpdateRegisterCheckItemCriticalResult(criticalResultDtoList, item.RegisterCheckId, item.ItemId, 'Y', 'Y', referenceRange.CriticalRangeValue);
|
|
//await CreateRegisterCheckItemCritical(item.RegisterCheckId, item.ItemId, 'Y', "");
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
UpdateRegisterCheckItemCriticalResult(criticalResultDtoList, item.RegisterCheckId, item.ItemId, 'N', null, "");
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
var isCriticalFollowValue = criticalFollowValueList.FirstOrDefault(m => item.Result.Contains(m.DisplayName));
|
|
|
|
//关键字检索
|
|
if (isCriticalFollowValue != null)
|
|
{
|
|
isCritical = true;
|
|
}
|
|
|
|
if (isCritical)
|
|
{
|
|
UpdateRegisterCheckItemCriticalResult(criticalResultDtoList, item.RegisterCheckId, item.ItemId, 'Y', 'Y', isCriticalFollowValue.DisplayName);
|
|
//await CreateRegisterCheckItemCritical(item.RegisterCheckId, item.ItemId, 'Y', isCriticalFollowValue.DisplayName);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
UpdateRegisterCheckItemCriticalResult(criticalResultDtoList, item.RegisterCheckId, item.ItemId, 'N', null, "");
|
|
}
|
|
|
|
}
|
|
|
|
return isCritical;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 组合项目随访函数
|
|
/// </summary>
|
|
/// <param name="doctorCheckDiagnosisInput"></param>
|
|
/// <param name="criticalResultDtoList"></param>
|
|
/// <returns></returns>
|
|
private bool GetAsbitemFollowUpFunction(DoctorCheckDiagnosisInput doctorCheckDiagnosisInput, List<GetCriticalResultDto> criticalResultDtoList)
|
|
{
|
|
bool isFollowUp = false;
|
|
var patientAsbitemDiagnosisInput = new PatientAsbitemDiagnosisInput()
|
|
{
|
|
SexName = doctorCheckDiagnosisInput.SexName,
|
|
Age = doctorCheckDiagnosisInput.Age
|
|
};
|
|
|
|
foreach (var item in doctorCheckDiagnosisInput.Items)
|
|
{
|
|
var itemResult = new ItemResultInput()
|
|
{
|
|
ItemId = item.ItemId,
|
|
ItemName = item.ItemName,
|
|
Result = item.Result
|
|
};
|
|
patientAsbitemDiagnosisInput.Items.Add(itemResult);
|
|
}
|
|
var diagnosisBuilder = new DiagnosisBuilder();
|
|
|
|
foreach (var asbitem in doctorCheckDiagnosisInput.Asbitems)
|
|
{
|
|
if (asbitem.IsFollowUpFunction == 'Y' && !string.IsNullOrWhiteSpace(asbitem.FollowUpFunction))
|
|
{
|
|
isFollowUp = diagnosisBuilder.GetAsbitemFollowUpResult(patientAsbitemDiagnosisInput, asbitem.DiagnosisFunction);
|
|
if (isFollowUp)
|
|
{
|
|
UpdateRegisterCheckCriticalResult(criticalResultDtoList, asbitem.RegisterCheckId, null, 'Y', "");
|
|
//await CreateRegisterCheckCritical(asbitem.RegisterCheckId, 'Y', "");
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
UpdateRegisterCheckCriticalResult(criticalResultDtoList, asbitem.RegisterCheckId, null, 'N', "");
|
|
}
|
|
}
|
|
}
|
|
|
|
return isFollowUp;
|
|
}
|
|
/// <summary>
|
|
/// 项目随访函数
|
|
/// </summary>
|
|
/// <param name="doctorCheckDiagnosisInput"></param>
|
|
/// <param name="criticalFollowValueList"></param>
|
|
/// <param name="criticalResultDtoList"></param>
|
|
/// <returns></returns>
|
|
private bool GetItemFollowUpFunction(
|
|
DoctorCheckDiagnosisInput doctorCheckDiagnosisInput,
|
|
List<CriticalFollowValue> criticalFollowValueList,
|
|
List<GetCriticalResultDto> criticalResultDtoList
|
|
)
|
|
{
|
|
bool isFollowUp = false;
|
|
var patientItemDiagnosisInput = new PatientItemDiagnosisInput()
|
|
{
|
|
SexName = doctorCheckDiagnosisInput.SexName,
|
|
Age = doctorCheckDiagnosisInput.Age
|
|
};
|
|
|
|
var diagnosisBuilder = new DiagnosisBuilder();
|
|
|
|
foreach (var item in doctorCheckDiagnosisInput.Items)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(item.Result))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (item.IsFollowUpFunction == 'Y' && !string.IsNullOrWhiteSpace(item.FollowUpFunction))
|
|
{
|
|
var itemResult = new ItemResultInput()
|
|
{
|
|
ItemId = item.ItemId,
|
|
ItemName = item.ItemName,
|
|
Result = item.Result
|
|
};
|
|
patientItemDiagnosisInput.Item = itemResult;
|
|
|
|
|
|
isFollowUp = diagnosisBuilder.GetItemFollowUpResult(patientItemDiagnosisInput, item.FollowUpFunction);
|
|
|
|
if (isFollowUp)
|
|
{
|
|
UpdateRegisterCheckItemCriticalResult(criticalResultDtoList, item.RegisterCheckId, item.ItemId, null, 'Y', "");
|
|
// await CreateRegisterCheckItemCritical(item.RegisterCheckId, item.ItemId, 'N', "");
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
UpdateRegisterCheckItemCriticalResult(criticalResultDtoList, item.RegisterCheckId, item.ItemId, null, 'N', "");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
#region 执行项目参考范围
|
|
var referenceRange = item.ReferenceRanges.Where(o => o.ForSexId == doctorCheckDiagnosisInput.SexId && doctorCheckDiagnosisInput.Age >= o.AgeLowerLimit && doctorCheckDiagnosisInput.Age <= o.AgeUpperLimit).FirstOrDefault();
|
|
if (referenceRange == null)
|
|
{
|
|
referenceRange = item.ReferenceRanges.Where(o => o.ForSexId == ForSexFlag.All && doctorCheckDiagnosisInput.Age >= o.AgeLowerLimit && doctorCheckDiagnosisInput.Age <= o.AgeUpperLimit).FirstOrDefault();
|
|
if (referenceRange != null && !string.IsNullOrWhiteSpace(referenceRange.FollowUpRangeValue))
|
|
{
|
|
|
|
isFollowUp = _registerCheckItemManager.GetNumberResultIsFollow(item.Result, referenceRange.FollowUpRangeValue);
|
|
if (isFollowUp)
|
|
{
|
|
UpdateRegisterCheckItemCriticalResult(criticalResultDtoList, item.RegisterCheckId, item.ItemId, null, 'Y', referenceRange.FollowUpRangeValue);
|
|
//await CreateRegisterCheckItemCritical(item.RegisterCheckId, item.ItemId, 'N', referenceRange.FollowUpRangeValue);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
UpdateRegisterCheckItemCriticalResult(criticalResultDtoList, item.RegisterCheckId, item.ItemId, null, 'N', "");
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
var isCriticalFollowValue = criticalFollowValueList.FirstOrDefault(m => item.Result.Contains(m.DisplayName));
|
|
|
|
if (isCriticalFollowValue != null)
|
|
{
|
|
isFollowUp = true;
|
|
}
|
|
|
|
if (isFollowUp)
|
|
{
|
|
UpdateRegisterCheckItemCriticalResult(criticalResultDtoList, item.RegisterCheckId, item.ItemId, null, 'Y', isCriticalFollowValue.DisplayName);
|
|
// await CreateRegisterCheckItemCritical(item.RegisterCheckId, item.ItemId, 'N', isCriticalFollowValue.DisplayName);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
UpdateRegisterCheckItemCriticalResult(criticalResultDtoList, item.RegisterCheckId, item.ItemId, null, 'N', "");
|
|
}
|
|
|
|
}
|
|
|
|
return isFollowUp;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 生成危急值标记、随访记录
|
|
/// </summary>
|
|
/// <param name="patientRegisterId"></param>
|
|
private async Task CreateFollowUpAsync(Guid patientRegisterId)
|
|
{
|
|
var isFollowUp = await _followUpRepository.FirstOrDefaultAsync(f => f.PatientRegisterId == patientRegisterId);
|
|
if (isFollowUp == null)
|
|
{
|
|
var followUpEnt = new FollowUp
|
|
{
|
|
IsPhoneComplete = 'N',
|
|
IsSmsComplete = 'N',
|
|
PatientRegisterId = patientRegisterId
|
|
};
|
|
|
|
await _followUpRepository.InsertAsync(followUpEnt);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成明细表危急值相关数据
|
|
/// </summary>
|
|
/// <param name="registerCheckId"></param>
|
|
/// <param name="itemId"></param>
|
|
/// <param name="isCriticalValue"></param>
|
|
/// <param name="isFollowUp"></param>
|
|
/// <param name="CriticalRangeValue"></param>
|
|
/// <returns></returns>
|
|
private async Task CreateRegisterCheckItemCritical(Guid registerCheckId, Guid itemId, char? isCriticalValue, char? isFollowUp, string CriticalRangeValue)
|
|
{
|
|
var registerCheckItemEnt = await _registerCheckItemRepository.FirstOrDefaultAsync(m => m.RegisterCheckId == registerCheckId
|
|
&& m.ItemId == itemId);
|
|
if (registerCheckItemEnt != null)
|
|
{
|
|
registerCheckItemEnt.CriticalRangeValue = CriticalRangeValue;
|
|
registerCheckItemEnt.IsCriticalValue = isCriticalValue;
|
|
if (isCriticalValue == 'Y')
|
|
{
|
|
registerCheckItemEnt.CriticalValueCreatorId = _currentUser.Id;
|
|
registerCheckItemEnt.CriticalValueCreationTime = DateTime.Now;
|
|
}
|
|
if (isFollowUp == 'Y')
|
|
{
|
|
registerCheckItemEnt.FollowUpCreatorId = _currentUser.Id;
|
|
registerCheckItemEnt.FollowUpCreationTime = DateTime.Now;
|
|
}
|
|
//registerCheckItemEnt.IsCriticalValueAudit = 'N';
|
|
//registerCheckItemEnt.IsReview = 'N';
|
|
registerCheckItemEnt.IsFollowUp = isFollowUp;
|
|
|
|
await _registerCheckItemRepository.UpdateAsync(registerCheckItemEnt);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成registerCheck表危急值相关数据
|
|
/// </summary>
|
|
/// <param name="registerCheckId"></param>
|
|
/// <param name="isCriticalValue"></param>
|
|
/// <param name="isFollowUp"></param>
|
|
/// <param name="CriticalRangeValue"></param>
|
|
/// <returns></returns>
|
|
private async Task CreateRegisterCheckCritical(Guid registerCheckId, char? isCriticalValue, char? isFollowUp, string CriticalRangeValue)
|
|
{
|
|
var registerCheckEnt = await _registerCheckRepository.FirstOrDefaultAsync(m => m.Id == registerCheckId);
|
|
if (registerCheckEnt != null)
|
|
{
|
|
registerCheckEnt.CriticalRangeValue = CriticalRangeValue;
|
|
|
|
if (isCriticalValue == 'Y')
|
|
{
|
|
registerCheckEnt.CriticalValueCreatorId = _currentUser.Id;
|
|
registerCheckEnt.CriticalValueCreationTime = DateTime.Now;
|
|
registerCheckEnt.IsCriticalValue = isCriticalValue;
|
|
}
|
|
if (isFollowUp == 'Y')
|
|
{
|
|
registerCheckEnt.FollowUpCreatorId = _currentUser.Id;
|
|
registerCheckEnt.FollowUpCreationTime = DateTime.Now;
|
|
}
|
|
//registerCheckEnt.IsCriticalValueAudit = 'N';
|
|
//registerCheckEnt.IsReview = 'N';
|
|
registerCheckEnt.IsFollowUp = isFollowUp;
|
|
|
|
await _registerCheckRepository.UpdateAsync(registerCheckEnt);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 临时更新危急值状态 registerCheck
|
|
/// </summary>
|
|
/// <param name="criticalResultDtoList"></param>
|
|
/// <param name="registerCheckId"></param>
|
|
/// <param name="isCritical"></param>
|
|
/// <param name="isFollowUp"></param>
|
|
/// <param name="criticalRangeValue"></param>
|
|
private void UpdateRegisterCheckCriticalResult(List<GetCriticalResultDto> criticalResultDtoList, Guid registerCheckId, char? isCritical, char? isFollowUp, string criticalRangeValue)
|
|
{
|
|
if (criticalResultDtoList.Where(m => m.RegisterCheckId == registerCheckId).Count() == 0)
|
|
{
|
|
criticalResultDtoList.Add(new GetCriticalResultDto
|
|
{
|
|
RegisterCheckId = registerCheckId
|
|
});
|
|
}
|
|
else
|
|
{
|
|
foreach (var criticalResultDto in criticalResultDtoList)
|
|
{
|
|
if (criticalResultDto.RegisterCheckId == registerCheckId)
|
|
{
|
|
if (isCritical != null && criticalResultDto.IsCritical != 'Y')
|
|
{
|
|
criticalResultDto.IsCritical = isCritical;
|
|
}
|
|
if (isFollowUp != null && criticalResultDto.IsFollowUp != 'Y')
|
|
{
|
|
criticalResultDto.IsFollowUp = isFollowUp;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(criticalRangeValue))
|
|
{
|
|
criticalResultDto.CriticalRangeValue = criticalRangeValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 临时更新危急值状态 registerCheckItem
|
|
/// </summary>
|
|
/// <param name="criticalResultDtoList"></param>
|
|
/// <param name="registerCheckId"></param>
|
|
/// <param name="itemId"></param>
|
|
/// <param name="isCritical"></param>
|
|
/// <param name="isFollowUp"></param>
|
|
/// <param name="criticalRangeValue"></param>
|
|
private void UpdateRegisterCheckItemCriticalResult(List<GetCriticalResultDto> criticalResultDtoList, Guid registerCheckId, Guid itemId, char? isCritical, char? isFollowUp, string criticalRangeValue)
|
|
{
|
|
|
|
//先增加registerCheck
|
|
if (criticalResultDtoList.Where(m => m.RegisterCheckId == registerCheckId).Count() == 0)
|
|
{
|
|
criticalResultDtoList.Add(new GetCriticalResultDto
|
|
{
|
|
RegisterCheckId = registerCheckId
|
|
});
|
|
}
|
|
|
|
foreach (var criticalResultDto in criticalResultDtoList)
|
|
{
|
|
if (criticalResultDto.RegisterCheckId == registerCheckId)
|
|
{
|
|
|
|
if (criticalResultDto.ItemDetails.Where(m => m.ItemId == itemId).Count() == 0)
|
|
{
|
|
var itemCriticalResultDto = new GetItemCriticalResultDto();
|
|
itemCriticalResultDto.RegisterCheckId = registerCheckId;
|
|
itemCriticalResultDto.ItemId = itemId;
|
|
if (isFollowUp != null && itemCriticalResultDto.IsFollowUp != 'Y')
|
|
{
|
|
itemCriticalResultDto.IsFollowUp = isFollowUp;
|
|
}
|
|
if (isCritical != null && itemCriticalResultDto.IsCritical != 'Y')
|
|
{
|
|
itemCriticalResultDto.IsCritical = isCritical;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(criticalRangeValue))
|
|
{
|
|
itemCriticalResultDto.CriticalRangeValue = criticalRangeValue;
|
|
}
|
|
|
|
criticalResultDto.ItemDetails.Add(itemCriticalResultDto);
|
|
}
|
|
else
|
|
{
|
|
foreach (var itemCriticalResultDto in criticalResultDto.ItemDetails)
|
|
{
|
|
if (itemCriticalResultDto.ItemId == itemId)
|
|
{
|
|
itemCriticalResultDto.RegisterCheckId = registerCheckId;
|
|
itemCriticalResultDto.ItemId = itemId;
|
|
if (isFollowUp != null && itemCriticalResultDto.IsFollowUp != 'Y')
|
|
{
|
|
itemCriticalResultDto.IsFollowUp = isFollowUp;
|
|
}
|
|
if (isCritical != null && itemCriticalResultDto.IsCritical != 'Y')
|
|
{
|
|
itemCriticalResultDto.IsCritical = isCritical;
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(criticalRangeValue))
|
|
{
|
|
itemCriticalResultDto.CriticalRangeValue = criticalRangeValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 处理危急值记录
|
|
/// </summary>
|
|
/// <param name="criticalResultDtoList"></param>
|
|
/// <param name="patientRegisterId"></param>
|
|
/// <returns></returns>
|
|
private async Task HandCriticalResult(List<GetCriticalResultDto> criticalResultDtoList, Guid patientRegisterId)
|
|
{
|
|
bool isCreateFollowUp = false;
|
|
foreach (var criticalResultDto in criticalResultDtoList)
|
|
{
|
|
|
|
foreach (var itemCriticalResultDto in criticalResultDto.ItemDetails)
|
|
{
|
|
if (itemCriticalResultDto.IsCritical == 'Y' || itemCriticalResultDto.IsFollowUp == 'Y')
|
|
{
|
|
isCreateFollowUp = true;
|
|
if (itemCriticalResultDto.IsCritical == 'Y')
|
|
{
|
|
criticalResultDto.IsCritical = itemCriticalResultDto.IsCritical;
|
|
}
|
|
if (itemCriticalResultDto.IsFollowUp == 'Y')
|
|
{
|
|
criticalResultDto.IsFollowUp = itemCriticalResultDto.IsFollowUp;
|
|
}
|
|
|
|
}
|
|
await CreateRegisterCheckItemCritical(itemCriticalResultDto.RegisterCheckId, itemCriticalResultDto.ItemId, itemCriticalResultDto.IsCritical, itemCriticalResultDto.IsFollowUp, itemCriticalResultDto.CriticalRangeValue);
|
|
}
|
|
|
|
if (criticalResultDto.IsCritical == 'Y' || criticalResultDto.IsFollowUp == 'Y')
|
|
{
|
|
isCreateFollowUp = true;
|
|
|
|
}
|
|
await CreateRegisterCheckCritical(criticalResultDto.RegisterCheckId, criticalResultDto.IsCritical, criticalResultDto.IsFollowUp, criticalResultDto.CriticalRangeValue);
|
|
|
|
}
|
|
|
|
if (isCreateFollowUp)
|
|
{
|
|
//增加随访主表记录
|
|
await _followUpAppService.CreateAsync(new PatientRegisterIdInputDto
|
|
{
|
|
PatientRegisterId = patientRegisterId
|
|
});
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
//删除随访表记录
|
|
await _followUpAppService.DeleteByPatientRegisterId(new PatientRegisterIdInputDto
|
|
{
|
|
PatientRegisterId = patientRegisterId
|
|
});
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
}
|