Browse Source

ai+体检报告上的结论筛选

master
wxd 6 months ago
parent
commit
7645e9fbbd
  1. 71
      src/Shentun.Peis.Application.Contracts/AIMessages/DeepSeekResponse.cs
  2. 11
      src/Shentun.Peis.Application.Contracts/AIMessages/GetAIMessageResultDto.cs
  3. 11
      src/Shentun.Peis.Application.Contracts/AIMessages/GetAIMessageResultInputDto.cs
  4. 5
      src/Shentun.Peis.Application.Contracts/PeisReports/GetPatientRegisterReportRequestDto.cs
  5. 10
      src/Shentun.Peis.Application.Contracts/PhoneFollowUps/GetPatientRegisterCriticalListInputDto.cs
  6. 107
      src/Shentun.Peis.Application/AIMessages/AIMessageAppService.cs
  7. 2
      src/Shentun.Peis.Application/PeisApplicationModule.cs
  8. 7
      src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs
  9. 71
      src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs
  10. 19
      src/Shentun.Peis.Domain.Shared/Enums/AITypeFlag.cs
  11. 3
      src/Shentun.Peis.Domain.Shared/Enums/ThirdInterfaceTypeFlag.cs

71
src/Shentun.Peis.Application.Contracts/AIMessages/DeepSeekResponse.cs

@ -0,0 +1,71 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.AIMessages
{
public class DeepSeekResponse
{
// 唯一请求标识符
[JsonProperty("id")]
public string Id { get; set; }
// 响应创建时间戳(Unix时间)
[JsonProperty("created")]
public long Created { get; set; }
// 使用的模型名称(如deepseek-chat)
[JsonProperty("model")]
public string Model { get; set; }
// 包含对话结果的集合
[JsonProperty("choices")]
public List<Choice> Choices { get; set; }
// Token使用统计(可选字段)
[JsonProperty("usage")]
public UsageInfo Usage { get; set; }
}
public class Choice
{
// 结果序号(多结果时区分)
[JsonProperty("index")]
public int Index { get; set; }
// 消息内容封装
[JsonProperty("message")]
public Message Message { get; set; }
// 终止原因(如"stop"表示正常结束)
[JsonProperty("finish_reason")]
public string FinishReason { get; set; }
}
public class Message
{
// 角色标识(user/assistant)
[JsonProperty("role")]
public string Role { get; set; }
// AI返回的文本内容
[JsonProperty("content")]
public string Content { get; set; }
}
public class UsageInfo
{
// 输入消耗的Token数
[JsonProperty("prompt_tokens")]
public int PromptTokens { get; set; }
// 输出消耗的Token数
[JsonProperty("completion_tokens")]
public int CompletionTokens { get; set; }
// 总Token消耗
[JsonProperty("total_tokens")]
public int TotalTokens { get; set; }
}
}

11
src/Shentun.Peis.Application.Contracts/AIMessages/GetAIMessageResultDto.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.AIMessages
{
public class GetAIMessageResultDto
{
public string Result { get; set; }
}
}

11
src/Shentun.Peis.Application.Contracts/AIMessages/GetAIMessageResultInputDto.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shentun.Peis.AIMessages
{
public class GetAIMessageResultInputDto
{
public string Message { get; set; }
}
}

5
src/Shentun.Peis.Application.Contracts/PeisReports/GetPatientRegisterReportRequestDto.cs

@ -73,6 +73,11 @@ namespace Shentun.Peis.PeisReports
/// </summary>
public string? IdNo { get; set; }
/// <summary>
/// 体检结论id集合 空集合查询所有
/// </summary>
public List<Guid> MedicalConclusionIds { get; set; } = new List<Guid>();
}
public class GetPeisReportDetailRequest_CustomerOrg

10
src/Shentun.Peis.Application.Contracts/PhoneFollowUps/GetPatientRegisterCriticalListInputDto.cs

@ -85,6 +85,16 @@ namespace Shentun.Peis.PhoneFollowUps
/// </summary>
public char? IsPhoneComplete { get; set; }
/// <summary>
/// 开始日期 随访日期检索
/// </summary>
public string? PhoneFollowUpStartDate { get; set; }
/// <summary>
/// 结束日期 随访日期检索
/// </summary>
public string? PhoneFollowUpEndDate { get; set; }
/// <summary>
/// 诊断级别ID 集合 可以查多个
/// </summary>

107
src/Shentun.Peis.Application/AIMessages/AIMessageAppService.cs

