fhircore icon indicating copy to clipboard operation
fhircore copied to clipboard

Populate HTML Content with QuestionnaireResponse Data

Open FikriMilano opened this issue 9 months ago • 1 comments

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)

  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 avatar May 14 '24 09:05 FikriMilano

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

FikriMilano avatar May 14 '24 09:05 FikriMilano

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

ellykits avatar May 17 '24 11:05 ellykits

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

FikriMilano avatar May 17 '24 13:05 FikriMilano

@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.

FikriMilano avatar May 20 '24 07:05 FikriMilano

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

ellykits avatar May 20 '24 07:05 ellykits

@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.

FikriMilano avatar May 20 '24 10:05 FikriMilano

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

ndegwamartin avatar May 20 '24 15:05 ndegwamartin

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

pld avatar May 20 '24 15:05 pld