Health plan prescriptions email plan-prescription

On this page: Follow a personalization use case that iterates over nested profile arrays with conditional rules to build a health plan email listing prescriptions that are ready for pickup or recalled.

A profile contains health plans, and each plan includes prescriptions. Prescriptions have various states, such as “ready,” “recall,” or “picked up”.

In this use case, we want to send a single email to each profile, including all prescriptions that are either ready for pick up or recalled. Click on each tab below for more information on the syntax to use to implement this use case.

Rendered Message

Hi John Doe,

Here are the prescriptions that are either ready for pick up or have been recalled:

Health Plan A

  • Prescription ID: pres1
    Name: Medication A
    State: ready
  • Prescription ID: pres2
    Name: Medication B
    State: recall

Health Plan B

  • Prescription ID: pres4
    Name: Medication D
    State: ready
HTML Template
code language-html
<p>Hi {{profile.person.firstName}} {{profile.person.lastName}},</p>
<p>Here are the prescriptions that are either ready for pick up or have been recalled:</p>
{{#each profile.plans as |plan|}}
<h3>{{plan.name}}</h3>
<ul>
   {{#each plan.prescriptions as |prescription|}}
   {%#if prescription.state = "ready" or prescription.state = "recall"%}
   <li>
      <strong>Prescription ID:</strong> {{prescription.prescription_id}}<br>
      <strong>Name:</strong> {{prescription.name}}<br>
      <strong>State:</strong> {{prescription.state}}
   </li>
   {%/if%}
   {{/each}}
</ul>
{{/each}}
Profile Data
code language-javascript
{
  "profile": {
    "person": {
      "firstName": "John",
      "lastName": "Doe"
    },
    "plans": [
      {
        "planId": "plan1",
        "name": "Health Plan A",
        "prescriptions": [
          {
            "prescription_id": "pres1",
            "name": "Medication A",
            "state": "ready"
          },
          {
            "prescription_id": "pres2",
            "name": "Medication B",
            "state": "recall"
          }
        ]
      },
      {
        "planId": "plan2",
        "name": "Health Plan B",
        "prescriptions": [
          {
            "prescription_id": "pres3",
            "name": "Medication C",
            "state": "picked up"
          },
          {
            "prescription_id": "pres4",
            "name": "Medication D",
            "state": "ready"
          }
        ]
      }
    ]
  }
}
recommendation-more-help
journey-optimizer-help