@ -0,0 +1,107 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Shentun.Peis.Enums;
using Shentun.Peis.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
namespace Shentun.Peis.AIMessages
{
/// <summary>
/// AI对话
/// </summary>
[ApiExplorerSettings(GroupName = "Work")]
[Authorize]
public class AIMessageAppService : ApplicationService
{
private readonly IRepository<ThirdInterface, Guid> _thirdInterfaceRepository;
public AIMessageAppService(
IRepository<ThirdInterface, Guid> thirdInterfaceRepository
)
{
_thirdInterfaceRepository = thirdInterfaceRepository;
}
/// <summary>
/// 获取Ai回复内容
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
[HttpPost("api/app/AIMessage/GetAIMessageResult")]
public async Task<GetAIMessageResultDto> GetAIMessageResultAsync(GetAIMessageResultInputDto input)
{
var messageDto = new GetAIMessageResultDto();
if (string.IsNullOrWhiteSpace(input.Message))
{
throw new UserFriendlyException("请求内容不能为空");
}
var thirdInterface = await _thirdInterfaceRepository.FirstOrDefaultAsync(f => f.ThirdInterfaceType == ThirdInterfaceTypeFlag.WebAI);
if (thirdInterface == null)
{
throw new UserFriendlyException("未配置第三方AI接口");
}
if (thirdInterface.IsActive != 'Y')
{
throw new UserFriendlyException("该接口已禁用");
}
var parmValue = thirdInterface.ParmValue;
var configurationBuilder = new ConfigurationBuilder()
.AddJsonStream(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(parmValue)));
var config = configurationBuilder.Build();
var apiBaseAddress = config.GetSection("Interface").GetSection("BaseAddress").Value;
var apiKey = config.GetSection("Interface").GetSection("ApiKey").Value;
var aiType = config.GetSection("Interface").GetSection("AIType").Value;
var modelValue = config.GetSection("Interface").GetSection("ModelValue").Value;
if (aiType == AITypeFlag.DeepSeek)
{
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri(apiBaseAddress);
// 设置API密钥或其他认证信息(如果有的话)
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
try
{
var requestBody = new
{
model = modelValue,
messages = new[] { new { role = "user", content = input.Message } }
};
var response = await client.PostAsJsonAsync("chat/completions", requestBody);
var result = await response.Content.ReadFromJsonAsync<DeepSeekResponse>();
string data = result.Choices.First().Message.Content;
messageDto.Result = data;
}
catch (HttpRequestException e)
{
throw new UserFriendlyException($"获取异常:{e.Message}");
}
}
}
else
{
throw new UserFriendlyException("AI接口类型不正确");
}
return messageDto;
}
}
}

2
src/Shentun.Peis.Application/PeisApplicationModule.cs

@ -52,6 +52,8 @@ public class PeisApplicationModule : AbpModule
//{
// options.PlugInSources.AddFolder(@"E:\Whitedolphins\NextPeis\src\Shentun.ColumnReferencePlugIns\bin\Debug\net6.0");
//});
//AI
}

7
src/Shentun.Peis.Application/PeisReports/PeisReportAppService.cs

@ -116,7 +116,8 @@ namespace Shentun.Peis.PeisReports
a.CreatorId,
a.MaritalStatusId,
a.IsUploadAppoint,
a.SummaryDoctorId
a.SummaryDoctorId,
a.MedicalConclusionId
},
//RegisterCheckCompleteFlag = registerCheck.CompleteFlag,
//IsCheck = asbitem.IsCheck,
@ -290,6 +291,10 @@ namespace Shentun.Peis.PeisReports
}
if (input.MedicalConclusionIds.Any())
{
sumquery = sumquery.Where(m => m.a.MedicalConclusionId != null && input.MedicalConclusionIds.Contains(m.a.MedicalConclusionId.Value));
}
int totalCount = sumquery.Count();

71
src/Shentun.Peis.Application/PhoneFollowUps/PhoneFollowUpAppService.cs

