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) O3-2972: Add disallow decimals validator #135

Merged
merged 3 commits into from
Apr 19, 2024

Conversation

denniskigen
Copy link
Member

@denniskigen denniskigen commented Apr 18, 2024

Requirements

  • This PR has a title that briefly describes the work done, including the ticket number if there is a ticket.
  • 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 adds a new validator that disallows entering decimal values in number fields based on the optional disallowDecimals property in a question definition.

This feature is necessitated by how numeric concepts can specify whether they allow decimal values or not:

CleanShot 2024-04-19 at 12  30 20@2x

Presently, the number rendering type doesn't provide any validation for decimal values (nor does the Carbon NumberInput which is what it's using under-the-hood).

With this new validator, form authors can tack on a disallowDecimals boolean property to the question definition for a number field and set it to true if it doesn't allow decimals. Once set up, the form engine will show an error if a decimal value is entered in the field.

This fix addresses an ongoing issue with the Laboratory Test Results form in the reference application. Filling the form with decimal values that lie within the reference ranges for those concepts yields an error when the form is submitted:

image-20240327-114806

This error is directly related to number fields not allowing decimal values. In this case, the fields that don't allow decimal values are:

  • Platelets
  • Neutrophils (%)
  • Mean Corpuscular Volume
  • Lymphocytes
  • Combined % of monocytes, eosinophils and basophils
  • Serum sodium
  • Total protein
  • Serum Glucose (mg/dl)
  • Serum glutamic-oxaloacetic transaminase
  • Alkaline Phosphatase, ALP (U/L)
  • Amylase (IU/L)
  • Serum Carbon Dioxide CO2 (mmol/L)

Screenshots

disallow-decimal-values.mp4

Related Issue

O3-2972

Other

Once this gets merged in, the next step is modifying the Lab Test Results form schema so that questions linked to concepts that don't allow decimal values have a disallowDecimals boolean property set to true in their question definitions.

@denniskigen
Copy link
Member Author

denniskigen commented Apr 18, 2024

@gracepotma do you know why the Amylase (IU/L) question is included twice on the Chemistry page of the Lab Test Results form? Was it added by mistake?

Copy link
Member

@donaldkibet donaldkibet left a comment

Choose a reason for hiding this comment

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

Thanks @denniskigen LGTM 🤝

@donaldkibet donaldkibet merged commit cd73355 into main Apr 19, 2024
3 checks passed
@donaldkibet donaldkibet deleted the feat/disallow-decimals-validator branch April 19, 2024 09:41
@denniskigen denniskigen changed the title (feat) Add disallow decimals validator (feat) O3-2972: Add disallow decimals validator Apr 19, 2024
donaldkibet pushed a commit that referenced this pull request May 15, 2024
* (feat) Add disallow decimals validator

* Restore ESLint ignores

* Remove console.log
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