-- UPDATE Enrollment_FeeItem
-- SET OldId = B.ID
-- FROM Enrollment_FeeItem A
-- LEFT JOIN PEIS.DBO.EnrollmentApplicationSheet B ON A.EID = B.EnrollmentId AND A.FeeItemName = B.NAME
-- WHERE A.EID < 80000 
-- AND A.FeeItemName IS NOT NULL 
-- AND B.NAME IS NOT NULL 
-- AND A.OLDID IS NULL;

-- SELECT * FROM pacs.DICOMSERVER.dbo.PEIS_PacsResult WHERE PatientCode='70525'


SELECT  * FROM PEIS.DBO.EnrollmentApplicationSheet WHERE EnrollmentID='71015' AND DEPARTMENTID<7
SELECT  * FROM PEISDB.DBO.Enrollment_FeeItem WHERE IsSend=0 AND OldId IS NOT NULL

SELECT TOP 10 *  
FROM Enrollment_FeeItem A
LEFT JOIN Enrollment_Patient C ON A.EID=C.ID 
LEFT JOIN PEIS.DBO.EnrollmentApplicationSheet B ON A.EID = B.EnrollmentId AND A.FeeItemName = B.NAME
WHERE A.EID < 80000
AND C.FinishTime IS NULL
AND A.FeeItemName IS NOT NULL 
AND B.NAME IS  NULL  
AND A.OLDID IS NULL
AND A.ItemClass = '检查'
AND A.DeptCode<>'0141'
AND A.CreateTime<'2024-06-16'
ORDER BY A.ID DESC

-- 胸部CT平扫=>胸部平扫 
-- UPDATE Enrollment_FeeItem
-- SET OldId = B.ID
SELECT TOP 10 A.ID,A.EID,A.FeeItemCode,A.FeeItemName,B.*  
FROM Enrollment_FeeItem A
LEFT JOIN Enrollment_Patient C ON A.EID=C.ID 
LEFT JOIN PEIS.DBO.EnrollmentApplicationSheet B ON A.EID = B.EnrollmentId 
WHERE 
A.OLDID IS NULL
AND A.IsSend=0
AND C.FinishTime IS NULL 
AND B.NAME='胸部CT平扫'
AND A.FeeItemName = '胸部平扫 ' 
AND A.CreateTime<'2024-06-16'
ORDER BY A.ID DESC