How do l schedule messages based on the value?

  • l am using Medic Collect to collect data. So the user select one value from the two names viz.
  1. HT
  2. DM
  • Ther are about 40 different scheduled messages for both HT and DM respectively, stored in the JSON.
    l have successfuly managed to schedule the mesages and it works.
    QUESTION: How do l make the system automatically pick the scheduled messages based on the user input value during patient registration, for example: If a user enters HT on the Medic Collect the system schedule the HT messages for the HT patient…on the other hand, If a user selects DM on the Medic Collect the system schedule the DM messages for the DM patient.
1 Like

The app_settings.json for your instance controls this in the .schedules and the .registrations keys.

In registrations you can set a javascript expression in the bool_expr field to check if a report has a specific value. Without knowing the field names on your reports I’m just providing a generic example.

"registrations" {
      "form": "YOUR_FORM",
      "events": [
        {
          "name": "on_create",
          "trigger": "assign_schedule",
          "params": "nick_test",
         "bool_expr": "doc.fields.name_choice === 'HT'"   
        },
}

Then in the schedules array you need an object that matches the name sent in the params above.

"schedules": [
    {
      "name": "nick_test",
      "translation_key": "TEST!",
      "summary": "",
      "description": "",
      "start_from": "reported_date",
      "messages": [
        {
          "translation_key": "This is a test",
          "group": 1,
          "offset": "7 days",
          "send_day": "",
          "send_time": "",
          "recipient": "clinic"
        }
      ]
    },
}

Here’s the documentation for registrations and for scheduleshttps://docs.communityhealthtoolkit.org/apps/reference/app-settings/schedules/

2 Likes

Thank you. On the schedules, l have two groups of messages, basing on your example say: nick_test_one and nick_test_two. Is it possible to embed nick_test_one and nick_test_two on the schedules array or should l separate them? e.g
“schedules”: [
{
“name”: “nick_test_one”,
“translation_key”: “TEST_ONE”,
“summary”: “”,
“description”: “”,
“start_from”: “reported_date”,
“messages”: [
{
“translation_key”: “This is a test one”,
“group”: 1,
“offset”: “7 days”,
“send_day”: “”,
“send_time”: “”,
“recipient”: “clinic”
}
]
},
{
“name”: “nick_test_two”,
“translation_key”: “TEST_TWO”,
“summary”: “”,
“description”: “”,
“start_from”: “reported_date”,
“messages”: [
{
“translation_key”: “This is a test two”,
“group”: 1,
“offset”: “7 days”,
“send_day”: “”,
“send_time”: “”,
“recipient”: “clinic”
}
]
},
}

The schedules array should be where all your schedules(messages) should be defined. I’m not sure I understand exactly what you are asking. Our standard config app_settings has a variety of schedules configured. Let me know if this answers your question.

@Nick in the words is it wise to have two different schedules?

“schedules”: [
{
“name”: “nick_test_one”,
“translation_key”: “TEST_ONE”,
“summary”: “”,
“description”: “”,
“start_from”: “reported_date”,
“messages”: [
{
“translation_key”: “This is a test one”,
“group”: 1,
“offset”: “7 days”,
“send_day”: “”,
“send_time”: “”,
“recipient”: “clinic”
}
]
},

AND
“schedules”: [
{
“name”: “nick_test_two”,
“translation_key”: “TEST_TWO”,
“summary”: “”,
“description”: “”,
“start_from”: “reported_date”,
“messages”: [
{
“translation_key”: “This is a test two”,
“group”: 1,
“offset”: “7 days”,
“send_day”: “”,
“send_time”: “”,
“recipient”: “clinic”
}
]
}

NB: The “name”: are different

I see what you mean now. It really depends on your needs. If the config for the schedules and associated messages are the same for your flows then it would make sense to only use one. However, if your flows are different, you would want to have multiple entries in the schedules array.

In our standard config we have schedules for different types of care based on what was submitted. The messages are going to be on different times, some have multiple messages being sent, others only send one. Some send to different recipients.

Since you have a conditional need based on the HT or DM value. I would assume that you’ll likely need two schedules. You would create 1 registration that has multiple events with the on_create name and the assign_schedule trigger. Each event would have bool_expr that conditions on the value(HT or DM) then assigns the schedule to your report. Which then you wouldn’t have all 40 messages you have defined you would get the subset in the schedule.

1 Like