   ,ceil(EXTRACT(SECOND FROM provider_first_view.created-provider_first_assign.created))  as "Time_to_SP_Access"
   ,'PASS' as "Residency_Test"
   ,null as "Repeat_Contact"
-  ,CASE WHEN log.code in ('COSPF', 'IRKB', 'SPFN', 'SPFM') THEN log.notes END as "Referral_Agencies"
+  ,null as "Referral_Agencies"
   ,null as "Complaint_Type"
   ,null as "Complaint_Date"
   ,null as "Complaint_Owner"

  ,c.from_case_id::boolean as "Split_Check"
  ,split_case.laa_reference as "Split_Link_Case"
  -- /SPLIT FIELDS. --
  ,COALESCE(trim((log.context->'provider')::text, '"'), provider.name) as "Provider_ID" -- need to convert to LAA provider ID
  ,category.code as "Category_Name"
  ,c.created as "Date_Case_Created"
  ,c.modified as "Last_Modified_Date"
  ,log.code as "Outcome_Code_Child"
  ,ceil(EXTRACT(EPOCH FROM (timer.stopped - timer.created))) as "Billable_Time"
  ,CASE WHEN latest_outcome.id = log.id THEN c.billable_time ELSE null END as "Cumulative_Time"
  ,mt1.code as "Matter_Type_1"
  ,mt2.code as "Matter_Type_2"

  LEFT OUTER JOIN provider_first_assign on provider_first_assign.case_id = c.id
  LEFT OUTER JOIN legalaid_case split_case on c.from_case_id = split_case.id
  LEFT OUTER JOIN diversity_view on pd.id = diversity_view.id
  LEFT OUTER JOIN cla_provider_provider as assigned_provider on trim((log.context->'provider_id')::text, '"')::numeric = assigned_provider.id

where
  log.type = 'outcome'
  and log.created >= %s
