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
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							112 lines
						
					
					
						
							4.1 KiB
						
					
					
				
								using Dapper;
							 | 
						|
								using Npgsql;
							 | 
						|
								using System;
							 | 
						|
								using System.Collections.Generic;
							 | 
						|
								using System.Data.Common;
							 | 
						|
								using System.Linq;
							 | 
						|
								using System.Text;
							 | 
						|
								using System.Threading.Tasks;
							 | 
						|
								
							 | 
						|
								namespace Shentun.Peis.PlugIns
							 | 
						|
								{
							 | 
						|
								    public class ImportPacsResultPlugInsBase : ThirdPlugInsBase
							 | 
						|
								    {
							 | 
						|
								        public ImportPacsResultPlugInsBase(string parmValue) : base(parmValue)
							 | 
						|
								        {
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        public virtual async Task<ImportPacsResultPlugInsOut> ImportResultAsync(ImportPacsResultPlugInsInput input)
							 | 
						|
								        {
							 | 
						|
								            var result = new ImportPacsResultPlugInsOut();
							 | 
						|
								            return result;
							 | 
						|
								        }
							 | 
						|
								        public async Task<List<PacsRequestForImportResultPlugIns>> GetPacsRequestForImportResultPlugInssAsync(Guid patientRegisterId)
							 | 
						|
								        {
							 | 
						|
								            using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
							 | 
						|
								            {
							 | 
						|
								                string sql;
							 | 
						|
								                sql = @"
							 | 
						|
								   SELECT distinct patient_register.patient_register_no,
							 | 
						|
								         patient_register.patient_name,
							 | 
						|
								         register_check.id ,
							 | 
						|
								        register_check.check_request_no
							 | 
						|
								from patient_register
							 | 
						|
								JOIN register_check on patient_register.id = register_check.patient_register_id
							 | 
						|
								JOIN register_check_asbitem on register_check.id = register_check_asbitem.register_check_id
							 | 
						|
								JOIN asbitem on register_check_asbitem.asbitem_id = asbitem.id 
							 | 
						|
								JOIN item_type on asbitem.item_type_id = item_type.id 
							 | 
						|
								where patient_register.id = @PatientRegisterId and 
							 | 
						|
								      item_type.is_check_request = 'Y' and
							 | 
						|
								      (patient_register.complete_flag = '0' or 
							 | 
						|
								          patient_register.complete_flag = '1' or 
							 | 
						|
								          patient_register.complete_flag = '2')
							 | 
						|
								                      ";
							 | 
						|
								                var pacsRequestForResultImportPlugInss = (await conn.QueryAsync<PacsRequestForImportResultPlugIns>(sql,
							 | 
						|
								                    new { PatientRegisterId = patientRegisterId })).ToList();
							 | 
						|
								                return pacsRequestForResultImportPlugInss;
							 | 
						|
								            }
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								
							 | 
						|
								        public async Task<List<PatientRegisterForLisRequest>> GetRequestPatientRegisters(int days)
							 | 
						|
								        {
							 | 
						|
								            using (DbConnection conn = new NpgsqlConnection(AppConnctionStr))
							 | 
						|
								            {
							 | 
						|
								                string sql;
							 | 
						|
								                var startDate = DateTime.Now.Date.AddDays(-days);
							 | 
						|
								                sql = @" SELECT distinct register_check.patient_register_id
							 | 
						|
								from patient_register
							 | 
						|
								JOIN register_check on patient_register.id = register_check.patient_register_id
							 | 
						|
								JOIN register_check_asbitem on register_check.id = register_check_asbitem.register_check_id
							 | 
						|
								JOIN asbitem on register_check_asbitem.asbitem_id = asbitem.id 
							 | 
						|
								JOIN item_type on asbitem.item_type_id = item_type.id 
							 | 
						|
								where 
							 | 
						|
								      item_type.is_check_request = 'Y' and 
							 | 
						|
								      (
							 | 
						|
								          patient_register.complete_flag = '1' or 
							 | 
						|
								          patient_register.complete_flag = '2') and
							 | 
						|
								      patient_register.medical_start_date >@StartDate and
							 | 
						|
								      register_check.creation_time >@StartDate
							 | 
						|
								ORDER BY register_check.patient_register_id
							 | 
						|
								                      ";
							 | 
						|
								                var patientRegisterForLisRequests = (await conn.QueryAsync<PatientRegisterForLisRequest>(sql,
							 | 
						|
								                    new { StartDate = startDate })).ToList();
							 | 
						|
								
							 | 
						|
								                return patientRegisterForLisRequests;
							 | 
						|
								            }
							 | 
						|
								
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        public override Task DoWork()
							 | 
						|
								        {
							 | 
						|
								            var loginResult = LoginAsync().Result;
							 | 
						|
								            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 = GetRequestPatientRegisters(days).Result;
							 | 
						|
								
							 | 
						|
								            foreach (var patientRegister in patientRegisters)
							 | 
						|
								            {
							 | 
						|
								                try
							 | 
						|
								                {
							 | 
						|
								                    var result = ImportResultAsync(new ImportPacsResultPlugInsInput()
							 | 
						|
								                    {
							 | 
						|
								                        PatientRegisterId = patientRegister.PatientRegisterId,
							 | 
						|
								                    }).Result;
							 | 
						|
								                }
							 | 
						|
								                catch (Exception ex)
							 | 
						|
								                {
							 | 
						|
								
							 | 
						|
								                }
							 | 
						|
								
							 | 
						|
								            }
							 | 
						|
								            return Task.CompletedTask;
							 | 
						|
								        }
							 | 
						|
								    }
							 | 
						|
								}
							 |