USE [peisdb]
GO

/****** Object:  StoredProcedure [dbo].[sp_GetPacsResult]    Script Date: 06/04/2024 09:51:02 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

 create PROCEDURE [dbo].[sp_GetPacsResult] 	@EID BIGINT ,@DeptCode varchar(20)
AS
BEGIN 
	 SELECT
	            e.ID,	e.PID,	A.FID,	c.ID AS RID,	e.SID,
	            A.FeeItemName,	c.RptItemCode,	FF.ImageTitle AS RptItemName,	c.ValueFormat,	c.SignFormat,
	            FF.ExamDesc AS TextResult,	 FF.ExamDoctor AS Reporter,	FF.ExamDatetime AS ReportTime,	InputDoctor  AS Checker,
	            c.Seq AS SeqReport, A.ItemClass, COALESCE ( A.GiveUpTime, d.GiveUpTime ) AS GiveUpTime
            FROM
	            Enrollment_FeeItem A
                        LEFT JOIN Dict_FeeItem  FeeItem ON A.FID= FeeItem.ID
	            LEFT JOIN Enrollment_CheckCost  COST ON A.OrderNo=COST.ID 
	            LEFT JOIN Dict_ReportItem c ON c.FID = A.FID
	            LEFT JOIN Exam_Part d ON A.EID = d.EID 	AND A.DeptCode = d.DeptCode
	            LEFT JOIN Exam_Result e ON e.PID = d.ID 	AND e.RID = c.ID
	            LEFT JOIN PACS .DICOMSERVER .DBO .PEIS_PacsResult  FF ON  FF.PatientCode = CONVERT(VARCHAR(20),A.EID) and (A.ID = FF.ExamFeeitem_Code OR A.OldId= FF.ExamFeeitem_Code)
            WHERE
              A.GiveUpTime IS NULL AND COST.SendTime IS NOT NULL AND COST.DeleteTime IS NULL AND  A.ItemClass = '检查' AND FeeItem.IsHide=0  AND 
	            A.EID =@EID AND A.DeptCode = @DeptCode
	            ORDER BY ReportTime DESC
END
GO


