-- 需要下载的图文件路径
								
SELECT A.PatientCode, A.ExamFeeitem_Code,A.IMAGETITLE,A.ImageFile,
       STUFF((SELECT ',' + B.SopInstanceUID
              FROM PACS.DICOMSERVER.DBO.ImgForReport B
              WHERE B.AccessionNumber=A.AccessionNumber
              FOR XML PATH('')), 1, 1, '') AS SopInstanceUID
FROM PACS.DICOMSERVER.DBO.PEIS_PacsResult A
where  A.ExamDatetime IS NOT NULL AND A.PatientCode='54521'
 
 
 -- 
 
 SELECT * FROM Report WHERE EID=54521
 
 SELECT * FROM  pacs.DICOMSERVER.dbo.PEIS_PacsResult WHERE  PatientCode='54521'
 
 -- 同步报告单
 
 INSERT INTO Report 
 ( EID, ReportNo, ReportTime, Reporter, Examer, Description, Summary, Positive, Title, Class, ReportImage, InTime,AccessionNumber )
                SELECT
		                A.PatientCode AS EID,
		                A.ExamFeeitem_Code AS ReportNo,
		                A.ExamDatetime AS ReportTime,
		                A.ExamDoctor AS Reporter,
		                A.InputDoctor AS Examer,
		                A.ExamDesc AS Description,
		                A.ExamSummary AS Summary,
		                A.ExamPositive AS Positive,
		                A.ImageTitle AS Title,
		                A.TransfTertarget AS Class,
		                A.ReportFile_PDF AS ReportImage,
		                GETDATE() AS InTime,
										AccessionNumber
                FROM	pacs.DICOMSERVER.dbo.PEIS_PacsResult A
                WHERE A.ExamDatetime IS NOT NULL and a.PatientCode='54521' AND NOT EXISTS (
                    SELECT 1 FROM Report AS B
											WHERE B.EID = A.PatientCode AND B.ReportNo=A.ExamFeeitem_Code
                ) and exists ( SELECT 1  FROM Enrollment_Patient WHERE ID = A.PatientCode)
								
								
								
								
								
								
--

SELECT * FROM	pacs.DICOMSERVER.dbo.PEIS_PacsResult A
WHERE A.ExamDatetime IS NOT NULL and a.PatientCode in
(
'70996'
,'70995'
,'71013'
,'71015'
,'71009'
,'70996'
,'54515'
,'54521'
,'71008'
)


SELECT TOP 2 * FROM	pacs.DICOMSERVER.dbo.PEIS_PacsResult  WHERE ReportFile_PDF IS NOT NULL AND ExamDatetime>'2024-06-1'