-
Notifications
You must be signed in to change notification settings - Fork 68
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-4137: Add support for nested obsGroup #427
Conversation
Size Change: +705 B (+0.06%) Total Size: 1.25 MB ℹ️ View Unchanged
|
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.
LGTM! Just a few minor comments.
field.questions | ||
?.filter((child) => !child.isHidden) | ||
.map((child, index) => { | ||
const keyId = `${child.id}_${index}`; |
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.
const keyId = `${child.id}_${index}`; | |
const key = `${child.id}_${index}`; |
src/adapters/obs-adapter.test.ts
Outdated
], | ||
}); | ||
|
||
const createNestedObs = () => ({ |
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.
const createNestedObs = () => ({ | |
const createEncounterWithNestedObs = () => ({ |
src/hooks/useFormFields.ts
Outdated
const conceptReferencesTemp = new Set<string>(); | ||
|
||
const flattenFields = (fields: FormField[]) => { |
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.
This function is recursive and causes side effects to external states, making it less pure. Below is an example of how we can simplify this logic (AI generated)
const processFlattenedFields = (fields: FormField[]): {
flattenedFields: FormField[];
conceptReferences: Set<string>;
} => {
const flattenedFields: FormField[] = [];
const conceptReferences = new Set<string>();
const processField = (field: FormField, parentGroupId?: string) => {
// Add group ID to nested fields if applicable
const processedField = parentGroupId
? { ...field, meta: { ...field.meta, groupId: parentGroupId } }
: field;
// Add field to flattened list
flattenedFields.push(processedField);
// Collect concept references
if (processedField.questionOptions?.concept) {
conceptReferences.add(processedField.questionOptions.concept);
}
// Collect concept references from answers
processedField.questionOptions?.answers?.forEach((answer) => {
if (answer.concept) {
conceptReferences.add(answer.concept);
}
});
// Recursively process nested questions for obsGroup
if (processedField.type === 'obsGroup' && processedField.questions) {
processedField.questions.forEach((nestedField) => {
processField(nestedField, processedField.id);
});
}
};
// Process all input fields
fields.forEach(processField);
return { flattenedFields, conceptReferences };
};
c16113f
to
21ebc76
Compare
Requirements
Summary
This PR introduces functionality for handling nested obsGroup questions. With this enhancement, users can now nest obsGroup elements within other obsGroup elements, allowing for complex hierarchical structures within forms. This feature supports scenarios requiring parent-child relationships among grouped observations, providing a more flexible and detailed data-capture process.
Example schema
Screenshots
Related Issue
https://openmrs.atlassian.net/browse/O3-4137
Other