How to get age from input date of birth

How would I calculate a person's age (at end of calendar year) based on form-inputted date of birth?

Thank you.

If you just needed the age in years, you could do something like:

Year of birth: {formtext: name=born; default=1980}
Age at end of the current year: {={time: YYYY} - born}

Is that what you were looking for?

Perfect, thanks.

From a calculated age can one set a task, for example if age < 55 "to have stool test", if age between 55-75(inclusive) "to have colonoscopy" but if > 75 "to have CT scan virtual colography"

AND THEN

If eligible "to have colonscopy" and "NOT Diabetic" then "proceed to colonoscopy" but if "Diabetic" requires "CONSULTATION PREPROCEDURE"

Absolutely, evolving from the above example:

Year of birth: {formtext: name=born; default=1980} {age={time: YYYY} - born}

Age at end of the current year: {=age}

{if: age < 55}
Have a stool test
{elseif: age <= 75}

Diabetic: {formmenu: name=diabetic; yes; no}
{if: diabetic == "yes"}
Consultation preprocedure
{else}
Proceed to colonscopy
{endif}

{else}
Have a CT scan
{endif}

So far so good. I was wondering if Text Blaze cane take it one step further:
My Snippet so far looks like this: (https://dashboard.blaze.today/snippet/NhgWY6oNkmT4ROdYuvdw)

Year of birth: { formmenu: name=year_born; 1930; 1931; 1932; 1934; 1935; 1936; 1937; 1938; 1939; 1940; 1941; 1942; 1944; 1945; 1946; 1947; 1948; 1949; 1950; 1951; 1952; 1954; 1955; 1956; 1957; 1958; 1959; 1960; 1961; 1962; 1964; 1965; 1966; 1967; 1968; 1969; 1970; 1971; 1972; 1974; 1975; 1976; 1977; 1978; 1979; 1980; 1981; 1982; 1984; 1985; 1986; 1987; 1988; 1989; 1990; 1991; 1992; 1994; 1995; 1996; 1997; 1998; 1999; 2000; 2001; 2002; 2003; 2004; 2005 } { age={time: YYYY} - year_born } Age at end of the current year: { =age }

{ if: age < 76 } Patient Diabetic Status: { formmenu: name=diabetic_status; - Select -; Not Diabetic; Diabetic }

{ if: diabetic_status==="Not Diabetic" } Blood Thinners: { formmenu: name=coag_status; - Select -; No Blood Thinners; Blood Thinners Taken }

{ if: coag_status==="Blood Thinners Taken" } Reason for Blood Thinners: { formmenu: name=coag_reason; - Select -; No recognised clinical indication for taking this treatment; Heart disease with coronary artery stents inserted over 12 months ago; Heart disease with coronary artery stents inserted within 12 months; Uncomplicated AF (atrial fibrillation) with no other associated heart disease; AF (atrial fibrillation) PLUS heart valve replacement; DVT or pulmonary emboli within 6 months; DVT or pulmonary emboli more than 6 months ago; Stroke within 12 months; Stroke more than 12 months ago; Severe Peripheral Vascular Disease with Stents; Bleeding Disorder } { elseif: coag_status==="No Blood Thinners" } { elseif: diabetic_status==="Diabetic" } { elseif: age >= 76 } { endif } { endif } { endif }

What I would like to be able to do is proceed to Section B - but only if

  1. age < 76 & diabetic_status = "Not Diabetic" & coag_status = "No Blood Thinners" => Proceed to Section B

OR

  1. age < 76 & diabetic_status = "Not Diabetic" & coag_status = "Blood Thinners" BUT only for certain coag_reason = "No recognised clinical indication for taking this treatment" or "Heart disease with coronary artery stents inserted over 12 months ago" or "Uncomplicated AF (atrial fibrillation) with no other associated heart disease" or "DVT or pulmonary emboli more than 6 months ago" or "Stroke more than 12 months ago" => Proceed to Section B

IF

  1. age >= 76 => do not proceed to Section B but must have a Clinical review
    or
  2. diabetic_status = "Diabetic" => do not proceed to Section B but must have a Clinical review
    or
  3. coag_reason = "Heart disease with coronary artery stents inserted within 12 months" or "AF (atrial fibrillation) PLUS heart valve replacement" or "DVT or pulmonary emboli within 6 months" or "Stroke within 12 months" or "Severe Peripheral Vascular Disease with Stents" or "Bleeding Disorder"

Was wandering if I should split the coag_reason into 2 groups high_risk & low_risk and then try?
Sorry if too complicated

So any sort of logic like you outline is completely doable in Text Blaze. You just have to combine the relevant boolean statements.

Some notes, you can certainly write:

(coag_reason == "No recognised clinical indication for taking this treatment" or coag_reason == "Heart disease with coronary artery stents inserted over 12 months ago" or coag_reason == "Uncomplicated AF (atrial fibrillation) with no other associated heart disease")

However, it might be easier to write it like this:

includes(["No recognised clinical indication for taking this treatment", "Heart disease with coronary artery stents inserted over 12 months ago", "Uncomplicated AF (atrial fibrillation) with no other associated heart disease"], coag_reason)

The includes function will allow you to test if the coag_reason matches one item in the list.

One concern with this overall approach though is you have to repeat long pieces of text multiple places. You have to put "No recognised clinical indication for taking this treatment" both in the {formmenu} and the {if} command. This is verbose and has a chance to introduce bugs if you change one of the two places but forget to change the other.

It may make sense to define variables for each of the special strings so you can reuse them.

I wonder if it would be helpful to do an online session or video where we walk through some of these possibilities on real world applications like this to teach the different tricks and best practices. What do you think?

Hi Scott an online session would be greatly appreciated.

Primarily because I still cannot understand the correct function or application of certain "operators" such as the difference between == and ===; or when or how to use [....] and how it differs from {...}

Although I understand the concept of your last statement "It may make sense to define variables for each of the special strings so you can reuse them" - I don't now how to put it in practice. Maybe an example.

How do I use the includes function? Not sure if there is an if operator in front of it?
includes(["No recognised clinical indication for taking this treatment", "Heart disease with coronary artery stents inserted over 12 months ago", "Uncomplicated AF (atrial fibrillation) with no other associated heart disease"], coag_reason)

Where can I see examples of the "includes" function?

Great, let's schedule something for this week. We can do the two of us to dig into this, but make it an open meeting if anyone else wants to join to learn or ask other questions.

How does this Friday the 22nd at 11AM GMT work for you?

We don't have any examples of includes in the docs, but here are some:

see if "a" is in a list:
{=includes(["a", "b", "c"], "a")}

see if "x" is in a list:
{=includes(["a", "b", "c"], "x")}

That would be great Scott.

Just to recheck 11am GMT = 9pm Sydney time (Australia Eastern Time = GMT +10)

Do you want me to send you a Zoom invite?

Yes, I believe that is correct. We can use Google Meet.

To recap:

May 22nd @ 11AM GMT
Meeting link: https://meet.google.com/pkk-qtwf-dfq

I'll post a message to the forum overall to see if anyone else wants to join.

:+1:
I'll do the same here.

Ok I can now see the action of the includes operator; it is then next step (ie its utility I have a problem with.

Lets say if the answer is yes, then I want outcome "go to section B" if answer is no then "go to section C" and then if "go to section B" -> do "x" or "y" or "z" if "go to section C" -> do "1" or "2" or "3"

We can dig into this more Friday, but basically you can use {if} commands to reveal or hide sections based on the user selection.

For example:

Section A

What is your favorite color: {formmenu: red; blue; green; name=color}

{if: includes(["red", "blue"], color)}
Section B (for people who chose red or blue)

What is you favorite shape: {formmenu: circles; triangles}
{elseif: color == "green"}
Section C (for people who choose green)

What is your favorite vacation: {formmenu: beach; mountains; stay home; name=vacation}

{if: vacation=="beach"}
One last question.

Do you prefer: {formmenu: lake beaches; ocean beaches}
{endif}
{endif}

Is that the type of thing you were looking for?