OHSU Hypertension Implementation Guide
0.1.0 - CI Build Unknown region code '840'

OHSU Hypertension Implementation Guide, published by Oregon Health and Science University. This guide is not an authorized publication; it is the continuous build for version 0.1.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/OHSUCMP/htnu18ig/ and changes regularly. See the Directory of published versions

Library: Non-medicinal Therapy Logic

Official URL: http://fhir.org/guides/ohsuhypertensionig/Library/NonPharmacologicIntervention Version: 0.1.0
Draft as of 2026-04-24 Computable Name: NonPharmacologicIntervention

Copyright/Legal: Published by OHSU under an Apache 2.0 License

Decision logic for providing tailored lifestyle recommendations based on patient behaviors.

Metadata
Title Non-medicinal Therapy Logic
Version 0.1.0
Status Draft
Jurisdiction 840 from http://unstats.un.org/unsd/methods/m49/m49.htm
Steward (Publisher) Oregon Health and Science University
Steward Contact Oregon Health and Science University
Description

Decision logic for providing tailored lifestyle recommendations based on patient behaviors.

Copyright

Published by OHSU under an Apache 2.0 License

Dependency Description: FHIR model information
Resource: http://fhir.org/guides/cqf/common/Library/FHIR-ModelInfo|4.0.1
Canonical URL: http://fhir.org/guides/cqf/common/Library/FHIR-ModelInfo|4.0.1
Dependency Description: Library FHIRHelpers
Resource: http://fhir.org/guides/ohsuhypertensionig/Library/FHIRHelpers|4.0.1
Canonical URL: http://fhir.org/guides/ohsuhypertensionig/Library/FHIRHelpers|4.0.1
Dependency Description: Library Common
Resource: Common Logic version: 0.1.0
Canonical URL: http://fhir.org/guides/ohsuhypertensionig/Library/OHSUHTNCommon|0.1
Dependency Description: Code system LOINC
Resource: LOINC
Canonical URL: http://loinc.org
Dependency Description: Code system Goal achievement status
Resource: Goal achievement status
Canonical URL: http://terminology.hl7.org/CodeSystem/goal-achievement
Dependency Description: Code system ConditionVerificationStatusCodes
Resource: ConditionVerificationStatus
Canonical URL: http://terminology.hl7.org/CodeSystem/condition-ver-status
Dependency Description: Code system ConditionCategorySystem
Resource: Condition Category Codes
Canonical URL: http://terminology.hl7.org/CodeSystem/condition-category
Dependency Description: Value set Tobacco Use Cessation Counseling
Resource: Tobacco Use Cessation Counseling
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.509
Dependency Description: Value set Weight Reduction Recommendations
Resource: Weight Reduction Recommendations
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1116.420
Dependency Description: Value set BMI Follow Up Plan SNOMEDCT
Resource: BMI Follow Up Plan SNOMEDCT
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1195.111
Dependency Description: Value set Alcohol Brief Intervention and Counseling
Resource: Alcohol Brief Intervention and Counseling
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1032.124
Dependency Description: Value set Counseling for Nutrition
Resource: Counseling for Nutrition
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.195.12.1003
Dependency Description: Value set Physical Activity Recommendations
Resource: Physical Activity Recommendations
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1116.418
Dependency Description: Value set Tobacco Smoking Status [Current] (Social History) (LOINC)
Resource: Tobacco Smoking Status [Current] (Social History) (LOINC)
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1330
Dependency Description: Value set Tobacco User
Resource: Tobacco User
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.2.422
Dependency Description: Value set BMI Ratio
Resource: BMI Ratio
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1.1490
Dependency Description: Value set Average Number of Drinks per Drinking Day
Resource: Average Number of Drinks per Drinking Day
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.106.11.1030
Dependency Description: Value set Alcohol Abuse Disorder
Resource: Alcohol Abuse Disorder
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1222.24
Dependency Description: Value set Hypertension
Resource: Hypertension
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.104.12.1016
Dependency Description: Value set Non essential Hypertension SNOMEDCT
Resource: Non essential Hypertension SNOMEDCT
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1032.10
Dependency Description: Value set Systolic Blood Pressure
Resource: Systolic blood pressure
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1104.2
Dependency Description: Value set Diastolic Blood Pressure
Resource: Diastolic Blood Pressure
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.2.1045
Dependency Description: Value set Blood Pressure Measured
Resource: Blood Pressure Measured
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.2012
Dependency Description: Value set End Stage Renal Disease
Resource: End Stage Renal Disease
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.2.590
Dependency Description: Value set Pregnancy
Resource: Pregnancy
Canonical URL: http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.378
Data Requirement Type: Patient
Profile(s): Patient
Must Support Elements: given, family
Data Requirement Type: Condition
Profile(s): Condition
Must Support Elements: code
Data Requirement Type: Observation
Profile(s): Observation
Must Support Elements: code, effective, value, component
Data Requirement Type: Goal
Profile(s): Goal
Must Support Elements: lifecycleStatus, category, target, target.due, target.due.value
Data Requirement Type: Procedure
Profile(s): Procedure
Must Support Elements: code
Parameters
Name Use Card. Type Documentation
Patient Out 0..1 Patient
Info Out 0..1 string
Patient Name Out 0..1 string
Meets Inclusion Criteria Out 0..1 boolean
Meets Exclusion Criteria Out 0..1 boolean
In Population Out 0..1 boolean
Goals Out 0..* Goal
Tobacco Cessation Goals Out 0..* Goal
Weight Loss Goals Out 0..* Goal
Alcohol Goals Out 0..* Goal
Physical Activity Goals Out 0..* Goal
Nutrition Goals Out 0..* Goal
Patient Has Behavioral Goals Out 0..1 boolean
Receive Therapy Out 0..1 boolean
Enter Workflow Out 0..1 boolean
Tobacco Cessation Goals Needing Update Out 0..* Goal
Smoking Status Observations Out 0..* Observation
Observations Indicating Patient is a Smoker Out 0..* Observation
Most Recent Observation of Patient Smoking Status Out 0..1 Observation
Patient is Currently a Smoker Out 0..1 boolean
Procedures Out 0..* Procedure
Last Smoking Counseling Procedure Out 0..1 Procedure
Needs Smoking Counseling Out 0..1 boolean
Smoking Recommendation Out 0..1 string
Tobacco Goal Summary Out 0..1 string
Smoking Rationale Out 0..1 string
Smoking Suggestions Out 0..1 string
Smoking Links Out 0..1 string
Smoking Rationale Combined Data Out 0..1 string
Smoking Indicator Status Out 0..1 string
Weight Loss Goals Needing Update Out 0..* Goal
Observations Specifying Patient BMI Out 0..* Observation
Most Recent Patient BMI Out 0..1 Observation
Patient BMI is Greater than 25 kg/m2 Out 0..1 boolean
Last BMI Counseling Procedure Out 0..1 Procedure
BMI Recommendation Out 0..1 string
Weight Loss Goal Summary Out 0..1 string
BMI Rationale Out 0..1 string
BMI Suggestions Out 0..1 string
BMI Links Out 0..1 string
BMI Rationale Combined Data Out 0..1 string
Weight Loss Indicator Status Out 0..1 string
Alcohol Goals Needing Update Out 0..* Goal
Observations Measuring Amount of Alcoholic Drinks Patient has per Drinking Day Out 0..* Observation
Most Recent Patient Drinking Observation Out 0..1 Observation
Heavy Daily Drinker Out 0..1 decimal
Condition Indicating Alcohol Abuse Disorder Out 0..* Condition
Patient is a Heavy Alcoholic Drinker Out 0..1 boolean
Last Alcohol Counseling Procedure Out 0..1 Procedure
Needs Alcohol Counseling Out 0..1 boolean
Alcohol Recommendation Out 0..1 string
Alcohol Moderation Goal Summary Out 0..1 string
Alcohol Rationale Out 0..1 string
Alcohol Suggestions Out 0..1 string
Alcohol Links Out 0..1 string
Alcohol Rationale Combined Data Out 0..1 string
Alcohol Moderation Indicator Status Out 0..1 string
Nutrition Goals Needing Update Out 0..* Goal
Last Nutrition Counseling Procedure Out 0..1 Procedure
Nutrition Recommendation Out 0..1 string
Nutrition Goal Summary Out 0..1 string
Nutrition Rationale Out 0..1 string
Nutrition Suggestions Out 0..1 string
Nutrition Links Out 0..1 string
Nutrition Rationale Combined Data Out 0..1 string
Nutrition Indicator Status Out 0..1 string
Physical Activity Goals Needing Update Out 0..* Goal
Last Physical Activity Counseling Procedure Out 0..1 Procedure
Physical Activity Recommendation Out 0..1 string
Physical Activity Goal Summary Out 0..1 string
Physical Activity Rationale Out 0..1 string
Physical Activity Suggestions Out 0..1 string
Physical Activity Links Out 0..1 string
Physical Activity Rationale Combined Data Out 0..1 string
Physical Activity Indicator Status Out 0..1 string
Patient Smoking Goals Action Path Out 0..1 boolean
Patient Weight Loss Goals Action Path Out 0..1 boolean
Patient Alcohol Goals Action Path Out 0..1 boolean
Patient Nutrition Goals Action Path Out 0..1 boolean
Patient Physical Activity Goals Action Path Out 0..1 boolean
TEST Get Average All BP Last 2 Years Out 0..1 Resource
TEST Get Average Most Recent BP Set Out 0..1 Resource
TEST Exclusion Out 0..1 boolean
Library Content
CQL Content
library NonPharmacologicIntervention version '0.1'

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1' called FHIRHelpers
include OHSUHTNCommon version '0.1' called Common

