Since you’re using CouchDb APIs, I think the best place to get information is the CouchDb documentation website.
If you want to get information about a specific doc, use:
From the screen shot above i have a column name variable called score_note in my app form that i want to pull the data from and use it as the value in card configuration code as seen below. The form name is care
If you are using allReportssimilarly to the default config, then keep in mind that it is an array of all reports for that contact, and you can’t access the fields directly. You can go through the individual reports manually, but given what you are trying to do here you could use the single form submission in report instead: report.fields.score_note, or using the getField function: getField(report, 'score_note');
Hi Cliff, that’s looking better. Can explain how you debugged the code? Are there any errors in your console?
An approach I usually take is to reduce the code to basic parts and ensure it works, then gradually build in the more complex parts. That way you can more clearly see what is working, and identify the aspect that breaks. For condition cards that generally means starting with a simple card with no condition and static data (value: 'random string'). If that works you can then add the condition to make sure it appears only when expected. Once you have that you can add the code to extract the necessary data, and then work on presenting it properly. When a part is not working as intended you can inspect the values to make sure they are what you’d expect. For contact summary this could be done by outputting values to the console with console.log(value).
In your case, given that the card is not showing I would suspect that the appliesIf function is behaving differently than you’d expect. It would be worthwhile to check the values passed to your function, since you might find that one of the values is unexpectedly undefined. If that’s the case, you might find this example helpful, especially since the function signature is different. You could follow the same pattern and use the globally available contact, indirectly used as thisContact in the example.
I have switched to the globally availbale contact defined above as const thisContact = contact;
{
label: 'risk.status',
appliesToType: 'report',
appliesIf: function (report){
if (thisContact.type !== 'person') { return false; }
if (report.form === 'care') { return true; }
return false;
},
fields: [
{
label: 'risk.category',
value : function(report) {
var edd = report.fields.score_note;
return edd;
},
width: 6
}
]
},
Looks like if the card can only appear on a coantact profile when the value of appliesToType is set to person ,for appliesToType: 'report' it creates a report card as stated here ,not sure if this report card appears on the contacts profile or not
the tricky bit here is how to fetch the data from the app report fields and display it in a report card to appear on the contact’s profile , i have changed the configurations like below
It looks like your card is at least showing up, which is a good start! What value do you see with the code above? Are there any errors in your console?
this is how the data looks like when pulled from the DB about the care form {"id":"20e108b7-5b74-4bf9-9b9b-d64cdc12e8e1","key":"20e108b7-5b74-4bf9-9b9b-d64cdc12e8e1","value":{"rev":"2-2090ce698a9f7c4e54d65795a1a72798"},"doc":{"_id":"20e108b7-5b74-4bf9-9b9b-d64cdc12e8e1","_rev":"2-2090ce698a9f7c4e54d65795a1a72798","form":"care","type":"data_record","content_type":"xml","reported_date":1648468798532,"contact":{"_id":"4ddf391d-b850-4e08-bada-57284b32d1bd","parent":{"_id":"a00cc3f0-196c-4477-a9a1-c2c04dd3f7f4"}},"from":"+256705475234","hidden_fields":["meta"],"fields":{"inputs":"","contact":{"_id":"b4ae429f-c321-4d4d-a5d7-63a5217c9642","patient_id":"","name":"ggg"},"care":{"medical":"fifty","knowledge":"none","adherence":"rarely","mental":"failed_treatment","transportation":"tr","support":"only","communication":"xx","employment":"unemployed","living":"homless","score":"31","score_note":"","category":""},"meta":{"instanceID":"uuid:a5686b67-48bd-40c7-9dc9-67051d810229","deprecatedID":""}},"geolocation":{"latitude":0.3407872,"longitude":32.5910528,"altitude":null,"accuracy":5378.323948523854,"altitudeAccuracy":null,"heading":null,"speed":null},"_attachments":{"content":{"content_type":"application/xml","revpos":1,"digest":"md5-xbSTavJykVpwsrqsL4vZBA==","length":968,"stub":true}}}},
Ah, I had meant the developer console in the browser. That’s where you would see runtime errors or output that you put in your contact summary code. I tested something similar to what you have with appliesToType: ['report'] and it is working as expected.
Given that it doesn’t run on your side you’ll need to dig into your appliesIf function to see what reports it is looking at, if any. I would suggest using a console.log(r) statement in your appliesIf function to get a better sense of what is going on.
i have applied the logging to the console in the appliesIf function but for some reason the values are not being logged into the console
That’s a good finding! Do you have any forms submitted for this contact? In the screenshot I don’t see any for the previous 3 months… are there any at all? If not, then that is expected, as a card will only show when a report meets the appliesIf condition.
Yes, that’s correct. Cards with appliesToType: ['report'] can only show if a report is submitted, and the appliesIf condition is true.
Conversely, cards that are defined for the contact type can show up for that contact whether or not a report has been submitted, assuming the type matches and appliesIf condition is true.
In the overview it says “Condition cards can be permanent or conditional; set to appear only when a specific type of report is submitted”, yet the reference documentation doesn’t make that as clear. Sorry that you struggled with this, and we’ll update the documentation so that others don’t have the same misunderstanding.
This is what am trying to achieve but i dont see the Level of care assessment form task moving from the Tasks and coming under Reports when the form is submitted…
Is it achieved with the resolvedIf parameter of task configuration ?