opensrp / fhircore

FHIR Core / OpenSRP 2 is a Kotlin application for delivering offline-capable, mobile-first healthcare project implementations from local community to national and international scale using FHIR and WHO Smart Guidelines on Android.
https://smartregister.org
Apache License 2.0
54 stars 41 forks source link

Populate HTML Content with QuestionnaireResponse Data #3257

Closed FikriMilano closed 3 months ago

FikriMilano commented 4 months ago

Describe the feature request. Create a feature that's able to:

Additional context I was initially thinking to use configuration + rules engine, but I feel it will take much more time since the implementation of those 2 need to be refactored first before it can be used by this feature. So, that's why I create a new class then do some simple string manipulation to the html.

Acceptance criteria

If the answer is not empty: "@is-not-empty('link-id')

Text

@is-not-empty" ->

Text


- [x] Populate answers as a list or a single value in the HTML

"/ul>@answer-as-list('link-id')</ul" ->

"p>@answer('link-id')</p" ->

(the answer)

"p>@answer('link-id')</p" ->

14-May-2024

(if it's a date type)

"

@answer('link-id','MMMM d, yyyy')

" ->

May 14, 2024


- [x] Populate the submitted date in the HTML content

"@submitted-date" -> 14-May-2024

"@submitted-date('MMMM d, yyyy')" -> May 14, 2024



**Area path**
Run the test cases, we couldn't directly use this feature in the app until ticket https://github.com/opensrp/fhircore/issues/3235 is complete.

**Implementation plan (For Engineers)**
1. Create HtmlPopulator class
2. Create populateHtml() method, it will accept a raw HTML string and return the populated HTML string with the data from the QuestionnaireResponse
3. Create these methods: processIsNotEmpty(), populateAnswerAsList(), populateAnswer(), populateSubmittedDate(). These will handle specific tasks such as hiding UI elements, populating answers as list items or single values, and populating the submitted date in the HTML content, mainly using string manipulation by finding the tags for each functionality, then replacing it with the correct string/answer.
FikriMilano commented 4 months ago

@pld @f-odhiambo this is a follow up ticket for PDF generation

ellykits commented 4 months ago

@FikriMilano Is the question displayed against the answer or just the link id?

FikriMilano commented 4 months ago

@ellykits I don't understand your question, could you elaborate?

FikriMilano commented 4 months ago

@ellykits we have an HTML that wants to get answer from a link id, we declare that link id in the HTML, and once the HTML got processed, the link id will get replaced by the answer of that link id.

Hope that answers your question.

ellykits commented 4 months ago

My question was whether we also display the question, as in question and answer response.

FikriMilano commented 4 months ago

@ellykits nope, we're only displaying the answers.

We don't have a use case to render dynamic question in PDF yet (dynamic because of using cqf-expression extension to it's question text).

But if the need arises in the future, we can quite simply introduce a new tag/function that retrieves the question itself.

ndegwamartin commented 4 months ago

This is good to go, reverting milestone to today cc @pld

pld commented 4 months ago

Let's have those loops cleaned up before merge, moving to sprint 11