Skip to content
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

(feat) obsGroup count validation #150

Merged
merged 10 commits into from
Dec 15, 2023

Conversation

arodidev
Copy link
Contributor

@arodidev arodidev commented Nov 29, 2023

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

This PR validates that the number of repeated obsGroup fields matches the repeat limit passed into the form's JSON

Screenshots

Screenshot 2023-12-01 at 11 01 36

Related Issue

Other

@arodidev arodidev changed the title MVP L&D birth count validation Nov 29, 2023
@arodidev arodidev marked this pull request as ready for review December 1, 2023 07:56
@arodidev arodidev changed the title L&D birth count validation (feat) L&D birth count validation Dec 1, 2023
src/components/encounter/ohri-encounter-form.component.tsx Outdated Show resolved Hide resolved
src/utils/ohri-form-helper.ts Outdated Show resolved Hide resolved
@arodidev arodidev marked this pull request as draft December 3, 2023 11:19
@arodidev arodidev marked this pull request as ready for review December 5, 2023 11:45
@arodidev arodidev changed the title (feat) L&D birth count validation (feat) obsGroup count validation Dec 5, 2023
Copy link
Collaborator

@kajambiya kajambiya left a comment

Choose a reason for hiding this comment

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

Hi Jamie, Nice work. Left some minor review comments

import { fetchConceptNameByUuid } from '../api/api';
import { ConceptTrue } from '../constants';
import { EncounterContext } from '../ohri-form-context';
import { OHRIFormField, OHRIFormPage, OHRIFormSection, SubmissionHandler } from '../api/types';
import { OHRIFormField, OHRIFormPage, OHRIFormSection, OpenmrsEncounter, SubmissionHandler } from '../api/types';
Copy link
Collaborator

Choose a reason for hiding this comment

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

You added showToast and OpenmrsEncounter imports but looks like you don't use them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is resolved.

src/components/encounter/ohri-encounter-form.component.tsx Outdated Show resolved Hide resolved

//validate obs group count against limit
const limit = field.questionOptions.repeatOptions?.limit;
const counter = obsGroupCounter?.filter((eachItem) => eachItem.fieldId === field.id)[0]?.obsGroupCount;
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a possible point of failure. What is this line meant to achieve? is there a hidden field with the count?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Count always defaults to 1 as is implemented in the repeating component, and I pass this to the obsGroupCounter state, and with any cloned obsGroup added the count is updated and passed to the obsGroupCounter at the beginning of the array. Not sure if this answers your question.

src/api/types.ts Outdated
@@ -311,3 +311,9 @@ export interface ReferencedForm {
formName: string;
alias: string;
}

export type TobsGroupCounter = {
Copy link
Member

Choose a reason for hiding this comment

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

This naming doesn't look intuitive enough especially with the T can rename it to RepeatGroupCounter or ObsGroupCounter or something else

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is resolved.

@pirupius pirupius requested a review from samuelmale December 12, 2023 14:13
Comment on lines +446 to +451
showToast({
description: 'obsGroup count does not match limit specified',
title: 'Invalid entry',
kind: 'error',
critical: true,
});
Copy link
Member

Choose a reason for hiding this comment

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

We should move away from using Toasts to represent form validation errors and follow the conventions defined in the O3 style guide. We should instead use "Inline" notifications for validation errors.

PS: We should also do a refactor in other places like "after successfully submitting the form" to render a "Snackbar" as opposed to the "Toast".

See: https://zeroheight.com/23a080e38/p/683580-notifications

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is noted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@samuelmale Work on this has been slated to be fixed under technical debt together with a refactor for all other applicable areas concerning this, and as such will not be resolved in this PR.
cc: @eudson

Copy link

Choose a reason for hiding this comment

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

Correct @arodidev ... we agree that the standards need to be followed but lets not block this specific PR.

@pirupius pirupius merged commit 9d91d3d into openmrs:main Dec 15, 2023
6 checks passed
pirupius added a commit that referenced this pull request Dec 15, 2023
pirupius added a commit that referenced this pull request Dec 15, 2023
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.

5 participants