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
17 KiB

using Dapper;
using Npgsql;
using ServiceReferenceAiDiKangLisResult;
using ServiceReferenceDianLisReport;
using ServiceReferenceDianLisResult;
using Shentun.Peis.ImportLisResults;
using Shentun.Peis.PlugIns.Extensions.ImportLisResults.Dian;
using Shentun.Peis.PlugIns.ImportLisResults;
using Shentun.Peis.PrintReports;
using Shentun.Peis.RegisterCheckPictures;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
namespace Shentun.Peis.PlugIns.Extensions.ImportLisResults.AiDiKang
{
public class ImportLisResultPlugInsAiDiKang : ImportLisResultPlugInsBase
{
private readonly string _userName;
private readonly string _passWord;
public ImportLisResultPlugInsAiDiKang(Guid thirdInterfaceId) : base(thirdInterfaceId)
{
_userName = InterfaceConfig.GetSection("Interface").GetSection("UserName").Value;
_passWord = InterfaceConfig.GetSection("Interface").GetSection("PassWord").Value;
}
public ImportLisResultPlugInsAiDiKang(string parmValue) : base(parmValue)
{
_userName = InterfaceConfig.GetSection("Interface").GetSection("UserName").Value;
_passWord = InterfaceConfig.GetSection("Interface").GetSection("PassWord").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 ImportOueSendResultByPatientRegisterIdAsync(patientRegister.PatientRegisterId);
}
}
public async Task<ImportLisResultPlugInsOut> ImportOueSendResultByPatientRegisterIdAsync(Guid patientRegisterId)
{
var lisResultAddress = InterfaceConfig.GetSection("Interface").GetSection("LisResultAddress").Value;
using (var client = CreateClient(lisResultAddress))
{
// 设置超时时间
client.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(2);
var aiDiKangKeyValue = await client.LoginAsync(_userName, _passWord);
if (aiDiKangKeyValue == "失败")
{
return new ImportLisResultPlugInsOut();
}
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' and b.is_audit='N' ";
var lisResultFromInterfaces = (await conn.QueryAsync<LisResultFromImportInterface>(register_item_sql)).ToList();
string barCode = lisResultFromInterfaces.FirstOrDefault().PatientRegisterNo;
var isCheck = await client.ExistsByYYtmAsync(barCode, aiDiKangKeyValue);
if (isCheck == "True")
{
//检查完
var sdsd = await client.GetJSONReportItemListByCustomerBarocdeAsync(barCode, aiDiKangKeyValue);
var sdsd2 = await client.GetReportItemListByCustomerBarocdeAsync(aiDiKangKeyValue, barCode, "常规报告");
}
////病理结果
//var result_bl = await client.GetDetailByHospCodeAsync(_clientID, _clientGUID, barCode, 1);
//var resultObj_bl = XmlHelper.DeserializeXmlAddRoot<GetDetailByHospCodePathologyOut>(result_bl.Body.GetDetailByHospCodeResult);
//if (resultObj_bl.ResultsDataSet != null && resultObj_bl.ResultsDataSet.Tables.Count > 0 && 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,
// CheckDate = dianResult.CollectDate,
// 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,
// CheckDate = dianResult.CollectDate,
// 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 AdiconWebServiceSoapClient CreateClient(string url)
{
return new AdiconWebServiceSoapClient(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;
// }
//}
}
}