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.
329 lines
16 KiB
329 lines
16 KiB
using Dapper;
|
|
using Npgsql;
|
|
using ServiceReferenceDianLisReport;
|
|
using ServiceReferenceDianLisResult;
|
|
using ServiceReferenceHzcyHis;
|
|
using Shentun.Peis.ImportLisResults;
|
|
using Shentun.Peis.PlugIns.ChargeRequests;
|
|
using Shentun.Peis.PlugIns.Extensions.ChargeRequests.Hzcy;
|
|
using Shentun.Peis.PlugIns.ImportLisResults;
|
|
using Shentun.Peis.PlugIns.LisRequests;
|
|
using Shentun.Peis.PlugIns.PatientRegisters;
|
|
using Shentun.Peis.PrintReports;
|
|
using Shentun.Peis.RegisterCheckPictures;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.ServiceModel;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.Application.Dtos;
|
|
|
|
namespace Shentun.Peis.PlugIns.Extensions.ImportLisResults.Dian
|
|
{
|
|
public class ImportLisResultPlugInsDian : ImportLisResultPlugInsBase
|
|
{
|
|
private readonly string _clientID;
|
|
private readonly string _clientGUID;
|
|
|
|
|
|
public ImportLisResultPlugInsDian(Guid thirdInterfaceId) : base(thirdInterfaceId)
|
|
{
|
|
_clientID = InterfaceConfig.GetSection("Interface").GetSection("ClientID").Value;
|
|
_clientGUID = InterfaceConfig.GetSection("Interface").GetSection("ClientGUID").Value;
|
|
}
|
|
public ImportLisResultPlugInsDian(string parmValue) : base(parmValue)
|
|
{
|
|
_clientID = InterfaceConfig.GetSection("Interface").GetSection("ClientID").Value;
|
|
_clientGUID = InterfaceConfig.GetSection("Interface").GetSection("ClientGUID").Value;
|
|
}
|
|
public override Task<ImportLisResultPlugInsOut> ImportResultByPatientRegisterIdAsync(Guid patientRegisterId)
|
|
{
|
|
return base.ImportResultByPatientRegisterIdAsync(patientRegisterId);
|
|
}
|
|
|
|
public override async Task DoWork()
|
|
{
|
|
var queryDaysStr = InterfaceConfig.GetSection("Interface").GetSection("Scheduler").GetSection("QueryDays").Value;
|
|
if (string.IsNullOrWhiteSpace(queryDaysStr))
|
|
{
|
|
queryDaysStr = "1";
|
|
}
|
|
if (!int.TryParse(queryDaysStr, out int days))
|
|
{
|
|
days = 1;
|
|
}
|
|
var patientRegisters = GetRequestPatientRegistersDianAsync(days).Result;
|
|
|
|
foreach (var patientRegister in patientRegisters)
|
|
{
|
|
await ImportDianResultByPatientRegisterIdAsync(patientRegister.PatientRegisterId);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<ImportLisResultPlugInsOut> ImportDianResultByPatientRegisterIdAsync(Guid patientRegisterId)
|
|
{
|
|
var lisResultAddress = InterfaceConfig.GetSection("Interface").GetSection("LisResultAddress").Value;
|
|
var lisReportAddress = InterfaceConfig.GetSection("Interface").GetSection("LisReportAddress").Value;
|
|
using (var client = CreateClient(lisResultAddress))
|
|
{
|
|
// 设置超时时间
|
|
client.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(2);
|
|
|
|
var execOrganizationUnitIdStr = InterfaceConfig.GetSection("Interface").GetSection("ExecOrganizationUnitId").Value;
|
|
var defaultCheckDoctorName = InterfaceConfig.GetSection("Interface").GetSection("DefaultCheckDoctorName").Value;
|
|
var barcodeMode = InterfaceConfig.GetSection("Interface").GetSection("BarcodeMode").Value; //0-人员条码 1-检验条码
|
|
|
|
|
|
#region 导入数据
|
|
|
|
|
|
List<CommonTableOut> itemCommonTableOuts = new List<CommonTableOut>();
|
|
List<CommonTableOut> asbitemCommonTableOuts = new List<CommonTableOut>();
|
|
|
|
string sql_item = $"select data_code as dian_code,display_name as item_id from common_table " +
|
|
$" where common_table_type_id='{InterfaceConfig.GetSection("Interface").GetSection("ItemCommonTableTypeId").Value}' ";
|
|
|
|
string sql_asbitem = $"select data_code as dian_code,display_name as item_id from common_table " +
|
|
$" where common_table_type_id='{InterfaceConfig.GetSection("Interface").GetSection("AsbitemCommonTableTypeId").Value}' ";
|
|
|
|
|
|
var result = new ImportLisResultPlugInsOut();
|
|
|
|
using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
|
|
{
|
|
itemCommonTableOuts = (await conn.QueryAsync<CommonTableOut>(sql_item)).ToList();
|
|
asbitemCommonTableOuts = (await conn.QueryAsync<CommonTableOut>(sql_asbitem)).ToList();
|
|
|
|
|
|
try
|
|
{
|
|
var createImportLisResultDtos = new List<CreateImportLisResultDto>();
|
|
|
|
//设置结果,生成小结
|
|
|
|
string register_item_sql = $"select d.lis_request_no,f.item_id::TEXT as item_id,g.display_name as item_name,patient_register_no" +
|
|
" from patient_register as a " +
|
|
" left join register_check as b on a.id=b.patient_register_id " +
|
|
" left join register_check_asbitem as c on b.id=c.register_check_id " +
|
|
" left join lis_request as d on c.lis_request_id=d.id " +
|
|
" left join asbitem as e on c.asbitem_id=e.id " +
|
|
" left join register_check_item as f on b.id=f.register_check_id " +
|
|
" left join item as g on f.item_id=g.id " +
|
|
$" where a.id='{patientRegisterId}' and e.is_outsend='Y' ";
|
|
|
|
|
|
|
|
var lisResultFromInterfaces = (await conn.QueryAsync<LisResultFromImportInterface>(register_item_sql)).ToList();
|
|
|
|
string barCode = lisResultFromInterfaces.FirstOrDefault().PatientRegisterNo;
|
|
|
|
string barCodeDian = "";
|
|
|
|
//常规结果获取
|
|
var result_cg = await client.GetDetailByHospCodeAsync(_clientID, _clientGUID, barCode, 0);
|
|
var resultObj_cg = XmlHelper.DeserializeXmlAddRoot<GetDetailByHospCodeNormalOut>(result_cg.Body.GetDetailByHospCodeResult);
|
|
|
|
if (resultObj_cg.ResultsDataSet != null)
|
|
{
|
|
barCodeDian = resultObj_cg.ResultsDataSet.Tables.FirstOrDefault().Barcode;
|
|
}
|
|
|
|
//病理结果
|
|
var result_bl = await client.GetDetailByHospCodeAsync(_clientID, _clientGUID, barCode, 1);
|
|
var resultObj_bl = XmlHelper.DeserializeXmlAddRoot<GetDetailByHospCodePathologyOut>(result_cg.Body.GetDetailByHospCodeResult);
|
|
|
|
if (resultObj_bl.ResultsDataSet != null && string.IsNullOrWhiteSpace(barCodeDian))
|
|
{
|
|
barCodeDian = resultObj_bl.ResultsDataSet.Tables.FirstOrDefault().Barcode;
|
|
}
|
|
foreach (var li in lisResultFromInterfaces)
|
|
{
|
|
var dian_code = itemCommonTableOuts.FirstOrDefault(f => f.ItemId == li.ItemId);
|
|
if (dian_code != null)
|
|
{
|
|
if (resultObj_cg.ResultsDataSet != null)
|
|
{
|
|
var dianResult = resultObj_cg.ResultsDataSet.Tables.FirstOrDefault(f => f.S == dian_code.DianCode);
|
|
if (dianResult != null)
|
|
{
|
|
var createImportLisResultDto = new CreateImportLisResultDto()
|
|
{
|
|
LisRequestNo = li.LisRequestNo,
|
|
ItemId = Guid.Parse(li.ItemId),
|
|
ItemName = li.ItemName,
|
|
Result = dianResult.FinalResult,
|
|
// Unit = lisResult.Unit,
|
|
// ReferenceRangeValue = lisResult.ReferenceRangeValue,
|
|
// CriticalRangeValue = lisResult.CriticalRangeValue,
|
|
// ResultStatusId = lisResult.ResultStatusId,
|
|
// ReportPrompt = lisResult.ReportPrompt,
|
|
CheckDoctorName = defaultCheckDoctorName,
|
|
CheckDate = dianResult.ApproveDate,
|
|
ExecOrganizationUnitId = Guid.Parse(execOrganizationUnitIdStr)
|
|
};
|
|
createImportLisResultDtos.Add(createImportLisResultDto);
|
|
}
|
|
}
|
|
|
|
if (resultObj_bl.ResultsDataSet != null)
|
|
{
|
|
var dianResult = resultObj_bl.ResultsDataSet.Tables.FirstOrDefault(f => f.TestCode == dian_code.DianCode);
|
|
if (dianResult != null)
|
|
{
|
|
var createImportLisResultDto = new CreateImportLisResultDto()
|
|
{
|
|
LisRequestNo = li.LisRequestNo,
|
|
ItemId = Guid.Parse(li.ItemId),
|
|
ItemName = li.ItemName,
|
|
Result = dianResult.Repidea,
|
|
// Unit = lisResult.Unit,
|
|
// ReferenceRangeValue = lisResult.ReferenceRangeValue,
|
|
// CriticalRangeValue = lisResult.CriticalRangeValue,
|
|
// ResultStatusId = lisResult.ResultStatusId,
|
|
// ReportPrompt = lisResult.ReportPrompt,
|
|
CheckDoctorName = defaultCheckDoctorName,
|
|
CheckDate = dianResult.ReportDate,
|
|
ExecOrganizationUnitId = Guid.Parse(execOrganizationUnitIdStr)
|
|
};
|
|
createImportLisResultDtos.Add(createImportLisResultDto);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (createImportLisResultDtos.Any())
|
|
{
|
|
var callResult = await CallAppServiceAsync<List<CreateImportLisResultDto>, object>("api/app/ImportLisResult/ImportResult", createImportLisResultDtos);
|
|
}
|
|
|
|
//导入图片
|
|
using (var clientReport = CreateReportClient(lisReportAddress))
|
|
{
|
|
var result_report = await clientReport.GetReportInfoAsync(_clientID, _clientGUID, barCodeDian, "0");
|
|
var resultObj_report = XmlHelper.DeserializeXmlAddRoot<GetReportInfoOut>(result_report.Body.GetReportInfoResult);
|
|
if (resultObj_report.Msg.Code == "1" && resultObj_report.ResultsDataSetReport != null && resultObj_report.ResultsDataSetReport.Tables.Any())
|
|
{
|
|
|
|
var ImportReportInputs = new List<UploadRegisterCheckPictureManyDto>();
|
|
|
|
foreach (var itemReport in resultObj_report.ResultsDataSetReport.Tables)
|
|
{
|
|
var base64str = ToBase64(itemReport.PicReportUrl);
|
|
var asbitemIds = asbitemCommonTableOuts.Where(m => m.DianCode == itemReport.TestCode).ToList();
|
|
if (asbitemIds.Any())
|
|
{
|
|
string sql_register_check_id = "select distinct b.id as register_check_id from patient_register as a " +
|
|
" left join register_check as b on a.id=b.patient_register_id " +
|
|
" left join register_check_asbitem as c on b.id=c.register_check_id " +
|
|
$" where a.id='{patientRegisterId}' and c.asbitem_id=ANY(@asbitemIds) ";
|
|
var registerCheckIds = (await conn.QueryAsync<RegisterCheckIdInputDto>(sql_register_check_id, new
|
|
{
|
|
asbitemIds = asbitemIds.Select(s => Guid.Parse(s.ItemId)).ToArray()
|
|
})).ToList();
|
|
foreach (var registerCheckId in registerCheckIds)
|
|
{
|
|
List<UploadRegisterCheckPictureManyPictureBaseStrsDto> pictureBaseStrs = new List<UploadRegisterCheckPictureManyPictureBaseStrsDto>();
|
|
pictureBaseStrs.Add(new UploadRegisterCheckPictureManyPictureBaseStrsDto
|
|
{
|
|
PictureBaseStr = base64str,
|
|
FileName = itemReport.TestCode,
|
|
IsPrint = 'Y'
|
|
});
|
|
|
|
ImportReportInputs.Add(new UploadRegisterCheckPictureManyDto
|
|
{
|
|
PictureBaseStrs = pictureBaseStrs,
|
|
PictureFileType = '0',
|
|
RegisterCheckId = registerCheckId.RegisterCheckId
|
|
});
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (var importReportInput in ImportReportInputs)
|
|
{
|
|
var callResult = await CallAppServiceAsync<UploadRegisterCheckPictureManyDto, object>("api/app/registercheckpicture/uploadregistercheckpicturemany", importReportInput);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{ }
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
return new ImportLisResultPlugInsOut();
|
|
|
|
}
|
|
|
|
|
|
private RasClientDetailSoapClient CreateClient(string url)
|
|
{
|
|
return new RasClientDetailSoapClient(new BasicHttpBinding(),
|
|
new EndpointAddress(url));
|
|
}
|
|
|
|
private ReportServiceSoapClient CreateReportClient(string url)
|
|
{
|
|
return new ReportServiceSoapClient(new BasicHttpBinding(),
|
|
new EndpointAddress(url));
|
|
}
|
|
|
|
|
|
private string ToBase64(string filename)
|
|
{
|
|
Stream stream;
|
|
string fileBase64;
|
|
if (filename.StartsWith("http"))
|
|
{
|
|
|
|
using (var httpClient = new HttpClient())
|
|
{
|
|
var response = httpClient.GetAsync(filename).Result;
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var contentStream = response.Content.ReadAsStreamAsync().Result;
|
|
using var memoryStream = new MemoryStream();
|
|
contentStream.CopyTo(memoryStream);
|
|
var fileBytes = memoryStream.ToArray();
|
|
return Convert.ToBase64String(fileBytes);
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("转换base64时,返回错误:" + response.StatusCode);
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
using (stream = new FileStream(filename, FileMode.Open, FileAccess.Read))
|
|
{
|
|
byte[] byteData = new byte[stream.Length];
|
|
stream.Read(byteData, 0, byteData.Length);
|
|
fileBase64 = Convert.ToBase64String(byteData);
|
|
stream.Close();
|
|
}
|
|
return fileBase64;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|