codesystem "LOINC": 'http://loinc.org'
codesystem "Goal achievement status": 'http://terminology.hl7.org/CodeSystem/goal-achievement'

valueset "Tobacco Use Cessation Counseling": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.3.509'
valueset "Weight Reduction Recommendations": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1116.420'
valueset "BMI Follow Up Plan SNOMEDCT": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1195.111'
valueset "Alcohol Brief Intervention and Counseling": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1032.124'
valueset "Counseling for Nutrition": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.195.12.1003'
valueset "Physical Activity Recommendations": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1116.418'
valueset "Tobacco Smoking Status [Current] (Social History) (LOINC)": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1146.1330'
valueset "Tobacco User": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.526.2.422'
valueset "BMI Ratio": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.600.1.1490'
valueset "Average Number of Drinks per Drinking Day": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.106.11.1030'
valueset "Alcohol Abuse Disorder": 'http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1222.24'

code "PACKS A DAY": '8663-7' from "LOINC" display 'Cigarettes smoked current (pack per day) - Reported'

context Patient

define "Info":
  'info'

define function "Last Counseling Procedure"(procedures List<FHIR.Procedure>):
    (Last(procedures P sort by start of Common."Normalize Interval"(performed)))

define function "Unique Goal Id"(goal String):
  goal + ToString(Now())

