Skip to content

(feat) O3-4171 : Validate concept answers and show error for non-existing answers #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Bharath-K-Shetty
Copy link
Contributor

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

Summary

  • Checks each answer concept against the original concept's answer list
  • Performs a concept lookup only for non-original answers
  • Shows an inline notification when one or more answers are invalid.

Screenshots

Screen.Recording.2025-04-08.190713.mp4

Related Issue

https://openmrs.atlassian.net/browse/O3-4171

Other

@Bharath-K-Shetty
Copy link
Contributor Author

Bharath-K-Shetty commented Apr 8, 2025

Hey @NethmiRodrigo should i stick with this endpoint ${restBaseUrl}/concept?q=${conceptId}&v=full for additional concept answers validation or current end point is good?
Also, I'm planning to extend the validation to check for invalid concept answer names as well. I haven’t implemented that part yet since there are a few existing issues with editing concept answer names that I want to avoid interfering with for now.Thanks..!

setInvalidAnswerFound(!allValid);
};

validateAnswers();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are calling this function inside useEffect, the function should be defined outside the useEffect hook.

if (originalAnswerIds.has(answer.id)) {
continue;
} else {
const url = `${restBaseUrl}/concept/${answer.id}?v=full`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the useConceptId hook.
For future reference, we don't usually do API calls within the component like this. We make hooks - https://o3-docs.openmrs.org/docs/coding-conventions/data-fetching.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NethmiRodrigo But we can't directly use the hook inside the loop right??

Comment on lines +198 to +206
{invalidAnswerFound && (
<InlineNotification
kind="error"
lowContrast
className={styles.error}
title={t('invalidAnswerConcept', 'Invalid Answer Concept Detected')}
subtitle={t('answerConceptValidation', 'One or more selected answer concepts do not exist in the system. ')}
/>
)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, maybe we can show a not found icon within the blue tag of the answer that is invalid. Otherwise we'd have to guess which ones are invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants