helsenorge / refero

FHIR Questionnaire Form Filler React Component
MIT License
15 stars 5 forks source link

Issue Report Regarding Date-Year-Input Preview #184

Open astghikpetrosyan1 opened 4 months ago

astghikpetrosyan1 commented 4 months ago

The issue primarily revolves around the DateYear component. Specifically, during the generation of the preview response, particularly when the pdf flag is set to true, an anomaly is encountered.

Detailed Description: Upon inspection, it was observed that within the preview response generation, the value retrieval mechanism relies on the getPDFValue function. Below is a snippet exemplifying its integration:

return React.createElement(textview_1.default, {
  id: props.id,
  item: props.item,
  value: getPDFValue(),
  onRenderMarkdown: props.onRenderMarkdown,
  helpButton: props.helpButton,
  helpElement: props.helpElement
}, props.children);

The getPDFValue function internally invokes the getYear function to fetch the relevant year data. However, a critical issue arises within the getYear function. Despite the conditional check for props.answer being an array, it invariably evaluates to false, leading to an undefined outcome. Consequently, the final response defaults to the 'not found text'.

Below is a segment illustrating the problematic section within the getYear function:

const getYear = () => {
  if (Array.isArray(props.answer)) {
    return props.answer.map(m => {
      return (createDateFromYear(props.item, m))?.getFullYear();
    });
  }
};

Proposed Solution: To address this issue, I have devised a solution that involves refining the getYear and getPDFValue functions. The modifications aim to enhance the logic flow and ensure accurate retrieval and presentation of the year data.

Here is a synopsis of the adjustments made:

const getYear = (): (number | undefined)[] | undefined | string | number => {
  if (Array.isArray(props.answer)) {
    return props.answer.map((m: QuestionnaireResponseItemAnswer) => createDateFromYear(props.item, m)?.getFullYear());
  }

  if (props.answer?.valueDate) {
    return props.answer?.valueDate
  }

  return answerState;
};

const getPDFValue = (): string | number => {
  const ikkeBesvartText = props.resources?.ikkeBesvart || '';

  const year = getYear();

  if (Array.isArray(year)) {
    return year
      ?.map(m => m?.toString())
      .join(', ') || ikkeBesvartText;
  }

  return year || ikkeBesvartText;
};

The outlined adjustments ensure robust handling of diverse data scenarios, thereby mitigating the issue encountered during the preview response generation.

I trust that this information provides valuable insight into the matter at hand. Please feel free to reach out should further clarification or assistance be required.

Thank you for your attention to this matter.

Best regards, Astghik

ruberino commented 2 weeks ago

We are currently in the prosess of replacing the old date components with new components from @helsenorge/designsystem-react package