/* Extract the COACH Code from the Goal */
define function "Goal Category"(goal FHIR.Goal):
  singleton from (goal.category category
    let coding: singleton from (category.coding c where c.system.value = 'https://coach.ohsu.edu')
    return FHIRHelpers.ToCode(coding))

/* Return a list containing the json string needed to update each given Goal */
define function "Update Goals String"(goals List<FHIR.Goal>):
  goals Goal
    let coding: "Goal Category"(Goal)
    return '{"id": "' + Goal.id + '", "type": "update-goal", "references": {"system":"' + coding.system + '", "code":"' + coding.code + '"}, "label": "Goal: '+ Goal.description.text + '"}'

define function "Goal Summary"(goals List<FHIR.Goal>):
  goals Goal return '<strong>' + Goal.description.text + '</strong>'

define "Patient Name":
  First(Patient.name.given)
   + ' ' +
  First(Patient.name.family)

/* Recommendation Criteria - Non-Pharmacologic Interventions  */
define "Meets Inclusion Criteria":
  exists Common."Condition Indicating Preexisting Hypertension" and not Common."HTN Crisis"

define "Meets Exclusion Criteria":
  Common."Patient Under Age 18"
    or Common."Patient Over Age 100"
    or exists Common."Condition Indicating End Stage Renal Disease"
    or exists Common."Condition Indicating Pregnancy"

define "In Population":
  // Preserve this ordering so excluded patients fail fast
  not "Meets Exclusion Criteria" and "Meets Inclusion Criteria"

/***** Decision Diamonds *****/
define "Patient Has Behavioral Goals":
  exists "Tobacco Cessation Goals" or
  exists "Weight Loss Goals" or
  exists "Alcohol Goals" or
  exists "Physical Activity Goals" or
  exists "Nutrition Goals"

// Therapy should be received if we're still collecting BPs or if the patient hasn't achieved their goal yet
define "Receive Therapy":
  not Common."Has BP Set" or (Common."Patient has a BP Goal" and Common."Above Goal Average Most Recent")

define "Enter Workflow":
  "In Population" and ("Patient Has Behavioral Goals" or "Receive Therapy")

/***** SMOKING CARD OUTPUT *****/

define "Smoking Recommendation":
  if exists "Tobacco Cessation Goals Needing Update" then 'Smoking cessation goal check-in.'
  else if exists "Tobacco Cessation Goals" then 'Smoking cessation goal check-in.'
  else if "Needs Smoking Counseling" then 'Discuss smoking cessation.'
  else if "Patient is Currently a Smoker" then 'Reminder about smoking cessation.'
  else ''

define "Smoking Rationale Combined Data":
  "Smoking Rationale" + '|' + "Smoking Suggestions" + '|at-most-one|' + "Smoking Links"

define "Smoking Rationale":
  if exists "Tobacco Cessation Goals Needing Update" then '{{#patient}}You set a smoking cessation goal and it is time to update your progress.{{/patient}}'
  else if exists "Tobacco Cessation Goals" then '{{#patient}}You set a smoking cessation goal; it isn\'t quite the time you set to update, but you can update that goal at any time.<br>' + "Tobacco Goal Summary" + '{{/patient}}'
  else if "Needs Smoking Counseling" then '{{#patient}}Reducing your smoking will help lower blood pressure, the risk of stroke, and other harmful events. Please discuss methods to reduce smoking with your care team.{{/patient}}{{#careTeam}}Patient reports they smoke. Counsel about quitting according to your local protocol.{{/careTeam}}'
  else if "Patient is Currently a Smoker" then '{{#patient}}You previously received counseling about quitting smoking, which would lower your blood pressure and other health risks. Please consider readdressing this goal.{{/patient}}{{#careTeam}}Patient still smokes, but has been counseled. Consider reminding about quitting according to your local protocol.{{/careTeam}}'
  else ''

