       PATIENT_ID
     , COUNT(PATIENT_ID)     AS ENCOUNTER_CNT
     , MIN(ADMISSION_DATE)   AS FIRST_ENCOUNTER_DATE 
-    , MAX(DISCHARGE_DATE)   AS LAST_ENCOUNTER_DATE 
+    , MAX(ADMISSION_DATE)   AS LAST_ENCOUNTER_DATE 
   FROM 
     BP_ADMISSION_DISCHARGE
   GROUP BY 


-- **********************************************
COMMIT;
-- **********************************************
BEGIN
     EXECUTE IMMEDIATE 'DROP VIEW DETECT_INVALID_INDEX';
EXCEPTION
     WHEN OTHERS THEN
            IF SQLCODE != -942 THEN
                 RAISE;
            END IF;
END;
/

-- **********************************************

--------------------------------------------------------

    OR  NOT REGEXP_LIKE(ICD10,'^[a-tA-Tv-zV-Z][0-9][a-zA-Z0-9](\.[a-zA-Z0-9]{0,4})?$')
); 

-- ******************************************************
CREATE OR REPLACE VIEW DETECT_INVALID_LABNUM_RESULT AS
(
