Closed joshid-ims closed 2 years ago
This is more complicated that I thought. Because this is in a loop things are a little uglier. I'm going to need input from the DS team.
@joshid-ims you can do this (I know in displayif, not sure about just displaying). This function was not designed to be used by the questionnaire developers, but maybe it's ok. (_value(year1)-_value(year2))*12 - (_value(month1)-_value(month2))
Pete tested it and replied:
Hi Deepti,
I can’t get the equation Daniel provided to work in a ‘max=’ statement.
For addition, we have sum(x,y). For subtraction, we have difference(x,y). Can you just ask Daniel if there are equivalent functions in quest for multiplication and division? I’ve tried using product(x,y), multiply(x,y), quotient(x,y), and divide(x,y) in the renderer, but these don’t work.
Thanks, Pete
@joshid-ims and Pete below is an example of how you can use the simple multiplication with max. It also works with displayif. It will not work with displaying a value. (+, -, *, /) should work.
Remember: you must start the expression with a "new" function in this case _value or valueOrDefault
[Q1] How old are you today? |__|__| (in years)
[Q2] How old do you think you'll be when you make your first million, if you already have, enter that date.
You have until twice your current age of {$Q1} |__|__|min=1 max=_value("Q1")*2|
Be careful how you use this, _value() was not really designed to be used by the questionnaire developer. Think about what happens if Q1 is not defined. You may wand to consider using valueOrDefault
[Q2] How old do you think you'll be when you make your first million, if you already have, enter that date.
You have until twice your current age of {$Q1} |__|__|min=1 max=valueOrDefault('Q1',24)/2-1|
Pete tried the way Daniel said. It gives syntax error. He wants to code following equation but not sure how to.
max = (#currentYear – [SRVBLU_COV3_V1R0_1_YEAR])*12 + (#currentMonth – [SRVBLU_COV3_V1R0_1_MONTH])
It took a little longer than expected.... BTW: you no longer have to start with new function, but you CANNOT mix them!
[Q1] How old are you today? |__|__| (in years)
[Q2] How old do you think you'll be when you make your first million, if you already have, enter that date.
|__|__|max=(#currentYear - _value('Q1'))*12 + (#currentMonth - _value('Q1'))|
For mathematical functions:
The question involved is https://github.com/episphere/quest/issues/43 (see below) in the biospecimen questionnaire. For the text box # months, Julie wants the max to be the # months between the Month/Year from response to https://github.com/episphere/quest/issues/18 (When was the 1st time that you had COVID-19) to current Month/Year.
[SrvBlU_COV22v1r0] How long did it take you to recover to your usual state of health from the date you first realized you had COVID-19? months days
We were thinking of calculating the number of months in between using formula {(year1-year2)X12} + (month1-month2).
Please let us know if there is a better way to implement this.
Daniel mentioned this already exists but we do not know how to.