                 FROM 
                     trisano.dw_morbidity_events_view
                 WHERE
-                    disease_name = 'Hepatitis B Pregnancy Event'
+                    disease_name = 'Hepatitis B Pregnancy Event' AND
+                    actual_delivery_date IS NULL
                     ;
 
 CREATE TABLE report2 AS

                        SELECT
                            dw_contact_events_id AS contact_event_id,
                            trisano.earliest_date(trisano.array_accum(hbig_vacc_date )) AS hbig_vacc_date,
                            trisano.earliest_date(trisano.array_accum(hebp_dose1_date)) AS hepb_dose1_date,
                            trisano.earliest_date(trisano.array_accum(hepb_dose2_date)) AS hepb_dose2_date,
                            trisano.earliest_date(trisano.array_accum(hepb_dose3_date)) AS hepb_dose3_date,
                            trisano.earliest_date(trisano.array_accum(hepb_dose4_date)) AS hepb_dose4_date,
                            trisano.earliest_date(trisano.array_accum(hepb_dose5_date)) AS hepb_dose5_date,
                            trisano.earliest_date(trisano.array_accum(hepb_dose6_date)) AS hepb_dose6_date
                        FROM (
                            SELECT
                                dw_contact_events_id,
                                CASE WHEN treatment_name = 'HBIG' THEN date_of_treatment ELSE NULL END AS hbig_vacc_date,
                                CASE WHEN treatment_name = 'Hep B Dose 1 Vaccination' THEN date_of_treatment ELSE NULL END AS hebp_dose1_date,
                                CASE WHEN treatment_name = 'Hep B Dose 2 Vaccination' THEN date_of_treatment ELSE NULL END AS hepb_dose2_date,
                                -- The ~ is intentional
                                CASE WHEN treatment_name ~ 'Hep B Dose 3 Vaccination' THEN date_of_treatment ELSE NULL END AS hepb_dose3_date,
                                CASE WHEN treatment_name = 'Hep B Dose 4 Vaccination' THEN date_of_treatment ELSE NULL END AS hepb_dose4_date,
                                CASE WHEN treatment_name = 'Hep B Dose 5 Vaccination' THEN date_of_treatment ELSE NULL END AS hepb_dose5_date,
                                CASE WHEN treatment_name = 'Hep B Dose 6 Vaccination' THEN date_of_treatment ELSE NULL END AS hepb_dose6_date
                            FROM
                                trisano.dw_contact_treatments_events_view dct
                            WHERE
                                treatment_given = 'Yes'
                        ) treatments_split
                        GROUP BY dw_contact_events_id
                    ) treatments_agg
                        ON (treatments_agg.contact_event_id = dce.id)
                WHERE

                                    SELECT
                                        dw_contact_events_id AS contact_event_id,
                                        trisano.earliest_date(trisano.array_accum(hbig_vacc_date )) AS hbig,
                                        trisano.earliest_date(trisano.array_accum(hepb_dose1_date)) AS hepb_dose1_date,
                                        trisano.earliest_date(trisano.array_accum(hepb_dose2_date)) AS hepb_dose2_date,
                                        trisano.earliest_date(trisano.array_accum(hepb_dose3_date)) AS hepb_dose3_date,
                                        trisano.earliest_date(trisano.array_accum(hepb_dose4_date)) AS hepb_dose4_date,
                                        trisano.earliest_date(trisano.array_accum(hepb_dose5_date)) AS hepb_dose5_date,
                                        trisano.earliest_date(trisano.array_accum(hepb_dose6_date)) AS hepb_dose6_date,
                                        trisano.earliest_date(trisano.array_accum(hepb_comvax1_date)) AS hepb_comvax1_date,
                                        trisano.earliest_date(trisano.array_accum(hepb_comvax2_date)) AS hepb_comvax2_date,
                                        trisano.earliest_date(trisano.array_accum(hepb_comvax3_date)) AS hepb_comvax3_date,
                                        trisano.earliest_date(trisano.array_accum(hepb_comvax4_date)) AS hepb_comvax4_date,
                                        trisano.earliest_date(trisano.array_accum(hepb_comvax5_date)) AS hepb_comvax5_date,
                                        trisano.earliest_date(trisano.array_accum(hepb_comvax6_date)) AS hepb_comvax6_date
                                    FROM (
                                        SELECT
                                            dw_contact_events_id,
                                            CASE WHEN treatment_name = 'HBIG' THEN date_of_treatment ELSE NULL END AS hbig_vacc_date,
                                            CASE WHEN treatment_name = 'Hepatitis B Dose 1' THEN date_of_treatment ELSE NULL END AS hepb_dose1_date,
                                            CASE WHEN treatment_name = 'Hepatitis B Dose 2' THEN date_of_treatment ELSE NULL END AS hepb_dose2_date,
                                            CASE WHEN treatment_name = 'Hepatitis B Dose 3' THEN date_of_treatment ELSE NULL END AS hepb_dose3_date,
                                            CASE WHEN treatment_name = 'Hepatitis B Dose 4' THEN date_of_treatment ELSE NULL END AS hepb_dose4_date,
                                            CASE WHEN treatment_name = 'Hepatitis B Dose 5' THEN date_of_treatment ELSE NULL END AS hepb_dose5_date,
                                            CASE WHEN treatment_name = 'Hepatitis B Dose 6' THEN date_of_treatment ELSE NULL END AS hepb_dose6_date,
                                            CASE WHEN treatment_name = 'Hepatitis B - Comvax Dose 1' THEN date_of_treatment ELSE NULL END AS hepb_comvax1_date,
                                            CASE WHEN treatment_name = 'Hepatitis B - Comvax Dose 2' THEN date_of_treatment ELSE NULL END AS hepb_comvax2_date,
                                            CASE WHEN treatment_name = 'Hepatitis B - Comvax Dose 3' THEN date_of_treatment ELSE NULL END AS hepb_comvax3_date,
                                            CASE WHEN treatment_name = 'Hepatitis B - Comvax Dose 4' THEN date_of_treatment ELSE NULL END AS hepb_comvax4_date,
                                            CASE WHEN treatment_name = 'Hepatitis B - Comvax Dose 5' THEN date_of_treatment ELSE NULL END AS hepb_comvax5_date,
                                            CASE WHEN treatment_name = 'Hepatitis B - Comvax Dose 6' THEN date_of_treatment ELSE NULL END AS hepb_comvax6_date
                                        FROM
                                            trisano.dw_contact_treatments_events_view dct
                                        WHERE
