Command to add elements to a list

Is there a command to add elements to a list?
For example, I would like to add "item f" to {list=["item a", "item b", "item c", "item d", "item e"]}.
I assume this is not explained on the reference page?

Hi @Naritatsu_Saito,
Can you please tell me what you are trying to do?

@VinodGubbala Thank you for your reply, I am a general practitioner in Japan and I am trying to create a medical aid tool using TB. I am planning to keep a list of patients' risk factors, e.g. hypertension, hypercholesterolemia, diabetes, etc., and I want to change the list dynamically.
So I am looking for a command to add elements to the list.

Can you give me an example of this? If you can share the snippet, it would be helpful and fast.
Please redact the information which is sensitive.

Are you looking for {formmenu}?

{formmenu: hypertension; hypercholesterolemia; diabetes; multiple=yes; name=results}
Patient symptoms: {=join(results, "BLAZE_AND")}

Thanks, but no. Is there a command to add elements to a list, like append in python?

One way to do it is to use merge function. Example:

{list=["a", "b"]}
List {=list}
{newlist=merge(list, ["c"])}
New list {=newlist}

Note: you can not re-assign newlist back to list as it would create recursive formula assignment.

Thank you for your prompt reply, understood. I see that I have to redefine the list anew, and that the same list name cannot be used. It seems a bit difficult to use, and I look forward to future improvements. Thank you.

Hi, can you please share the snippet example that you are trying to achieve? We need to understand the use case completely.

Thanks for your kind help. I haven't been able to create snippet yet, so I'll explain in writing.

I am thinking of snipets that automatically generate documents to explain to patients based on the Japanese guidelines for the treatment of hypertension. According to the guidelines, the antihypertensive target is 125/75 mmHg for home blood pressure if the patient is elderly (over 75 years), has diabetes, chronic kidney disease, cerebrovascular disease or coronary artery disease, and 135/75 mmHg if none of these conditions apply.

The following snippet are considered.

  1. Check the above risk factors using the multiple choice checkbox
  2. Create an explanation for the patient based on this (if the checkbox is empty, a sentence like "You do not have any risk factors, so--" is generated).

To achieve this, I wanted to make the check box a list that changes dynamically.

Well, this could be implemented without using a list, but as the complexity of such a guideline-based treatment recommendation programme increases, I thought it would be more convenient to be able to dynamically change the contents of the list.

Are you trying something like this?

I used toggle

{risks=[["name": "Risk 1", "selected": risk1],["name": "Risk 2", "selected": risk2],["name": "Risk 3", "selected": risk3]]}
{formtoggle: name=risk1}{endformtoggle}
{formtoggle: name=risk2}{endformtoggle}
{formtoggle: name=risk3}{endformtoggle}
{selectedRisks=filter(risks, (risk) -> risk.selected)}
Here are some risks {=join(map(selectedRisks, (risk) ->, "BLAZE_AND")}
You do not have any risk factors

But I strongly recommend you to use formmenu for this

{risks=[["name": "Risk 1"],["name": "Risk 2"],["name": "Risk 3"]]}
{formmenu: values={=risks}; itemformatter=(risk) ->; multiple=yes; name=selectedRisks}
Here are some risks {=join(map(selectedRisks, (risk) ->, "BLAZE_AND")}
You do not have any risk factors

1 Like

@VinodGubbala Thank you, this is exactly what I wanted to do, I will study the TB commands further.

I'm so glad I could be of assistance! Please don't hesitate to reach out if you have any more questions. We're always here to help.