@ -41,7 +41,7 @@ namespace Shentun.Peis.PhoneFollowUps
private readonly IRepository<Patient, Guid> _patientRepository;
private readonly CustomerOrgManager _customerOrgManager;
private readonly IRepository<RegisterCheckSummary, Guid> _registerCheckSummaryRepository;
private readonly IRepository<SmsSend,Guid> _smsSendRepository;
private readonly IRepository<SmsSend, Guid> _smsSendRepository;
public PhoneFollowUpAppService(
@ -513,6 +513,14 @@ namespace Shentun.Peis.PhoneFollowUps
query = query.Where(m => input.DiagnosisLevelIds.Contains(m.registerCheck.DiagnosisLevelId) || input.DiagnosisLevelIds.Contains(m.registerCheckItem.DiagnosisLevelId));
}
if (!string.IsNullOrWhiteSpace(input.PhoneFollowUpStartDate) && !string.IsNullOrWhiteSpace(input.PhoneFollowUpEndDate))
{
query = query.Where(m => m.phoneFollowUpEmpty != null
&& m.phoneFollowUpEmpty.PlanFollowDate >= Convert.ToDateTime(input.PhoneFollowUpStartDate)
&& m.phoneFollowUpEmpty.PlanFollowDate < Convert.ToDateTime(input.PhoneFollowUpEndDate).AddDays(1));
}
#endregion
@ -561,46 +569,49 @@ namespace Shentun.Peis.PhoneFollowUps
};
var phoneFollowUpWithPatientRegisterDetail = itemGroup.Where(m => m.phoneFollowUpEmpty != null).Select(s => new PhoneFollowUpWithPatientRegisterDto
var phoneFollowUpWithPatientRegisterDetail = itemGroup.Where(m => m.phoneFollowUpEmpty != null).GroupBy(g => g.phoneFollowUpEmpty).Select(s => new PhoneFollowUpWithPatientRegisterDto
{
FollowUpId = s.phoneFollowUpEmpty.FollowUpId,
CreationTime = s.phoneFollowUpEmpty.CreationTime,
ReplyContent = s.phoneFollowUpEmpty.ReplyContent,
PlanFollowDate = DataHelper.ConversionDateToString(s.phoneFollowUpEmpty.PlanFollowDate),
CreatorId = s.phoneFollowUpEmpty.CreatorId,
FollowUpContent = s.phoneFollowUpEmpty.FollowUpContent,
Id = s.phoneFollowUpEmpty.Id,
IsComplete = s.phoneFollowUpEmpty.IsComplete,
LastModificationTime = s.phoneFollowUpEmpty.LastModificationTime,
LastModifierId = s.phoneFollowUpEmpty.LastModifierId,
CreatorName = _cacheService.GetSurnameAsync(s.phoneFollowUpEmpty.CreatorId).GetAwaiter().GetResult(),
LastModifierName = _cacheService.GetSurnameAsync(s.phoneFollowUpEmpty.LastModifierId).GetAwaiter().GetResult(),
FollowUpId = s.Key.FollowUpId,
CreationTime = s.Key.CreationTime,
ReplyContent = s.Key.ReplyContent,
PlanFollowDate = DataHelper.ConversionDateToString(s.Key.PlanFollowDate),
CreatorId = s.Key.CreatorId,
FollowUpContent = s.Key.FollowUpContent,
Id = s.Key.Id,
IsComplete = s.Key.IsComplete,
LastModificationTime = s.Key.LastModificationTime,
LastModifierId = s.Key.LastModifierId,
CreatorName = _cacheService.GetSurnameAsync(s.Key.CreatorId).GetAwaiter().GetResult(),
LastModifierName = _cacheService.GetSurnameAsync(s.Key.LastModifierId).GetAwaiter().GetResult(),
PatientName = firstItem.patientRegister.PatientName
}).ToList();
var smsSendDetail = itemGroup.Where(m => m.smsSendEmpty != null).Select(s => new SmsSendDto
var smsSendDetail = itemGroup.Where(m => m.smsSendEmpty != null).GroupBy(g => g.smsSendEmpty).Select(s => new SmsSendDto
{
FollowUpId = s.smsSendEmpty.FollowUpId,
CreationTime = s.smsSendEmpty.CreationTime,
CreatorId = s.smsSendEmpty.CreatorId,
Id = s.smsSendEmpty.Id,
IsComplete = s.smsSendEmpty.IsComplete,
LastModificationTime = s.smsSendEmpty.LastModificationTime,
LastModifierId = s.smsSendEmpty.LastModifierId,
CreatorName = _cacheService.GetSurnameAsync(s.smsSendEmpty.CreatorId).GetAwaiter().GetResult(),
LastModifierName = _cacheService.GetSurnameAsync(s.smsSendEmpty.LastModifierId).GetAwaiter().GetResult(),
PatientName = s.smsSendEmpty.PatientName,
Content = s.smsSendEmpty.Content,
MobileTelephone = s.smsSendEmpty.MobileTelephone,
PlanSendDate = DataHelper.ConversionDateToString(s.smsSendEmpty.PlanSendDate),
PatientId = s.smsSendEmpty.PatientId,
SmsTypeId = s.smsSendEmpty.SmsTypeId
FollowUpId = s.Key.FollowUpId,
CreationTime = s.Key.CreationTime,
CreatorId = s.Key.CreatorId,
Id = s.Key.Id,
IsComplete = s.Key.IsComplete,
LastModificationTime = s.Key.LastModificationTime,
LastModifierId = s.Key.LastModifierId,
CreatorName = _cacheService.GetSurnameAsync(s.Key.CreatorId).GetAwaiter().GetResult(),
LastModifierName = _cacheService.GetSurnameAsync(s.Key.LastModifierId).GetAwaiter().GetResult(),
PatientName = s.Key.PatientName,
Content = s.Key.Content,
MobileTelephone = s.Key.MobileTelephone,
PlanSendDate = DataHelper.ConversionDateToString(s.Key.PlanSendDate),
PatientId = s.Key.PatientId,
SmsTypeId = s.Key.SmsTypeId
}).ToList();
temoDto.PhoneFollowUpWithPatientRegisterDetail = phoneFollowUpWithPatientRegisterDetail;
temoDto.SmsSendDetail = smsSendDetail;
entListDto.Add(temoDto);
}

19
src/Shentun.Peis.Domain.Shared/Enums/AITypeFlag.cs

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace Shentun.Peis.Enums
{
public static class AITypeFlag
{
/// <summary>
/// DeepSeek
/// </summary>
[Description("DeepSeek")]
public const string DeepSeek = "01";
}
}

3
src/Shentun.Peis.Domain.Shared/Enums/ThirdInterfaceTypeFlag.cs

@ -44,5 +44,8 @@ namespace Shentun.Peis.Enums
[Description("第三方预约对接")]
public const string ThirdBooking = "12";
[Description("AI对接")]
public const string WebAI = "13";
}
}
Loading…
Cancel
Save