public async Task <IActionResult> GetPrescriptionRecordPageListAsync([FromQuery] GetPrescriptionRecordPageListRequestDto requestDto)
        {
            var result = await new PrescriptionInformationBiz().GetPrescriptionRecordPageListAsync(requestDto);
            var unpaidPrescriptions = await new PrescriptionBiz().GetUnpaidPrescriptionsByInformationIdsAsync(result.CurrentPage.Select(a => a.InformationGuid).Distinct().ToList());

            foreach (var item in result.CurrentPage)
            {
                item.ObligationAmount = unpaidPrescriptions.Where(a => a.InformationGuid == item.InformationGuid).Sum(a => a.TotalCost);
            }
            return(Success(result));
        }
Пример #2
0
        /// <summary>
        /// 获取处方记录分页列表
        /// </summary>
        /// <param name="requestDto"></param>
        /// <returns></returns>
        public async Task <GetPrescriptionRecordPageListResponseDto> GetPrescriptionRecordPageListAsync(GetPrescriptionRecordPageListRequestDto requestDto)
        {
            if (requestDto.IsExport)
            {
                requestDto.PageSize = int.MaxValue;
            }
            requestDto.StartDate = requestDto.StartDate.Date;
            requestDto.EndDate   = requestDto.EndDate.Date.AddDays(1).AddSeconds(-1);
            var sqlWhere = string.Empty;

            if (!string.IsNullOrWhiteSpace(requestDto.HospitalGuid))
            {
                sqlWhere = $"{sqlWhere} and a.hospital_guid=@HospitalGuid";
            }
            if (!string.IsNullOrWhiteSpace(requestDto.OfficeGuid))
            {
                sqlWhere = $"{sqlWhere} and a.office_guid=@OfficeGuid";
            }
            if (!string.IsNullOrWhiteSpace(requestDto.DoctorGuid))
            {
                sqlWhere = $"{sqlWhere} and a.doctor_guid=@DoctorGuid";
            }
            if (!string.IsNullOrWhiteSpace(requestDto.UserGuid))
            {
                sqlWhere = $"{sqlWhere} and da.user_guid=@UserGuid";
            }
            if (requestDto.PaidStatus != null)
            {
                sqlWhere = $"{sqlWhere} and a.paid_status=@PaidStatus";
            }
            if (requestDto.ReceptionType != null)
            {
                sqlWhere = $"{sqlWhere} and a.reception_type=@ReceptionType";
            }
            if (!string.IsNullOrWhiteSpace(requestDto.Keyword))
            {
                sqlWhere = $@"{sqlWhere} AND (
							a.patient_name LIKE CONCAT(@Keyword,'%') 
							OR a.patient_phone = @Keyword
							OR a.clinical_diagnosis LIKE CONCAT(@Keyword,'%') 
							OR d.item_name LIKE CONCAT(@Keyword,'%') 
							OR c.prescription_no = @Keyword 
                            OR u.user_name LIKE CONCAT(@Keyword,'%') 
						) "                        ;
            }
            var sql    = $@"SELECT
							a.information_guid,
                            CASE
		                        a.paid_status 
		                        WHEN 'NotPaid' THEN
		                        '未收款' 
		                        WHEN 'PartiallyUnpaid' THEN
		                        '部分未收款' 
		                        WHEN 'Paided' THEN
		                        '已收款' 
                                ELSE '无有效处方' 
	                        END as `status`,
                            da.appointment_guid,
							da.patient_relationship,
							a.patient_name,
							a.patient_gender,
							a.patient_phone,
							b.office_name,
							a.clinical_diagnosis,
							a.reception_type,
							a.creation_date AS reception_time,
							a.total_cost,
							u.user_name as doctor_name,
							GROUP_CONCAT( distinct c.prescription_no SEPARATOR '/' ) AS prescription_nos
						FROM
							t_doctor_prescription_information a
							LEFT JOIN t_doctor_office b ON a.office_guid = b.office_guid
							LEFT JOIN t_doctor_prescription c ON a.information_guid = c.information_guid 
							AND c.`status` <> 'Cancellation' 
							AND c.`enable` = 1 
							left join t_doctor_prescription_recipe d on d.prescription_guid=c.prescription_guid
							left join t_consumer_doctor_appointment da on da.appointment_guid=a.appointment_guid
							left join t_utility_user u on u.user_guid=a.doctor_guid
						WHERE
							a.`enable` = 1 {sqlWhere}
							and a.creation_date BETWEEN @StartDate and @EndDate
						GROUP BY
							a.information_guid,
                            a.paid_status,
                            da.appointment_guid,
							da.patient_relationship,
							a.patient_name,
							a.patient_gender,
							a.patient_phone,
							b.office_name,
							a.clinical_diagnosis,
							a.reception_type,
							a.creation_date,
							a.total_cost,
							u.user_name
						ORDER BY a.creation_date desc "                        ;
            var result = await MySqlHelper.QueryByPageAsync <GetPrescriptionRecordPageListRequestDto, GetPrescriptionRecordPageListResponseDto, GetPrescriptionRecordPageListItemDto>(sql, requestDto);


            return(result);
        }