Is it possible to create a REDCap question that autofills based on previous answers? - redcap

I am working on a research project and I have an eligibility screener. I'd like to have a question at the end that is hidden from participants that shows "eligible - yes or no?" and autofills based on their questions to previous answers. Is this possible; if so, how could I set this up?

You would set this field up as a calculated field, hiding it as necessary, and build the arithmetic from your inclusion/exclusion criteria such that it returns 1 for eligible and 0 for ineligible. You can then use this 'eligible' value for later conditional logic, branching logic, automated survey invitations, and so on.
For example, say your eligibility requirements were that the participant is 18 years or older, does not have type-1 diabetes, and has a BMI greater than 30. Your calculated field would be something like:
if([age] >= 18 and [t1_diabetes] = '0' and [bmi] > 30, 1, 0)

Related

Prevent data entry if inclusion criteria not met

I'd like to know how to prevent REDCap to let the operator enter data if inclusion criteria ( in a clinical trial or EHR study are not met ?
Are there a sort of branching logic or anything else ?
for instance, there are 3 yes now questions, if all are yes, then the next instrument could be filled , if not all conditions are met, show a message ( that not all criteria are met) and prevent data entry.
You would typically show a warning to the operator that the subject is excluded due to some factor, with a descriptive text field with branching logic (where 0 encodes 'no'): [q1] = 0 or [q2] = 0 or [q3] = 0.
There is also an external module called Form Render Skip Logic (FRSL) that allows you to define the logic controlling the flow between forms (whereas functions like survey queue do not work for forms), and thus only proceed to the next form if [q1] = 1 and [q2] = 1 and [q3] = 1. Although you will need to contact your site administrators to install this/enable for your project.

Is there a way to filter and return results for the unique of one column, with conditions of another?

Question
For the data below, is there a way to return results —for each order in col B— either:
If the most recent status [col D] for an order (ex. for order 10021) is closed, then return that row.
If not, return every row since the most recent closed status for that order (ex. for order 10020, rows 4 and 5).
Previous efforts and attempted solutions
Previously, I was only returning one result, the most recent status for each order with the following:
=SORTN(SORT(A2:D,1,FALSE),9^9,2,2,FALSE)
However, I would like if orders can have more than one current status.
I've tried a few things, and was able to achieve what I'm looking for, unfortunately only if there is one order, with the following:
(The linked sheet below explains how I got to this)
=IFERROR(FILTER(A2:D5,A2:A5>INDEX(SORT(FILTER(A2:D5,D2:D5="CLOSED"),1,0),1,1)),FILTER(A2:D5,A2:A5>=INDEX(SORT(FILTER(A2:D5,D2:D5="CLOSED"),1,0),1,1)))
The other alternative I can think of is a script with a loop.
Summary
It was difficult to know how to title this question but came to it since essentially we're trying to filter for the unique of col B, with conditions against col A & D.
Here's a link to a sample Google spreadsheet you can edit, showing all the attempts.
All your help and comments are greatly appreciated!
maybe like this:
=ARRAYFORMULA(UNIQUE(SORT({VLOOKUP(UNIQUE(INDIRECT("B2:B"&COUNTA(B2:B)+1)),
SORT({B2:B, TO_TEXT(A2:D)}, 2, 0), {2, 3, 4, 5}, 0);
FILTER(A2:D, D2:D="RETURN")},1,1)))
Solution
All credit to Matt King who found a complete answer.
=ARRAYFORMULA(QUERY({A:D,(COUNTIFS(C:C,C:C,A:A,">="&A:A)=1)*(D:D="CLOSED")
+NOT(REGEXMATCH(TRIM(TRANSPOSE(QUERY(IF((TRANSPOSE(A:A)<=A:A)*(TRANSPOSE(C:C)=C:C),D:D,)
,,9^99))),"CLOSED"))},"select Col1,Col2,Col3,Col4 where Col5=1"))
Essentially,
First assigning a count to each row for any given order
Transpose and combine statuses
If there is a CLOSED status in there, don't use it
Then filter with query language
Resulting in—
See solution here.
Mod
I added a clause to completely exclude the status NOTE from current records—
=ARRAYFORMULA(QUERY({A:D,(COUNTIFS(B:B,B:B,A:A,">="&A:A)=1)*(D:D="CLOSED")+
(ARRAYFORMULA(IF((ARRAYFORMULA(NOT(REGEXMATCH(TRIM(TRANSPOSE(QUERY
(IF((TRANSPOSE(A:A)<=A:A)*(TRANSPOSE(B:B)=B:B),D:D,),,9^99))),"CLOSED"))))
=TRUE,IF((ARRAYFORMULA(NOT(TRANSPOSE(ARRAYFORMULA(TRANSPOSE(D:D)))="NOTE")))
=FALSE,FALSE,TRUE),FALSE)))},"select Col1,Col2,Col3,Col4 where Col5=1"))
Implementation
This was sample tested against 2500 rows of data, and took over 80 seconds to execute. So although this answers the question, it isn't necessarily a viable solution.

