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.

112 lines
4.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
  1. using Dapper;
  2. using Npgsql;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data.Common;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace Shentun.Peis.PlugIns
  10. {
  11. public class ImportPacsResultPlugInsBase : ThirdPlugInsBase
  12. {
  13. public ImportPacsResultPlugInsBase(string parmValue) : base(parmValue)
  14. {
  15. }
  16. public virtual async Task<ImportPacsResultPlugInsOut> ImportResultAsync(ImportPacsResultPlugInsInput input)
  17. {
  18. var result = new ImportPacsResultPlugInsOut();
  19. return result;
  20. }
  21. public async Task<List<PacsRequestForImportResultPlugIns>> GetPacsRequestForImportResultPlugInssAsync(Guid patientRegisterId)
  22. {
  23. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  24. {
  25. string sql;
  26. sql = @"
  27. SELECT distinct patient_register.patient_register_no,
  28. patient_register.patient_name,
  29. register_check.id ,
  30. register_check.check_request_no
  31. from patient_register
  32. JOIN register_check on patient_register.id = register_check.patient_register_id
  33. JOIN register_check_asbitem on register_check.id = register_check_asbitem.register_check_id
  34. JOIN asbitem on register_check_asbitem.asbitem_id = asbitem.id
  35. JOIN item_type on asbitem.item_type_id = item_type.id
  36. where patient_register.id = @PatientRegisterId and
  37. item_type.is_check_request = 'Y' and
  38. (patient_register.complete_flag = '0' or
  39. patient_register.complete_flag = '1' or
  40. patient_register.complete_flag = '2')
  41. ";
  42. var pacsRequestForResultImportPlugInss = (await conn.QueryAsync<PacsRequestForImportResultPlugIns>(sql,
  43. new { PatientRegisterId = patientRegisterId })).ToList();
  44. return pacsRequestForResultImportPlugInss;
  45. }
  46. }
  47. public async Task<List<PatientRegisterForLisRequest>> GetRequestPatientRegisters(int days)
  48. {
  49. using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
  50. {
  51. string sql;
  52. var startDate = DateTime.Now.Date.AddDays(-days);
  53. sql = @" SELECT distinct register_check.patient_register_id
  54. from patient_register
  55. JOIN register_check on patient_register.id = register_check.patient_register_id
  56. JOIN register_check_asbitem on register_check.id = register_check_asbitem.register_check_id
  57. JOIN asbitem on register_check_asbitem.asbitem_id = asbitem.id
  58. JOIN item_type on asbitem.item_type_id = item_type.id
  59. where
  60. item_type.is_check_request = 'Y' and
  61. (
  62. patient_register.complete_flag = '1' or
  63. patient_register.complete_flag = '2') and
  64. patient_register.medical_start_date >@StartDate and
  65. register_check.creation_time >@StartDate
  66. ORDER BY register_check.patient_register_id
  67. ";
  68. var patientRegisterForLisRequests = (await conn.QueryAsync<PatientRegisterForLisRequest>(sql,
  69. new { StartDate = startDate })).ToList();
  70. return patientRegisterForLisRequests;
  71. }
  72. }
  73. public override Task DoWork()
  74. {
  75. var loginResult = LoginAsync().Result;
  76. var queryDaysStr = InterfaceConfig.GetSection("Interface").GetSection("Scheduler").GetSection("QueryDays").Value;
  77. if (string.IsNullOrWhiteSpace(queryDaysStr))
  78. {
  79. queryDaysStr = "1";
  80. }
  81. if (!int.TryParse(queryDaysStr, out int days))
  82. {
  83. days = 1;
  84. }
  85. var patientRegisters = GetRequestPatientRegisters(days).Result;
  86. foreach (var patientRegister in patientRegisters)
  87. {
  88. try
  89. {
  90. var result = ImportResultAsync(new ImportPacsResultPlugInsInput()
  91. {
  92. PatientRegisterId = patientRegister.PatientRegisterId,
  93. }).Result;
  94. }
  95. catch (Exception ex)
  96. {
  97. }
  98. }
  99. return Task.CompletedTask;
  100. }
  101. }
  102. }