SELECT CS.CLAIMS_ID, CE.LONG_NAME CORPORATENAME, CS.PATIENT_NAME, CS.EMPLOYEE_NAME,CS.DEPARTMENT,E.SUBSIDIARY ,E.BRANCH, CS.ADMISSION_DATE, CS.DISCHARGEABLE_DATE , CS.PROVIDER_NAME, CS.PANEL_PROVIDER, TRIM(DS.ICD_CODE)||', '||DS.DESCRIPTION DIAGNOSISNAME, CS.MC_TAKEN_DAY ,CR.DESCRIPTION COVERAGE_DESCRIPTION, SD2.FDESC CLAIMTYPE,CS.REMARKS, CS.DUE_TOTAL, CS.PAID_TO_CLAIMANT, CS.PAID_BY_CLAIMANT, CS.AUTHORIZATION_CODE, CS.SERVICE_DATE,CS.RECORD_NO,CS.SUB_RECORD_NO,CS.PLAN_ID,CS.TRANSMISSION_DATE,CS.CLAIMS_REC_DATE, CS.CLAIMS_STATUS ,CS.APPROVED_BY, CS.HOSP_INVOICE_NO, CS.TERMINAL_ID, CS.TERMINAL_TYPE, CS.DEDUCTIBLE,CS.POLICY_NO,CS.PAYEE_NAME,CS.CARD_NO, CS.DOCRCV_BY, CS.CENTRE_CODE ,CS.DOCUMENT_NO,CS.MRN , NVL((SELECT UPLDT FROM (SELECT UPLDT FROM SYT_ATTACHDOC LD WHERE TO_NUMBER(TRIM(LD.KEY1))=CS.CLAIMS_ID AND LD.MATERIAL_TYPE IN('申诉材料','补充材料','调查材料') AND ROWNUM<2 ORDER BY UPLDT DESC) WHERE ROWNUM<2),CS.SERVICE_DATE) AS LAST_DOCUMENT_RECEIVED_DATE FROM CLAIMS CS, CORPORATE CE, COVERAGE_MASTER CR, SYC_REFCD SD1, SYC_REFCD SD2, DIAGNOSIS DS , EMPLOYEE E WHERE CS.COVERAGE_ID = CR.COVERAGE_CODE AND CS.CORPORATE_CODE = CE.CORP_CODE AND CS.PRIMARY_DIAGNOSIS = DS.ICD_CODE AND CS.CLAIM_TYPE = SD1.REFCD AND CS.CARD_NO = E.CARD_NO AND SD1.VAR1 = SD2.REFCD AND SD1.MODID = 'ES' AND SD1.REFGRP = 'CLAIMTYP' AND SD2.MODID = 'ES' AND SD2.REFGRP = 'CLAIM_APPLICABLE' AND CS.PLAN_ID!='TEST-2023-GLOBAL-PLAN-DEMO' AND (CS.PAYOR_CODE,CS.CENTRE_CODE) IN (SELECT SYFIELD(STNCD,'*',1,1), SYFIELD(STNCD,'*',2,1) FROM SYM_USRSTN WHERE USRID='SYSTEM' AND STNTYP IN ('PC')) AND (CS.CORPORATE_CODE IN (SELECT STNCD FROM SYM_USRSTN WHERE USRID='SYSTEM' AND STNTYP IN ('PY','CO')) OR (CS.PAYOR_CODE,CS.CENTRE_CODE) IN (SELECT SYFIELD(STNCD,'*',1,1), SYFIELD(STNCD,'*',2,1) FROM SYM_USRSTN WHERE USRID='SYSTEM' AND STNTYP IN ('PC'))) AND CS.CLAIMS_REC_DATE>=TO_DATE('1999-01-01','yyyy-MM-dd') AND CS.CLAIMS_REC_DATE<TO_DATE('2099-01-01','yyyy-MM-dd')+1