                                         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_dose7_date)) AS hepb_dose7_date,
+                                        trisano.earliest_date(trisano.array_accum(hepb_dose8_date)) AS hepb_dose8_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
+                                        trisano.earliest_date(trisano.array_accum(hepb_comvax6_date)) AS hepb_comvax6_date,
+                                        trisano.earliest_date(trisano.array_accum(hepb_comvax7_date)) AS hepb_comvax7_date,
+                                        trisano.earliest_date(trisano.array_accum(hepb_comvax8_date)) AS hepb_comvax8_date,
+                                        COALESCE(trisano.earliest_date(trisano.array_accum(hepb_dose1_date)), trisano.earliest_date(trisano.array_accum(hepb_comvax1_date))) AS dose1_recvd,
+                                        COALESCE(trisano.earliest_date(trisano.array_accum(hepb_dose2_date)), trisano.earliest_date(trisano.array_accum(hepb_comvax2_date))) AS dose2_recvd,
+                                        COALESCE(trisano.earliest_date(trisano.array_accum(hepb_dose3_date)), trisano.earliest_date(trisano.array_accum(hepb_comvax3_date))) AS dose3_recvd,
+                                        COALESCE(trisano.earliest_date(trisano.array_accum(hepb_dose4_date)), trisano.earliest_date(trisano.array_accum(hepb_comvax4_date))) AS dose4_recvd,
+                                        COALESCE(trisano.earliest_date(trisano.array_accum(hepb_dose5_date)), trisano.earliest_date(trisano.array_accum(hepb_comvax5_date))) AS dose5_recvd,
+                                        COALESCE(trisano.earliest_date(trisano.array_accum(hepb_dose6_date)), trisano.earliest_date(trisano.array_accum(hepb_comvax6_date))) AS dose6_recvd,
+                                        COALESCE(trisano.earliest_date(trisano.array_accum(hepb_dose7_date)), trisano.earliest_date(trisano.array_accum(hepb_comvax7_date))) AS dose7_recvd,
+                                        COALESCE(trisano.earliest_date(trisano.array_accum(hepb_dose8_date)), trisano.earliest_date(trisano.array_accum(hepb_comvax8_date))) AS dose8_recvd
                                     FROM (
                                         SELECT
                                             dw_contact_events_id,

                                -- comments inline. The current maximum value
                                -- is 9
                                CASE
                                    WHEN dce.contact_type = 'Infant' THEN
                                        CASE
                                            WHEN dce.birth_date IS NULL AND dme_2.actual_delivery_date IS NULL THEN 
                                                8 -- fdd = report date, act = "Enter Infant's Date of Birth"
                                            WHEN hbig IS NULL THEN
                                                CASE
                                                    WHEN hepb_dose1_date IS NULL AND hepb_comvax1_date IS NULL THEN
                                                        1 -- fdd = dob, act = "Needs HBIG and Hepatitis B Dose 1"
                                                    ELSE
                                                        CASE WHEN CURRENT_DATE - dce.birth_date < 7 THEN
                                                            2 -- fdd = dob, act = "Needs HBIG"
                                                        ELSE
                                                            4 -- fdd = COALESCE(hepb_dose1_date, hepb_comvax1_date) + INTERVAL '6 months', act = "Needs Hepatitis B Dose 2"
                                                        END
                                                END
                                            ELSE -- hbig is not null
                                                CASE
                                                    WHEN hepb_dose1_date IS NULL AND hepb_comvax1_date IS NULL THEN
                                                        3 -- fdd = dob, act = "Needs Hepatitis B Dose 1"
                                                    WHEN hepb_dose2_date IS NULL AND hepb_comvax2_date IS NULL THEN
                                                        4 -- fdd = COALESCE(hepb_dose1_date, hepb_comvax1_date) + INTERVAL '6 months', act = "Needs Hepatitis B Dose 2"
                                                    WHEN hepb_dose3_date IS NULL AND hepb_comvax4_date IS NULL THEN
                                                        5 -- fdd = COALESCE(hepb_dose2_date, hepb_comvax2_date) + INTERVAL '6 months', act = "Needs Hepatitis B Dose 3"
                                                    WHEN
                                                        hepb_dose3_date IS NULL AND hepb_comvax4_date IS NULL AND
                                                        COALESCE(  -- between 9 and 18 months old
                                                            (now() - COALESCE(dce.birth_date, dme_2.actual_delivery_date)) BETWEEN (interval '30 days' * 9) AND (interval '30 days' * 18),
                                                            dce.age_in_years BETWEEN .6 AND 1.5
                                                        ) AND
                                                        (trisano.get_contact_hbsag_before(dce.id, CURRENT_DATE)).lab_test_date IS NULL AND
                                                        (trisano.get_contact_hbsag_before(dce.id, CURRENT_DATE)).test_result IS NULL THEN
                                                        6 -- fdd = dob + INTERVAL '9 months', act = "Needs Serology 3 months after Hepatitis B Dose 3 / Hepatitis B – Comvax Dose 4"
                                                    ELSE -1 -- don't show this contact
                                                END
                                        END    
                                    ELSE -- Not an 'Infant' type
                                        CASE
                                            WHEN
                                                COALESCE((trisano.get_contact_hbsag_before(dce.id, CURRENT_DATE)).test_result, 'dummy') = 'Positive / Reactive' OR
                                                COALESCE((trisano.get_contact_antihb_before(dce.id, CURRENT_DATE)).test_result, 'dummy') = 'Positive / Reactive'
                                                THEN 9 -- fdd = report date, act = 'Close Contact'
                                            WHEN
                                                (
                                                    (hepb_dose1_date IS NULL AND hepb_comvax1_date IS NULL) OR
                                                    (hepb_dose2_date IS NULL AND hepb_comvax2_date IS NULL) OR
                                                    (hepb_dose3_date IS NULL AND hepb_comvax3_date IS NULL)
                                                ) AND hepb_dose6_date IS NULL
                                                THEN
                                                    7 -- fdd = report date, act = "Check vaccination history; Test or Vaccinate"
                                            ELSE 
                                                CASE WHEN disposition = 'Closed: Completed' THEN -1 -- Don't show this contact
                                                ELSE 9 -- fdd = report date, act = 'Close contact'
                                                END
                                        END
                                END AS fdd_act_code
                            FROM
                                trisano.dw_contact_events_view dce

                                hepb_dose2_date::TIMESTAMPTZ,
                                hepb_comvax1_date::TIMESTAMPTZ,
                                hepb_comvax2_date::TIMESTAMPTZ,
                                dose1_recvd, dose2_recvd, dose3_recvd,
                                dose4_recvd, dose5_recvd, dose6_recvd,
                                dose7_recvd, dose8_recvd,
                                CASE
                                    WHEN dce.birth_date IS NOT NULL THEN
                                        CASE