AMPL Syntax Error - Greater than or equal to issue

I am modeling a sort of schedule optimization problem in AMPL and am using gurobi for the option solver.
In this problem, I have declared a set of schedules from 1 through 1000, and called this set "Schedules".
Each schedule sas a sort of layer (a parameter called "layer" has been created) with a value ranging from 1 to 4. This is a sort of preference or hirearchy of the days off that this particular schedule has.
I want several constraints that determine how many schedules of each preference are available. For instance, I want at least 170 of the schedules to have a preference layer of 1. I wrote the following line to do so:
subject to Preference1: sum {j in Schedules: layer[j]=1} >= L1Demand;
Where L1Demand is set to 170. However, when I go to include the model file in the ampl window, I get the following error:
syntax error
context:
subject to Preference1: sum {j in Schedules: layer[j]=1} >>> >= <<< L1Demand;
I don't understand why this is throwing out a syntax error. I may be missing something very basic or obvious, but can anyone tell me as to why this would be happening? Thank you very much.
You should specify an argument for sum, for example:
sum {j in Schedules: layer[j]=1} x[j]
where x is some variable indexed over Schedules.

Joomla K2 content sort by number of votes

I'm using Joomla 2.5 and K2 2.5.7. I have a category with posts with a different number of votes. In the front end, I need to sort the items of this category by number of votes.
I re-configured standard stars rating systems to simple "Give one vote" system.
I need this for a ranking order page, so it will have items with the largest number of votes on the top.
What I have
I have my MVC template for K2 category. I was wondering, if sorting $this->leading in category.php is the right to go for.
If it is, how can I do it? With var_dump there is variable numOfVotes which carry real number of votes. How can I sort this object by this var?
Thank you very much!
This K2 forum post seems to answer your question. You need to use the mod_content k2 module and use the "sort by" parameter and select highest rating.
If you go to 'modules/mod_k2_content/helper.php' in the ftp, you'll see on line 98, that there it says
$query .= ", (r.rating_sum/r.rating_count) AS rating";
This sorts the data by the highest rating. Now generally this would sort it by the number of votes divided by the number of people who have voted giving a result between 1 and 5. However as everyone in your case gets a vote of 5 - then your average result will always be 5 by that calculation!, I think that you'll have to replace that line with:
$query .= ", r.rating_count AS rating";
i.e. just sorting by the number of people who have voted (N.B. This assumes you're not using a vote down system as well! You haven't mentioned it so I'm assuming not)
Then you should just be able to use the module (selecting the parameter that you desire as normal)
For using the component category option etc. Then the same line of code can be found in 'components/com_k2/models/itemlist.php' on Line 39 which again would need to be edited. Then you could just use the built in parameters as usual!

Magento Option Question

This seems simple enough in theory but I haven't found anything on it. I need it for a client. Please see this page as an example: http://www.customsportsteamuniforms.com/index.php/test-shirt.html
On that page, you will find the first option that says "What kind of Screen Printing do you want?" If you select 1 color and you also happen to want more than 1 quantity (let's say 5), you will end up with this formula for the product cost:
$5 (cost) x $25 (option) x 5 quantity = total.
I DO NOT want it to do that. The option should be a one time fee in this case. The formula should read:
$5 (cost) x 5 quantity = sub-total + $25 (option) = total
How do I do this?
Magento's additional fees are all calculated on a per-product basis. If you want to add a fee to the entire order, you'll need to add some custom code to add this as a sort of handling fee for the order. The semantics for this are up to you (for instance, what about 2 different shirts both with 1-color screen printing options).
I found a plugin that does this:
http://www.absolutepricing.com/
Although, in my opinion, this should have been part of the system to begin with, but that's neither here nor there...

Resources