define "Smoking Suggestions":
  if exists "Tobacco Cessation Goals Needing Update" then '[' + Combine("Update Goals String"("Tobacco Cessation Goals Needing Update"), ',') + ']'
  else if exists "Tobacco Cessation Goals" then '[ { "id": "goal-suggestion", "label": "", "type": "suggestion-link", "actions": [{"label":"View/Edit Goals", "url":"/goals"}] } ]'
  else if "Needs Smoking Counseling" then '[
    {"id": "smoking-counseling", "type":"counseling-link", "references": {"system":"http://snomed.info/sct", "code":"225323000"},"label": "Smoking Cessation Counseling","actions": [{"url":"/counseling/smoking-cessation", "label":"Click here to learn more about tobacco cessation."}]},
    {"id": "' + "Unique Goal Id"('smoking-goal-') + '", "type":"goal", "references":{"system":"https://coach.ohsu.edu", "code":"smoking-cessation", "display": "Smoking Cessation"}, "label": "Set a Tobacco Cessation Goal", "actions": [{"label":"Reduce my tobacco use to [quantity] [method:cigarettes] per [time period]."}] }]'
  else if "Patient is Currently a Smoker" then '[ { "id": "' + "Unique Goal Id"('smoking-goal-') + '", "type":"goal", "references":{"system":"https://coach.ohsu.edu", "code":"smoking-cessation", "display": "Smoking Cessation"}, "label": "Set a Tobacco Cessation Goal", "actions": [{"label":"Reduce my tobacco use to [quantity] [method:cigarettes] per [time period]."}] } ]'
  else ''

define "Smoking Links":
  '[
    { "label": "AHA: Smoking and your Health", "url": "https://www.heart.org/en/health-topics/high-blood-pressure/changes-you-can-make-to-manage-high-blood-pressure/smoking-high-blood-pressure-and-your-health"}
  ]'

define "Tobacco Goal Summary":
  Combine("Goal Summary"("Tobacco Cessation Goals"), '<br>')

define "Smoking Indicator Status":
  if exists "Tobacco Cessation Goals Needing Update" then 'warning'
  else 'info'

/***** WEIGHT LOSS CARD OUTPUT *****/

define "BMI Recommendation":
  if exists "Weight Loss Goals Needing Update" then 'Weight loss goal check-in.'
  else if exists "Weight Loss Goals" then 'Weight loss goal check-in.'
  else if "Patient BMI is Greater than 25 kg/m2" and "Last BMI Counseling Procedure" is null then 'Consider weight loss strategies.'
  else if "Patient BMI is Greater than 25 kg/m2" then 'Reminder about weight loss.'
  else ''

define "BMI Rationale Combined Data":
  "BMI Rationale" + '|' + "BMI Suggestions" + '|at-most-one|' + "BMI Links"

define "BMI Rationale":
  if exists "Weight Loss Goals Needing Update" then '{{#patient}}You set a goal for weight loss and it is time to update your progress.{{/patient}}'
  else if exists "Weight Loss Goals" then '{{#patient}}You set a goal for weight loss; it isn\'t quite the time you set to update, but you can update at any time.<br>' + "Weight Loss Goal Summary" + '{{/patient}}'
  else if "Patient BMI is Greater than 25 kg/m2" and "Last BMI Counseling Procedure" is null then '{{#patient}}Your current weight suggests that weight reduction will help lower your blood pressure, the risk of stroke, and other harmful events. Please discuss stategies with your care team to lose weight.{{/patient}}{{#careTeam}}Patient has a BMI of 25 or greater. Guidelines recommend weight loss to aid in lowering blood pressure.{{/careTeam}}'
  else if "Patient BMI is Greater than 25 kg/m2" then '{{#patient}}You previously received counseling about weight loss. Weight reduction will help lower your blood pressure. Please consider readdressing this goal.{{/patient}}{{#careTeam}}Patient has a BMI of 25 or greater; they have been counseling, but may need a reminder.{{/careTeam}}'
  else ''

define "BMI Suggestions":
  if exists "Weight Loss Goals Needing Update" then '[' + Combine("Update Goals String"("Weight Loss Goals Needing Update"), ',') + ']'
  else if exists "Weight Loss Goals" then '[ { "id": "goal-suggestion", "label": "", "type": "suggestion-link", "actions": [{"label":"View/Edit Goals", "url":"/goals"}] } ]'
  else if "Patient BMI is Greater than 25 kg/m2" and "Last BMI Counseling Procedure" is null then '[
    {"id": "weight-loss-counseling", "label": "Weight Loss Counseling", "type": "counseling-link", "references": {"system":"http://snomed.info/sct", "code":"266724001"}, "actions": [ {"label":"Learn more about weight loss.", "url":"/counseling/weight-loss"}]},
    {"id": "' + "Unique Goal Id"('weight-loss-goal-') + '", "type":"goal", "references":{"system":"https://coach.ohsu.edu", "code":"weight-loss", "display": "Weight Loss"}, "label": "Set a Weight Loss Goal", "actions": [{"label":"Reduce my weight by [quantity] pounds."}] }
  ]'
  else if "Patient BMI is Greater than 25 kg/m2" then '[ { "id": "' + "Unique Goal Id"('weight-loss-goal-') + '", "type":"goal", "references":{"system":"https://coach.ohsu.edu", "code":"weight-loss", "display": "Weight Loss"}, "label": "Set a Weight Loss Goal", "actions": [{"label":"Reduce my weight by [quantity] pounds."}] } ]'
  else ''

define "BMI Links":
  '[
    {"label":"University of Michigan: Hypertension", "url":"https://uhs.umich.edu/hypertension"},
    {"label":"AHA: Changes You Can Make to Manage High Blood Pressure", "url":"https://www.heart.org/en/health-topics/high-blood-pressure/changes-you-can-make-to-manage-high-blood-pressure"}
  ]'

define "Weight Loss Goal Summary":
  Combine("Goal Summary"("Weight Loss Goals"), '<br>')

define "Weight Loss Indicator Status":
  if exists "Weight Loss Goals Needing Update" then 'warning'
  else 'info'

/***** ALCOHOL CARD OUTPUT *****/

define "Alcohol Recommendation":
  if exists "Alcohol Goals Needing Update" then 'Alcohol moderation goal due for update.'
  else if exists "Alcohol Goals" then 'Alcohol moderation check-in.'
  else if "Needs Alcohol Counseling" then 'Discuss alcohol moderation.'
  else if "Patient is a Heavy Alcoholic Drinker" then 'Reminder about strategies for alcohol moderation.'
  else ''

define "Alcohol Rationale Combined Data":
  "Alcohol Rationale" + '|' + "Alcohol Suggestions" + '|at-most-one|' + "Alcohol Links"

define "Alcohol Rationale":
  if exists "Alcohol Goals Needing Update" then '{{#patient}}You set a goal to reduce drinking alcohol and it is time to update your progress.{{/patient}}'
  else if exists "Alcohol Goals" then '{{#patient}}You set a goal to reduce alcohol; it isn\'t quite the time you set to update, but you can update at any time.<br>' + "Alcohol Moderation Goal Summary" + '{{/patient}}'
  else if "Needs Alcohol Counseling" then '{{#patient}}Reducing your alcohol consumption will help lower your blood pressure, along with other health risks. Please discuss methods to reduce your drinking with your care team.{{/patient}}{{#careTeam}}Patient reports heavy alcohol use. Counsel them to cut down or quit according to your local protocol.{{/careTeam}}'
  else if "Patient is a Heavy Alcoholic Drinker" then '{{#patient}}You previously received counseling about alcohol consumption. Moderating alcohol consumption has proven benefits to heart health and reducing blood pressure. Please consider readdressing this goal.{{/patient}}'
  else ''

define "Alcohol Suggestions":
  if exists "Alcohol Goals Needing Update" then '[' + Combine("Update Goals String"("Alcohol Goals Needing Update"), ',') + ']'
  else if exists "Alcohol Goals" then '[ { "id": "goal-suggestion", "label": "", "type": "suggestion-link", "actions": [{"label":"View/Edit Goals", "url":"/goals"}] } ]'
  else if "Needs Alcohol Counseling" then '[
    {"id": "alcohol-counseling", "label": "Alcohol Counseling", "type": "counseling-link", "references": {"system":"http://snomed.info/sct", "code":"24165007"}, "actions": [ {"label":"Learn more about alcohol moderation.", "url":"/counseling/alcohol-moderation"}]},
    {"id": "' + "Unique Goal Id"('alcohol-goal-') + '", "type":"goal", "references":{"system":"https://coach.ohsu.edu", "code":"alcohol-moderation", "display": "Alcohol Moderation"}, "label": "Set an Alcohol Moderation Goal", "actions": [{"label":"Reduce my alcohol consumption to [quantity] drinks per [time period]."}] }
  ]'
  else if "Patient is a Heavy Alcoholic Drinker" then '[{ "id": "' + "Unique Goal Id"('alcohol-goal-') + '", "type":"goal", "references":{"system":"https://coach.ohsu.edu", "code":"alcohol-moderation", "display": "Alcohol Moderation"}, "label": "Set an Alcohol Moderation Goal", "actions": [{"label":"Reduce my alcohol consumption to [quantity] drinks per [time period]."}] } ]'
  else ''

define "Alcohol Links":
  '[
    {"label":"AHA: Alcohol and High Blood Pressure", "url":"https://www.heart.org/en/health-topics/high-blood-pressure/changes-you-can-make-to-manage-high-blood-pressure/limiting-alcohol-to-manage-high-blood-pressure"}
  ]'

define "Alcohol Moderation Goal Summary":
  Combine("Goal Summary"("Alcohol Goals"), '<br>')

define "Alcohol Moderation Indicator Status":
  if exists "Alcohol Goals Needing Update" then 'warning'
  else 'info'

/***** NUTRITION CARD OUTPUT *****/

define "Nutrition Recommendation":
  if exists "Nutrition Goals Needing Update" then 'Nutrition goal update.'
  else if exists "Nutrition Goals" then 'Nutrition goal check-in.'
  else if "Last Nutrition Counseling Procedure" is null then 'Discuss dietary changes (with salt/sodium reduction).'
  else 'Reminder about nutrition.'

define "Nutrition Rationale Combined Data":
  "Nutrition Rationale" + '|' + "Nutrition Suggestions" + '|at-most-one|' + "Nutrition Links"

define "Nutrition Rationale":
  if exists "Nutrition Goals Needing Update" then '{{#patient}}You set a nutrition goal and it is time to update your progress.{{/patient}}'
  else if exists "Nutrition Goals" then '{{#patient}}You set a nutrition goal; it isn\'t quite the time you set to update it, but you may update that goal at any time.<br>' + "Nutrition Goal Summary" + '{{/patient}}'
  else if "Last Nutrition Counseling Procedure" is null then '{{#patient}}Choosing the DASH diet, a low-sodium diet or another heart-healthy diet, may lower your elevated blood pressure and reduce your risk of heart attack and stroke. Please discuss potential dietary changes with your care team.{{/patient}}{{#careTeam}}Patient needs counseling about reducing sodium or choosing a heart healthy diet.{{/careTeam}}'
  else '{{#patient}}You have previously received counseling about dietary change. Maintaining a healthy diet that avoids excess salt/sodium could help control blood pressure. Please consider readressing this goal.{{/patient}}'

define "Nutrition Suggestions":
  if exists "Nutrition Goals Needing Update" then '[' + Combine("Update Goals String"("Nutrition Goals Needing Update"), ',') + ']'
  else if exists "Nutrition Goals" then '[ { "id": "goal-suggestion", "label": "", "type": "suggestion-link", "actions": [{"label":"View/Edit Goals", "url":"/goals"}] } ]'
  else if "Last Nutrition Counseling Procedure" is null then '[
    {"id": "nutrition-counseling", "label": "Nutrition Counseling", "type": "counseling-link", "references": {"system":"http://snomed.info/sct", "code":"11816003"}, "actions": [ {"label":"Learn more about nutrition and diet changes.", "url":"/counseling/diet"}]},
    {"id": "' + "Unique Goal Id"('nutrition-goal-') + '", "type":"goal", "references":{"system":"https://coach.ohsu.edu", "code":"nutrition", "display": "Nutrition"}, "label": "Set a Nutrition/Diet Change Goal", "actions": [{"label":"Avoid eating [food item] for the next [quantity] [time period:week(s)]."}]}
  ]'
  else '[{ "id": "' + "Unique Goal Id"('nutrition-goal-') + '", "type":"goal", "references":{"system":"https://coach.ohsu.edu", "code":"nutrition", "display": "Nutrition"}, "label": "Set a Nutrition/Diet Change Goal", "actions": [{"label":"Avoid eating [food item] for the next [quantity] [time period:week(s)]."}] } ]'

define "Nutrition Links":
  '[
    {"label": "NIH: DASH Diet", "url": "https://www.nhlbi.nih.gov/health-topics/dash-eating-plan"},
    {"label": "CDC: Eating Healthy", "url": "https://www.cdc.gov/healthy-weight-growth/healthy-eating/"}
  ]'

define "Nutrition Goal Summary":
    Combine("Goal Summary"("Nutrition Goals"), '<br>')

define "Nutrition Indicator Status":
  if exists "Nutrition Goals Needing Update" then 'warning'
  else 'info'

/***** PHYSICAL ACTIVITY CARD OUTPUT *****/

define "Physical Activity Recommendation":
  if exists "Physical Activity Goals Needing Update" then 'Physical activity goal check-in.'
  else if exists "Physical Activity Goals" then 'Physical activity goal check-in.'
  else if "Last Physical Activity Counseling Procedure" is null then 'Discuss strategies for increasing physical activity.'
  else 'Reminder about physical activity.'

define "Physical Activity Rationale Combined Data":
  "Physical Activity Rationale" + '|' + "Physical Activity Suggestions" + '|at-most-one|' + "Physical Activity Links"

define "Physical Activity Rationale":
  if exists "Physical Activity Goals Needing Update" then '{{#patient}}You set a physical activity goal and it is time to update your progress.{{/patient}}'
  else if exists "Physical Activity Goals" then '{{#patient}}You set a physical activity goal; it isn\'t quite the time you set to update it, but you may update that goal at any time.<br>' + "Physical Activity Goal Summary" + '{{/patient}}'
  else if "Last Physical Activity Counseling Procedure" is null then '{{#patient}}Physical activity can help reduce your blood pressure, risk of stroke, and other harmful events. Please discuss strategies to increase your physical activity with your care team.{{/patient}}{{#careTeam}}Patient needs counseling about increasing physical activity.{{/careTeam}}'
  else '{{#patient}}You previously received counseling about physical activity. Maintaining at least a moderate amount of physical activity will help control blood pressure. Please consider readdressing this goal.{{/patient}}'

define "Physical Activity Suggestions":
  if exists "Physical Activity Goals Needing Update" then '[' + Combine("Update Goals String"("Physical Activity Goals Needing Update"), ',') + ']'
  else if exists "Physical Activity Goals" then '[ { "id": "goal-suggestion", "label": "", "type": "suggestion-link", "actions": [{"label":"View/Edit Goals", "url":"/goals"}] } ]'
  else if "Last Physical Activity Counseling Procedure" is null then '[
    {"id": "physical-activity-counseling", "label": "Physical Activity Counseling", "type": "counseling-link", "references": {"system":"http://snomed.info/sct", "code":"304507003"}, "actions": [ {"label":"Learn more about physical activity.", "url":"/counseling/physical-activity"}]},
    {"id": "' + "Unique Goal Id"('physical-activity-goal-') + '", "type":"goal", "references":{"system":"https://coach.ohsu.edu", "code":"physical-activity", "display": "Physical Activity"}, "label": "Set a Physical Activity Goal", "actions": [{"label":"Exercise for [quantity] [time period:hours], [quantity] times per [time period]."}] }
  ]'
  else '[{ "id": "' + "Unique Goal Id"('physical-activity-goal-') + '", "type":"goal", "references":{"system":"https://coach.ohsu.edu", "code":"physical-activity", "display": "Physical Activity"}, "label": "Set a Physical Activity Goal", "actions": [{"label":"Exercise for [quantity] [time period:hours], [quantity] times per [time period]."}] } ]'

define "Physical Activity Links":
  '[
    {"label": "AHA: Getting Active to Control your High Blood Pressure", "url": "https://www.heart.org/en/health-topics/high-blood-pressure/changes-you-can-make-to-manage-high-blood-pressure/getting-active-to-control-high-blood-pressure"},
    {"label": "Health.gov: Current physical activity guidelines", "url": "https://health.gov/our-work/physical-activity/current-guidelines"},
    {"label": "CDC: Physical Activity Index", "url":"https://www.cdc.gov/physical-activity/php/about/"}
  ]'

define "Physical Activity Goal Summary":
    Combine("Goal Summary"("Physical Activity Goals"), '<br>')

define "Physical Activity Indicator Status":
  if exists "Physical Activity Goals Needing Update" then 'warning'
  else 'info'

/* Non-Pharmacologic Interventions Workflow */
define "Goals":
  (Common.QualifiedGoal(["Goal"])) Goal where Goal.lifecycleStatus = 'active'

// Look for custom tobacco goal coding
define "Tobacco Cessation Goals":
  "Goals" Goal
    where Goal.category.coding.code contains 'smoking-cessation'

// Return Goals past target date
define "Tobacco Cessation Goals Needing Update":
  ("Tobacco Cessation Goals") Goal
    where First(Goal.target).due.value same day or before Today()

// Smoking Observations less than 5 years old (Issue #113)
// For smoking, we check when the observation ends in case the practioner has documented the start date as when the patient started smoking
define "Smoking Status Observations":
  (Common.QualifiedObservation(Common."All Observations" A where Common.TransformCodeableConcept(A.code) in "Tobacco Smoking Status [Current] (Social History) (LOINC)")) SmokingObserved
  where Common."Normalize Interval"(SmokingObserved.effective) ends 60 months or less before Today()

// All observations indicating patient is a smoker
define "Observations Indicating Patient is a Smoker":
  "Smoking Status Observations" SmokingStatus
    where SmokingStatus.value as CodeableConcept in "Tobacco User"
      and singleton from (
        SmokingStatus.component C
          where FHIRHelpers.ToConcept(C.code) ~ "PACKS A DAY"
            and C.value is Quantity and Common.WithUnit(C.value, 'Packs/Day')
      ) is not null

define "Most Recent Observation of Patient Smoking Status":
  Last(
    "Smoking Status Observations" SmokingObserved
    sort by Coalesce(end of Common."Normalize Interval"(effective), issued)
  )

define "Patient is Currently a Smoker":
  "In Population" and "Observations Indicating Patient is a Smoker" contains "Most Recent Observation of Patient Smoking Status"

// Look for custom weight loss goal coding
define "Weight Loss Goals":
  "Goals" Goal
    where Goal.category.coding.code contains 'weight-loss'

// Return Goals past target date
define "Weight Loss Goals Needing Update":
  ("Weight Loss Goals") Goal
    where First(Goal.target).due.value same day or before Today()

// All BMI observations for previous 2 years (Issue #113)
define "Observations Specifying Patient BMI":
  (Common.QualifiedObservation(Common."All Observations" A where Common.TransformCodeableConcept(A.code) in "BMI Ratio")) BMIObserved
    where BMIObserved.value is Quantity
      and Common.WithUnit(BMIObserved.value, 'kg/m2') and
      Common."Normalize Interval"(BMIObserved.effective) starts 24 months or less before Today()

define "Most Recent Patient BMI":
  Last(
    "Observations Specifying Patient BMI" BMIObserved
    sort by Coalesce(end of Common."Normalize Interval"(effective), issued)
  )

define "Patient BMI is Greater than 25 kg/m2":
  "In Population" and "Most Recent Patient BMI".value >= 25.0 'kg/m2'

