forked from openmrs/openmrs-esm-patient-management
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) KHP3-6944 : Add KDOD cascading units and cadre and required id…
…entifiers for civilian rank (#51) * (fix) remove null values from queues query params (#27) * (feat) KDOD service unit filters * (feat) KHP3-6944 : Add KDOD cascading units and cadre and required identifiers for civilian rank * (feat) add dynamic showing of publication number
- Loading branch information
1 parent
66c8afe
commit fb67255
Showing
13 changed files
with
35,644 additions
and
36 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
5,893 changes: 5,893 additions & 0 deletions
5,893
packages/esm-bed-management-app/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
5,901 changes: 5,901 additions & 0 deletions
5,901
packages/esm-patient-list-management-app/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
6,047 changes: 6,047 additions & 0 deletions
6,047
packages/esm-patient-registration-app/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...n-app/src/patient-registration/field/person-attributes/useUpdateIdentifierRequirement.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { useEffect, useCallback, useRef, useMemo, useContext } from 'react'; | ||
import { deleteIdentifierType, initializeIdentifier } from '../id/id-field.component'; | ||
import { ResourcesContext } from '../../../offline.resources'; | ||
|
||
const useUpdateIdentifierRequirement = (setFieldValue, values) => { | ||
const { identifierTypes = [] } = useContext(ResourcesContext); | ||
const previousAttributes = useRef(values.attributes); | ||
const previousIdentifiers = useRef(values.identifiers); | ||
|
||
const publicationNumberIdentifier = useMemo( | ||
() => identifierTypes?.find((identifier) => identifier.name === 'Publication Number'), | ||
[identifierTypes], | ||
); | ||
|
||
// Memoize the civilian check | ||
const isCivilian = useMemo(() => Object.values(values.attributes ?? {}).includes('Civilian'), [values.attributes]); | ||
|
||
// Memoize the identifier initialization logic | ||
const initializePublicationIdentifier = useCallback( | ||
(currentIdentifiers) => { | ||
if (!publicationNumberIdentifier) { | ||
console.warn('Publication Number identifier type not found'); | ||
return null; | ||
} | ||
|
||
const initializedIdentifier = initializeIdentifier( | ||
publicationNumberIdentifier, | ||
currentIdentifiers[publicationNumberIdentifier.uuid], | ||
); | ||
|
||
return initializedIdentifier; | ||
}, | ||
[publicationNumberIdentifier], | ||
); | ||
// Only run the effect if isCivilian is true | ||
useEffect(() => { | ||
// Skip if we don't have the required data | ||
if (!values.attributes || !publicationNumberIdentifier) { | ||
return; | ||
} | ||
|
||
// Check if relevant values have actually changed | ||
const attributesChanged = previousAttributes.current !== values.attributes; | ||
const identifiersChanged = previousIdentifiers.current !== values.identifiers; | ||
|
||
if (!attributesChanged && !identifiersChanged) { | ||
return; | ||
} | ||
|
||
// Update refs | ||
previousAttributes.current = values.attributes; | ||
previousIdentifiers.current = values.identifiers; | ||
const isDependant = Object.values(values.attributes ?? {}).includes('Dependant'); | ||
// Only proceed if the user is a civilian | ||
if (isCivilian && isDependant) { | ||
const initializedIdentifier = initializePublicationIdentifier(values.identifiers); | ||
|
||
// check if values.identifiers already has the publication number identifier | ||
const hasPublicationNumberIdentifier = values.identifiers[publicationNumberIdentifier.fieldName]; | ||
|
||
if (initializedIdentifier && !hasPublicationNumberIdentifier) { | ||
setFieldValue('identifiers', { | ||
...values.identifiers, | ||
[publicationNumberIdentifier.fieldName]: { ...initializedIdentifier, required: true }, | ||
}); | ||
} | ||
} else { | ||
// Before deleting the publication number identifier, check if it exists | ||
if (values.identifiers[publicationNumberIdentifier.fieldName]) { | ||
setFieldValue('identifiers', deleteIdentifierType(values.identifiers, publicationNumberIdentifier.fieldName)); | ||
} | ||
} | ||
}, [ | ||
values.attributes, | ||
values.identifiers, | ||
isCivilian, | ||
publicationNumberIdentifier, | ||
initializePublicationIdentifier, | ||
setFieldValue, | ||
]); | ||
}; | ||
|
||
export default useUpdateIdentifierRequirement; |
Oops, something went wrong.