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-3712: add a concept answer to a concept in the form builder #351

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/components/interactive-builder/edit-question.modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import type {
DatePickerTypeOption,
} from '../../types';
import { useConceptLookup } from '../../hooks/useConceptLookup';
import { useConceptInfo } from '../../hooks/useConceptInfo';
import { useConceptName } from '../../hooks/useConceptName';
import { usePatientIdentifierLookup } from '../../hooks/usePatientIdentifierLookup';
import { usePatientIdentifierName } from '../../hooks/usePatientIdentifierName';
Expand Down Expand Up @@ -129,7 +130,7 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
isLoadingConcepts: isLoadingAnsConcepts,
} = useConceptLookup(conceptAnsToLookup);
const [selectedConcept, setSelectedConcept] = useState<Concept | null>(null);

const { concept: editConceptInfo } = useConceptInfo(questionToEdit.questionOptions.concept);
const { concepts, isLoadingConcepts } = useConceptLookup(conceptToLookup);
const { conceptName, conceptNameLookupError, isLoadingConceptName } = useConceptName(
questionToEdit.questionOptions.concept,
Expand Down Expand Up @@ -170,7 +171,6 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
date: [{ value: 'calendar', label: t('calendarOnly', 'Calendar only'), defaultChecked: false }],
time: [{ value: 'timer', label: t('timerOnly', 'Timer only'), defaultChecked: false }],
};

const debouncedSearch = useMemo(() => {
return debounce((searchTerm: string) => setConceptToLookup(searchTerm), 500) as (searchTerm: string) => void;
}, []);
Expand Down Expand Up @@ -202,6 +202,7 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
setAnswer(false);
setConceptToLookup('');
setSelectedAnswers([]);
setAddedAnswers([]);
setSelectedConcept(concept);
setConceptMappings(
concept?.mappings?.map((conceptMapping) => {
Expand Down Expand Up @@ -875,7 +876,14 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
</div>
) : null}

{(selectedConcept || questionToEdit) && questionToEdit?.questionOptions.answers?.length ? (
{!hasConceptChanged && editConceptInfo?.datatype?.uuid == '8d4a48b6-c2cc-11de-8d13-0010c6dffd0f' ? (
Copy link
Contributor

@NethmiRodrigo NethmiRodrigo Nov 18, 2024

Choose a reason for hiding this comment

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

Why do we have a hard-coded UUID?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Willie-theBeastMutua please check my comment, just removing the conditional logic is sufficient, and we'll merge this in. Thanks!

Choose a reason for hiding this comment

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

Why do we have a hard-coded UUID?

The UUID id for the coded datatype that is the check

Choose a reason for hiding this comment

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

@Willie-theBeastMutua please check my comment, just removing the conditional logic is sufficient, and we'll merge this in. Thanks!

If I remove the logic, the more answers will display even when the concept is not of a coded datatype so I added a hook that collects data on the concept and I check for the UUID for the coded datatype. I can use the word "Coded" to check but my fear was what would happen if the language changed

Copy link
Contributor

Choose a reason for hiding this comment

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

Ignore my suggestion about simply removing the condition, I see why the hook is needed.
@ibacher if we do a datatype.display === "Coded", would that be language sensitive?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Willie-theBeastMutua for now lets assume it wont change with the language

Copy link
Member

Choose a reason for hiding this comment

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

@NethmiRodrigo Yes, but if you used datatype.name is shouldn't be, except in some edge-cases.

Copy link
Member

Choose a reason for hiding this comment

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

In general display is the (possibly) localized metadata, but name is the "raw" value.

Choose a reason for hiding this comment

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

@NethmiRodrigo this is done

<div>
<Button kind="tertiary" onClick={showAddQuestion} iconDescription="Add" size="sm">
More Answers
</Button>
</div>
) : null}
{hasConceptChanged && answersFromConcept.length ? (
<div>
<Button kind="tertiary" onClick={showAddQuestion} iconDescription="Add" size="sm">
More Answers
Expand Down
13 changes: 13 additions & 0 deletions src/hooks/useConceptInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import useSWR from 'swr';
import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
import type { Concept } from '../types';

export function useConceptInfo(conceptId: string) {
const url = `${restBaseUrl}/concept/${conceptId}`;

const { data } = useSWR<{ data: Concept }, Error>(conceptId ? url : null, openmrsFetch);

return {
concept: data?.data ?? null,
};
}