fhircore
fhircore copied to clipboard
Populate HTML Content with QuestionnaireResponse Data
Describe the feature request. Create a feature that's able to:
- Hide UI elements if there is no answer in the referred link id
- Populate answers as a list or a single value in the HTML
- Populate the submitted date in the HTML content
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
- [x] Hide UI elements if there is no answer in the referred link id
If the answer is empty:
"@is-not-empty('link-id')<p>Text</p>@is-not-empty" -> (nothing)
If the answer is not empty:
"@is-not-empty('link-id')<p>Text</p>@is-not-empty" -> <p>Text</p>
- [x] Populate answers as a list or a single value in the HTML
"</ul>@answer-as-list('link-id')</ul>" -> <ul><li>answer 1</li><li>answer 2</li></ul>
"<p>@answer('link-id')</p>" -> <p>(the answer)</p>
"<p>@answer('link-id')</p>" -> <p>14-May-2024</p> (if it's a date type)
"<p>@answer('link-id','MMMM d, yyyy')</p>" -> <p>May 14, 2024</p>
- [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)
- Create HtmlPopulator class
- Create populateHtml() method, it will accept a raw HTML string and return the populated HTML string with the data from the QuestionnaireResponse
- 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.
@pld @f-odhiambo this is a follow up ticket for PDF generation
@FikriMilano Is the question displayed against the answer or just the link id?
@ellykits I don't understand your question, could you elaborate?
@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.
My question was whether we also display the question, as in question and answer response.
@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.
This is good to go, reverting milestone to today cc @pld
Let's have those loops cleaned up before merge, moving to sprint 11