// Look for custom alcohol goal coding
define "Alcohol Goals":
  "Goals" Goal
    where Goal.category.coding.code contains 'alcohol-moderation'

// Return Goals past target date
define "Alcohol Goals Needing Update":
  ("Alcohol Goals") Goal
    where First(Goal.target).due.value same day or before Today()

// Get observations from the last 5 years reporting number of drinks per day (Issue #113)
// We check when the observation ends in case the practioner has documented the start date as when the patient started drinking that amount
define "Observations Measuring Amount of Alcoholic Drinks Patient has per Drinking Day":
  (Common.QualifiedObservation(Common."All Observations" A where Common.TransformCodeableConcept(A.code) in "Average Number of Drinks per Drinking Day")) DrinksPerDay
    where Common."Normalize Interval"(DrinksPerDay.effective) ends 60 months or less before Today() and
      DrinksPerDay.value is Quantity
      and Common.WithUnit(DrinksPerDay.value, 'Drinks/Day')

define "Most Recent Patient Drinking Observation":
  Last(
    "Observations Measuring Amount of Alcoholic Drinks Patient has per Drinking Day" DrinksPerDay
    sort by Coalesce(end of Common."Normalize Interval"(effective), issued)
  )

define "Heavy Daily Drinker":
  if Patient.gender = 'male' then 3.0
  else 2.0

// Get Conditions for Alcohol Abuse Disorder
define "Condition Indicating Alcohol Abuse Disorder":
  Common."Conditions" Problem
    where Problem.code in "Alcohol Abuse Disorder" and
    Common."Is Valid Prevalence Period"(Problem)

define "Patient is a Heavy Alcoholic Drinker":
  if not "In Population" then
    false
  else
    "Most Recent Patient Drinking Observation".value.value >= "Heavy Daily Drinker" or
      exists "Condition Indicating Alcohol Abuse Disorder"

define "Nutrition Goals":
  "Goals" Goal
    where Goal.category.coding.code contains 'nutrition'

define "Nutrition Goals Needing Update":
  ("Nutrition Goals") Goal
    where First(Goal.target).due.value same day or before Today()

define "Physical Activity Goals":
  "Goals" Goal
    where Goal.category.coding.code contains 'physical-activity'

define "Physical Activity Goals Needing Update":
  ("Physical Activity Goals") Goal
    where First(Goal.target).due.value same day or before Today()

/***** COUNSELING PROCEDURES *****/
// Get all procedures for subject since Epic does not support getting by code
define "Procedures":
  Common.QualifiedProcedure(["Procedure"])

define "Last Alcohol Counseling Procedure":
  "Last Counseling Procedure"("Procedures" Procedure
    where Procedure.code in "Alcohol Brief Intervention and Counseling")

define "Last Smoking Counseling Procedure":
  "Last Counseling Procedure"("Procedures" Procedure
    where Procedure.code in "Tobacco Use Cessation Counseling")

define "Last BMI Counseling Procedure":
  "Last Counseling Procedure"("Procedures" Procedure
    where Procedure.code in "Weight Reduction Recommendations" or Procedure.code in "BMI Follow Up Plan SNOMEDCT")

define "Last Nutrition Counseling Procedure":
  "Last Counseling Procedure"("Procedures" Procedure
    where Procedure.code in "Counseling for Nutrition")

define "Last Physical Activity Counseling Procedure":
  "Last Counseling Procedure"("Procedures" Procedure
    where Procedure.code in "Physical Activity Recommendations")

define "Needs Alcohol Counseling":
  "Patient is a Heavy Alcoholic Drinker" and not Common."Procedure Occurred In Last 2 Years"("Last Alcohol Counseling Procedure")

define "Needs Smoking Counseling":
  "Patient is Currently a Smoker" and not Common."Procedure Occurred In Last 2 Years"("Last Smoking Counseling Procedure")

/* Action Conditionals defined in Plan Definition */
define "Patient Smoking Goals Action Path":
  "Enter Workflow" and ("Patient is Currently a Smoker" or exists "Tobacco Cessation Goals")

define "Patient Weight Loss Goals Action Path":
  "Enter Workflow" and ("Patient BMI is Greater than 25 kg/m2" or exists "Weight Loss Goals")

define "Patient Alcohol Goals Action Path":
  "Enter Workflow" and ("Patient is a Heavy Alcoholic Drinker" or exists "Alcohol Goals")

define "Patient Nutrition Goals Action Path":
  "Enter Workflow"

define "Patient Physical Activity Goals Action Path":
  "Enter Workflow"

define "TEST Get Average All BP Last 2 Years":
  Common."Avg BP"(Common."Blood Pressure Observations for Last 2 Years")

define "TEST Get Average Most Recent BP Set":
  Common."Avg BP"(Common."Most Recent BP Set")

define "TEST Exclusion":
  Common."Patient Under Age 18"
ELM XML Content
Encoded data 
ELM JSON Content
Encoded data 
Generated using version 0.5.4 of the sample-content-ig Liquid templates