-
Notifications
You must be signed in to change notification settings - Fork 215
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-4065 Allow manual entry of auto generated identifiers #1338
Open
ynurmahomed
wants to merge
5
commits into
openmrs:main
Choose a base branch
from
ynurmahomed:O3-4065
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f9d5a54
(feat) O3-4065 Allow manual entry of auto generated identifiers
ynurmahomed 16b36c3
Merge branch 'main' into O3-4065
ynurmahomed 287a237
Merge branch 'main' into O3-4065
ynurmahomed a930046
Merge branch 'main' into O3-4065
ynurmahomed b61fc45
Remove id field configuration
ynurmahomed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,15 +18,17 @@ interface IdentifierInputProps { | |
} | ||
|
||
const IdentifierInput: React.FC<IdentifierInputProps> = ({ patientIdentifier, fieldName }) => { | ||
const { autoGeneration, initialValue, identifierValue, identifierName, required, selectedSource } = patientIdentifier; | ||
const { t } = useTranslation(); | ||
const { defaultPatientIdentifierTypes } = useConfig(); | ||
const { defaultPatientIdentifierTypes, fieldConfigurations } = useConfig(); | ||
const { identifierTypes } = useContext(ResourcesContext); | ||
const { isOffline, values, setFieldValue } = useContext(PatientRegistrationContext); | ||
const identifierType = useMemo( | ||
() => identifierTypes.find((identifierType) => identifierType.uuid === patientIdentifier.identifierTypeUuid), | ||
[patientIdentifier, identifierTypes], | ||
); | ||
const { autoGeneration, initialValue, identifierValue, identifierName, required } = patientIdentifier; | ||
const manualEntryEnabled = | ||
fieldConfigurations.id.allowAutoGenerationManualEntry && selectedSource?.autoGenerationOption?.manualEntryEnabled; | ||
const [hideInputField, setHideInputField] = useState(autoGeneration || initialValue === identifierValue); | ||
const name = `identifiers.${fieldName}.identifierValue`; | ||
const [identifierField, identifierFieldMeta] = useField(name); | ||
|
@@ -46,8 +48,8 @@ const IdentifierInput: React.FC<IdentifierInputProps> = ({ patientIdentifier, fi | |
setFieldValue(`identifiers.${fieldName}`, { | ||
...patientIdentifier, | ||
identifierValue: initialValue, | ||
selectedSource: null, | ||
autoGeneration: false, | ||
selectedSource, | ||
autoGeneration, | ||
} as PatientIdentifierValue); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [initialValue, setHideInputField]); | ||
|
@@ -57,6 +59,7 @@ const IdentifierInput: React.FC<IdentifierInputProps> = ({ patientIdentifier, fi | |
setFieldValue(`identifiers.${fieldName}`, { | ||
...patientIdentifier, | ||
...setIdentifierSource(identifierType?.identifierSources?.[0], initialValue, initialValue), | ||
...(autoGeneration && manualEntryEnabled && { identifierValue: initialValue || '' }), | ||
}); | ||
}; | ||
|
||
|
@@ -83,9 +86,12 @@ const IdentifierInput: React.FC<IdentifierInputProps> = ({ patientIdentifier, fi | |
} | ||
}; | ||
|
||
const showEditButton = !required && hideInputField && (!!initialValue || manualEntryEnabled); | ||
const showResetButton = | ||
(!!initialValue && initialValue !== identifierValue) || (!hideInputField && manualEntryEnabled); | ||
return ( | ||
<div className={styles.IDInput}> | ||
{!autoGeneration && !hideInputField ? ( | ||
{!hideInputField ? ( | ||
<Input | ||
id={name} | ||
labelText={identifierName} | ||
|
@@ -99,8 +105,10 @@ const IdentifierInput: React.FC<IdentifierInputProps> = ({ patientIdentifier, fi | |
/> | ||
) : ( | ||
<div className={styles.textID}> | ||
<p className={styles.label}>{identifierName}</p> | ||
<p data-testid="identifier-label" className={styles.bodyShort02}> | ||
<p data-testid="identifier-label" className={styles.label}> | ||
{required ? identifierName : `${identifierName} (${t('optional', 'optional')})`} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Different languages have different requirements around word order, so it would be better to make this whole thing translatable. See the i18next docs. |
||
</p> | ||
<p data-testid="identifier-placeholder" className={styles.bodyShort02}> | ||
{autoGeneration ? t('autoGeneratedPlaceholderText', 'Auto-generated') : identifierValue} | ||
</p> | ||
<input data-testid="identifier-input" type="hidden" {...identifierField} disabled /> | ||
|
@@ -111,9 +119,10 @@ const IdentifierInput: React.FC<IdentifierInputProps> = ({ patientIdentifier, fi | |
</div> | ||
)} | ||
<div style={{ marginBottom: '1rem' }}> | ||
{!patientIdentifier.required && patientIdentifier.initialValue && hideInputField && ( | ||
{showEditButton && ( | ||
<UserHasAccess privilege="Edit Patient Identifiers"> | ||
<Button | ||
data-testid="edit-button" | ||
size="md" | ||
kind="ghost" | ||
onClick={handleEdit} | ||
|
@@ -124,7 +133,7 @@ const IdentifierInput: React.FC<IdentifierInputProps> = ({ patientIdentifier, fi | |
</Button> | ||
</UserHasAccess> | ||
)} | ||
{initialValue && initialValue !== identifierValue && ( | ||
{showResetButton && ( | ||
<UserHasAccess privilege="Edit Patient Identifiers"> | ||
<Button | ||
size="md" | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there reason we need to add the new O3 config property here (ie "allowAutoGenerationManulEntry") instead of entirely relying on the "autogenerationOption.manualEntryEnabled" config that comes from the IDGen module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mogoodrich The config property is because I was not sure if this feat should be enabled by default. It can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need extra configuration here. Makes sense to remove it.