Class: HlnIce::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/hln_ice/client.rb

Overview

Client for the HLN ICE (Immunization Calculation Engine) OpenCDS service.

Evaluates a patient’s immunization history against the ICE forecasting rules and returns both the raw recommendations and a simplified status mapping keyed by vaccine group.

Constant Summary collapse

STATUS_MAPPING =

Mapping from ICE status codes to our status keys

{
  "CONDITIONAL" => "conditional",
  "FUTURE_RECOMMENDED" => "compliant",
  "NOT_RECOMMENDED" => "compliant",
  "RECOMMENDED" => "overdue",
}.freeze
VACCINE_MAPPING =

Mapping from ICE vaccine groups to our immunization keys

{
  "DTP Vaccine Group" => :dtap_tdap,
  "Hep A Vaccine Group" => :hep_a,
  "Hep B Vaccine Group" => :hep_b,
  "Hib Vaccine Group" => :hib,
  "HPV Vaccine Group" => :hpv,
  "Meningococcal Vaccine Group" => :mcv4,
  "MMR Vaccine Group" => :mmr,
  "Pneumococcal Vaccine Group" => :pcv,
  "Polio Vaccine Group" => :ipv_opv,
  "Varicella Vaccine Group" => :var,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url:, timeout: 30, max_retries: 3, retry_delay: 1, logger: nil) ⇒ Client

Returns a new instance of Client.



42
43
44
45
46
47
48
# File 'lib/hln_ice/client.rb', line 42

def initialize(base_url:, timeout: 30, max_retries: 3, retry_delay: 1, logger: nil)
  @base_url = base_url
  @timeout = timeout
  @max_retries = max_retries
  @retry_delay = retry_delay
  @logger = logger || Logger.new($stdout)
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



40
41
42
# File 'lib/hln_ice/client.rb', line 40

def base_url
  @base_url
end

#loggerObject (readonly)

Returns the value of attribute logger.



40
41
42
# File 'lib/hln_ice/client.rb', line 40

def logger
  @logger
end

#max_retriesObject (readonly)

Returns the value of attribute max_retries.



40
41
42
# File 'lib/hln_ice/client.rb', line 40

def max_retries
  @max_retries
end

#retry_delayObject (readonly)

Returns the value of attribute retry_delay.



40
41
42
# File 'lib/hln_ice/client.rb', line 40

def retry_delay
  @retry_delay
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



40
41
42
# File 'lib/hln_ice/client.rb', line 40

def timeout
  @timeout
end

Instance Method Details

#available?Boolean

Check if the ICE service is available

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hln_ice/client.rb', line 51

def available?
  url = "#{base_url}/opencds-decision-support-service/version"

  begin
    response = HTTParty.get(
      url,
      timeout:
    )

    response.success?
  rescue => e
    logger.error("ICE service unavailable: #{e.message}")
    false
  end
end

#evaluate_immunizations(patient_data) ⇒ Object

Evaluate immunizations using patient data



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/hln_ice/client.rb', line 68

def evaluate_immunizations(patient_data)
  url = "#{base_url}/opencds-decision-support-service/api/resources/evaluate"

  # Build the payload for the ICE service
  payload = build_ice_payload(patient_data)

  # Make the request with retries
  response = nil
  retries = 0

  begin
    response = HTTParty.post(
      url,
      body: payload.to_json,
      headers: {
        "Content-Type": "application/json",
        "Accept": "application/json"
      },
      timeout:
    )

    if response.success?
      parse_ice_response(response.body)
    else
      handle_error_response(response)
    end
  rescue => e
    retries += 1
    if retries <= max_retries
      logger.warn("Retrying ICE request (#{retries}/#{max_retries}): #{e.message}")
      sleep(retry_delay)
      retry
    else
      logger.error("Error evaluating immunizations after #{max_retries} retries: #{e.message}")
      { success: false, error: "Error evaluating immunizations: #{e.message}" }
    end
  end
end