I've gone through your snippet and rewrote is to simplify it. Let me outline the steps I took.
Here is your original snippet:
{formtoggle: name=Search for a specific option or set of Colonoscopy descriptors:; trim=right}{descriptors=["-", "Positive FOBT and subsequent colonoscopy with no abnormalities detected - 32222 - once on a day", "Symptoms consistent with pathology of the colonic mucosa - 32222 - once on a day", "Iron deficiency or anaemia or IDA - 32222 - once on a day", "Abnormal diagnostic imaging of colon - 32222 - once on a day", "First colonoscopy following CRC surgery - 32222 - once on a day", "Pre-operative evaluation - 32222 - once on a day", "Repeat colonoscopy required due to inadequate bowel preparation for previous colonoscopy - 32222 - once on a day", "Management of IBD or inflammatory bowel disease - 32222 - once on a day", "Colonoscopy revealed 1 to 4 low-grade polyps - 32223 - only once in any 5 year period", "Colonoscopy revealed 1 to 4 adenomas each less than 10-mm in diameter and had no villous features or high grade dysplasia - 32223 - only once in any 5 year period", "Moderate risk of CRC due to family history with one FDR less than 55 at diagnosis - 32223 - only once in any 5 year period", "Moderate risk of CRC due to family history with two FDRs at any age at diagnosis - 32223 - only once in any 5 year period", "Moderate risk of CRC due to family history with one FDR and two SDRs at any age at diagnosis - 32223 - only once in any 5 year period", "History of CRC and initial post-op colonoscopy did not reveal any adenomas or CRC - 32223 - only once in any 5 year period", "Moderate risk of CRC due to a history of adenomas greater than 10-mm in diameter - 32224 - only once in any 3 year period", "Moderate risk of CRC due to a history of adenomas with villous features - 32224 - only once in any 3 year period", "Moderate risk of CRC due to a history of adenomas with high grade dysplasia - 32224 - only once in any 3 year period", "Moderate risk of CRC due to a history of 5 to 9 adenomas less than 10-mm in diameter with no villous features or high grade dysplasia - 32224 - only once in any 3 year period", "High risk of CRC due to a history of more than 10 adenomas - 32225 - not more than 4 times in any 12 month period", "High risk of CRC due to previous colonoscopy having a piecemeal or possibly incomplete excision of a large sessile polyp - 32225 - not more than 4 times in any 12 month period", "High risk for CRC due to known or suspected FAP - familial adenomatous polyposis - 32226 - only once in any 12 month period", "High risk for CRC due to known or suspected Lynch Syndrome - 32226 - only once in any 12 month period", "High risk for CRC due to known or suspected Serrated Polyposis Syndrome - 32226 - only once in any 12 month period", "Colonoscopic examination for the treatment of bleeding due to radiation proctitis - 32227 - once on a day", "Colonoscopic examination for the treatment of bleeding due to angioectasia - 32227 - once on a day", "Colonoscopic examination for the treatment of post-polypectomy bleeding - 32227 - once on a day", "Colonoscopic examination for the treatment of colonic strictures with balloon dilatation - 32227 - once on a day", "Colonoscopy other than above indications - 32228 - only once", "Polypectomy - 32229"]; trim=yes} {note} {formtext: name=search; trim=left} {endnote: trim=left}
List of Colonoscopy descriptors that match the search - {current_descriptors=filter(descriptors, x -> trim(search) == "" or count(split(lower(x), lower(search)))>1)}{formmenu: values={=current_descriptors}; trim=left} {endformtoggle: trim=left}
{formtoggle: name=Display Colonoscopy descriptor / Item No. / Recall Period: ; trim=right} {note}{descriptor_to_item=["Positive FOBT and subsequent colonoscopy with no abnormalities detected":"32222", "Symptoms consistent with colonic pathology":"32222", "Iron deficiency or anaemia or IDA":"32222", "Abnormal diagnostic imaging of colon":"32222", "First colonoscopy following CRC surgery":"32222", "Pre-operative evaluation":"32222", "Repeat colonoscopy required due to inadequate bowel preparation":"32222", "Management of IBD or inflammatory bowel disease":"32222", "Colonoscopy revealed 1 to 4 low-grade polyps":"32223", "Colonoscopy revealed 1 to 4 adenomas less than 10-mm with no villous features or high grade dysplasia":"32223", "Moderate risk of CRC due to family history with one FDR less than 55":"32223", "Moderate risk of CRC due to family history with two FDRs at any age":"32223", "Moderate risk of CRC due to family history with one FDR and two SDRs at any age":"32223", "History of CRC and post-op colonoscopy did not reveal any adenomas or CRC":"32223", "Moderate risk of CRC due to a history of adenomas greater than 10-mm":"32224", "Moderate risk of CRC due to a history of adenomas with villous features":"32224", "Moderate risk of CRC due to a history of adenomas with high grade dysplasia":"32224", "Moderate risk of CRC due to a history of 5 to 9 adenomas less than 10-mm with no villous features or high grade dysplasia":"32224", "High risk of CRC due to a history of more than 10 adenomas":"32225", "High risk of CRC due to having a piecemeal or incomplete excision of a large sessile polyp":"32225", "High risk for CRC due to known or suspected FAP - familial adenomatous polyposis":"32226", "High risk for CRC due to known or suspected Lynch Syndrome":"32226", "High risk for CRC due to known or suspected Serrated Polyposis Syndrome":"32226", "Colonoscopy for the treatment of bleeding due to radiation proctitis":"32227", "Colonoscopy for the treatment of bleeding due to angioectasia":"32227", "Colonoscopy for the treatment of post-polypectomy bleeding":"32227", "Colonoscopy for the treatment of colonic strictures with balloon dilatation":"32227", "Colonoscopy other than above indications":"32228", "Polypectomy":"32229"]} {item_to_recall=["32222":"Once on a day", "32223":"Only once in any 5-year period", "32224":" Only once in any 3-year period ", "32225":"Not more than 4 times in any 12-month period ", "32226":"Only once in any 12-month period ", "32227":"Once on a day", "32228":"Only once ", "32229":"-"]}
Select Colonoscopy Descriptor: {formmenu: Positive FOBT and subsequent colonoscopy with no abnormalities detected; Symptoms consistent with colonic pathology; Iron deficiency or anaemia or IDA; Abnormal diagnostic imaging of colon; First colonoscopy following CRC surgery; Pre-operative evaluation; Repeat colonoscopy required due to inadequate bowel preparation; Management of IBD or inflammatory bowel disease; Colonoscopy revealed 1 to 4 low-grade polyps; Colonoscopy revealed 1 to 4 adenomas less than 10-mm with no villous features or high grade dysplasia; Moderate risk of CRC due to family history with one FDR less than 55; Moderate risk of CRC due to family history with two FDRs at any age; Moderate risk of CRC due to family history with one FDR and two SDRs at any age; History of CRC and post-op colonoscopy did not reveal any adenomas or CRC; Moderate risk of CRC due to a history of adenomas greater than 10-mm; Moderate risk of CRC due to a history of adenomas with villous features; Moderate risk of CRC due to a history of adenomas with high grade dysplasia; Moderate risk of CRC due to a history of 5 to 9 adenomas less than 10-mm with no villous features or high grade dysplasia; High risk of CRC due to a history of more than 10 adenomas; High risk of CRC due to having a piecemeal or incomplete excision of a large sessile polyp; High risk for CRC due to known or suspected FAP - familial adenomatous polyposis; High risk for CRC due to known or suspected Lynch Syndrome; High risk for CRC due to known or suspected Serrated Polyposis Syndrome; Colonoscopy for the treatment of bleeding due to radiation proctitis; Colonoscopy for the treatment of bleeding due to angioectasia; Colonoscopy for the treatment of post-polypectomy bleeding; Colonoscopy for the treatment of colonic strictures with balloon dilatation; Colonoscopy other than above indications; Polypectomy; name=descriptor; trim=left}{endnote: trim=left}
Descriptor: {=descriptor}
Number: {=descriptor_to_item[descriptor]}
Recall Period: {=item_to_recall[descriptor_to_item[descriptor]]}{endformtoggle: trim=left}
I made the following changes:
-
Removed the duplication of the descriptor list: In the original version you repeat the list of descriptors three times. This would make the snippet difficult to maintain as you have to update all three places with the exact right string every time you make a change. I consolidate this to a single list.
-
Removed the duplication of the descriptor select menu: I have removed the select menu in the optional "searching" toggle. I don't believe it is needed as people can select from the second select menu.
-
Removed some unnecessary attributes E.g. there were a lot of trims that weren't really necessary
-
Reformatted the named lists I reformatted the named lists to make them easier to read and edit. This doesn't change the behavior at all, but makes the snippet a lot easier to understand and edit.
My reworked version is below. Hope this helps!
{descriptor_to_item=[
"Positive FOBT and subsequent colonoscopy with no abnormalities detected":"32222",
"Symptoms consistent with colonic pathology":"32222",
"Iron deficiency or anaemia or IDA":"32222",
"Abnormal diagnostic imaging of colon":"32222",
"First colonoscopy following CRC surgery":"32222",
"Pre-operative evaluation":"32222",
"Repeat colonoscopy required due to inadequate bowel preparation":"32222",
"Management of IBD or inflammatory bowel disease":"32222",
"Colonoscopy revealed 1 to 4 low-grade polyps":"32223",
"Colonoscopy revealed 1 to 4 adenomas less than 10-mm with no villous features or high grade dysplasia":"32223",
"Moderate risk of CRC due to family history with one FDR less than 55":"32223",
"Moderate risk of CRC due to family history with two FDRs at any age":"32223",
"Moderate risk of CRC due to family history with one FDR and two SDRs at any age":"32223",
"History of CRC and post-op colonoscopy did not reveal any adenomas or CRC":"32223",
"Moderate risk of CRC due to a history of adenomas greater than 10-mm":"32224",
"Moderate risk of CRC due to a history of adenomas with villous features":"32224",
"Moderate risk of CRC due to a history of adenomas with high grade dysplasia":"32224",
"Moderate risk of CRC due to a history of 5 to 9 adenomas less than 10-mm with no villous features or high grade dysplasia":"32224",
"High risk of CRC due to a history of more than 10 adenomas":"32225",
"High risk of CRC due to having a piecemeal or incomplete excision of a large sessile polyp":"32225",
"High risk for CRC due to known or suspected FAP - familial adenomatous polyposis":"32226",
"High risk for CRC due to known or suspected Lynch Syndrome":"32226",
"High risk for CRC due to known or suspected Serrated Polyposis Syndrome":"32226",
"Colonoscopy for the treatment of bleeding due to radiation proctitis":"32227",
"Colonoscopy for the treatment of bleeding due to angioectasia":"32227",
"Colonoscopy for the treatment of post-polypectomy bleeding":"32227",
"Colonoscopy for the treatment of colonic strictures with balloon dilatation":"32227",
"Colonoscopy other than above indications":"32228",
"Polypectomy":"32229"
]}
{item_to_recall=[
"32222":"Once on a day",
"32223":"Only once in any 5-year period",
"32224":" Only once in any 3-year period ",
"32225":"Not more than 4 times in any 12-month period ",
"32226":"Only once in any 12-month period ",
"32227":"Once on a day",
"32228":"Only once ",
"32229":"-"
]; trim=yes}
{descriptors=keys(descriptor_to_item); trim=yes}
{current_descriptors=descriptors; trim=yes}
{note}
{formtoggle: name=Search for a specific option or set of Colonoscopy descriptors:} {formtext: name=search; trim=left} {current_descriptors=filter(descriptors, x -> trim(search) == "" or count(split(lower(x), lower(search)))>1)} {endformtoggle}
Select Colonoscopy Descriptor: {formmenu: values={=current_descriptors}; name=descriptor}
{endnote: trim=right}
Descriptor: {=descriptor}
Number: {=descriptor_to_item[descriptor]}
Recall Period: {=item_to_recall[descriptor_to_item[descriptor]]}