Sha256: 607d012dd6e12295ae2e8db9ae7b0fc591a42ff6851c8230910253073f02d60e

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/events"

module Renalware
  module Events
    # Query object that returns, for a patient, the most recent matching event (if any) for each
    # event_type_alert_trigger row in the databse. The results are used to display
    # alerts in the UI.
    # For example given a vaccination Event::Type and an EventTypeAlertTrigger
    # which is configured to find any vaccination event with the word "covid" in
    # anywhere in the document, this query will return the most matching event.
    # It is possible to have mltiple triggers rows for the same event type, so for eample one
    # could display triggers for the most recent covid vaccination, and the most recent HBV
    # vaccination.
    class AlertableEventsQuery
      def self.call(patient:)
        Event
          .for_patient(patient)
          .joins(event_type: :alert_triggers)
          .select("DISTINCT ON (events.patient_id, event_type_alert_triggers.id) events.*")
          .where("(events.document::text ilike '%' || when_event_document_contains || '%') or (events.description ilike '%' || when_event_description_contains || '%')")
          .order("events.patient_id, event_type_alert_triggers.id, events.created_at desc")
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/models/renalware/events/alertable_events_query.rb
renalware-core-2.1.0 app/models/renalware/events/alertable_events_query.rb
renalware-core-2.0.167 app/models/renalware/events/alertable_events_query.rb
renalware-core-2.0.166 app/models/renalware/events/alertable_events_query.rb
renalware-core-2.0.165 app/models/renalware/events/alertable_events_query.rb
renalware-core-2.0.164 app/models/renalware/events/alertable_events_query.rb
renalware-core-2.0.163 app/models/renalware/events/alertable_events_query.rb
renalware-core-2.0.162 app/models/renalware/events/alertable_events_query.rb