Passing information from contact-summary.templated.js to tasks.js

We have some issue that if the patient/woman that is pregnant and that has more than 43 weeks, it should have doing a task like end of pregnancy .

So, What I have struggle right now is getting the data from contact-summary.templated (or a calculation) to tasks.js as a appliesIf condition.

function screeningAdulthoodLMPEndOfPregnancy(screening_adulthood){
    const lmpDate = getLMPDateFromScreeningAdulthood(screening_adulthood); 
    return Math.round(DateTime.local().diff(DateTime.fromISO(lmpDate), 'weeks').weeks) > 43 ;
}

function getLMPDateFromScreeningAdulthood(screening_adulthood){
    return Utils.getField(screening_adulthood,'lmp'); //|| Utils.getField(screening_adulthood,'latest_lmp_date');
}

So, from this function, I will get the data from this form “screening_adulthood” and fetch the data on another function that ‘lmp’ has.

Then, once I get that one, using Math Function to compute the pregnancy weeks and then if greater than 43 weeks. Then, the task will gonna show.

Hi @Marcelo_De_Guzman , So your question is, you already know how many weeks the pregnancy is, and you want to get this info on task such that you know wheter to populate the task or not?

Mostly get the information about the number of weeks so that on the task I can use it as a appliesIf and will run new task.

So, What I have struggle right now is getting the data from contact-summary.templated (or a calculation) to tasks.js as a appliesIf condition.

I might be missing something here, but your contact-summary.templated.js file and your tasks.js file should be able to share code. You can extract the logic into a sparate file and then require that file in contact-summary.templated.js and tasks.js. (Similar to how the tasks.js and targets.js files in the example Default config both depend on shared logic in the nools-extras.js file.

Alternatively, you mention “calculation”. If your algorithm is sufficiently complex, you could extract it to an extension-lib that could be referenced from forms/contact-summary/tasks/etc.

Hi @Marcelo_De_Guzman , as we discussed briefly on the call, the default config shows how to calculate and expose these fields from contact-summary-templated .

The pregnancy_home_visit.xlsx form demonstrates how is this field retrieved and used on the form. Look for line 42 and 53 to see how tt_received_ctx holds the value of tt_received_past exposed in contact summary and how that is used in forms in line 197.

There are multiple examples of passing these values and you can do the same for your task form.