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-3365: Add the ability to record non-coded cause-of-death #1876

Merged
merged 3 commits into from
Jun 26, 2024

Conversation

jwnasambu
Copy link
Contributor

@jwnasambu jwnasambu commented Jun 24, 2024

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

Summary

I included a feature to allow users to enter a free-text cause of death. If someone selects 'Other', the text input field will be available for entering this free-text concept

Screenshots

screencast.2024-06-25.11.PM-55-08.mp4

Related Issue

https://openmrs.atlassian.net/browse/O3-3365

Other

@jwnasambu jwnasambu marked this pull request as draft June 24, 2024 19:05
@jwnasambu
Copy link
Contributor Author

Hey @ibacher and @denniskigen, I kindly request for your guidance please! I'm a bit stuck on how to properly utilize other cause of death concept fetched by the useCauseOfDeath hook. When I add the TextInput input, it creates another other concept that functions as expected but on submitting the entered value in the TextInput throws an error as reflected in the video above.

Comment on lines 40 to 41
const OTHER_CONCEPT_UUID = 'UUID of other';
const OTHER_CONCEPT_DISPLAY = t('other', 'Other');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const OTHER_CONCEPT_UUID = 'UUID of other';
const OTHER_CONCEPT_DISPLAY = t('other', 'Other');
```suggestion
const freetextCauseOfDeathUuid = 5622AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';

@@ -34,25 +35,34 @@ const MarkPatientDeceasedForm: React.FC<DefaultPatientWorkspaceProps> = ({ close
const { deathDate, isDead } = usePatientDeceasedStatus(patientUuid);
const [isSubmitting, setIsSubmitting] = useState(false);
const [searchTerm, setSearchTerm] = useState('');
const [showOtherInputField, setShowOtherInputField] = useState(false);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const [showOtherInputField, setShowOtherInputField] = useState(false);

Comment on lines 43 to 60
const filteredCausesOfDeath = useMemo(() => {
if (!searchTerm) {
return causesOfDeath;
if (!causesOfDeath) return [];

let filtered = causesOfDeath.filter((concept) => concept.uuid !== OTHER_CONCEPT_UUID);

if (searchTerm) {
filtered = fuzzy
.filter(searchTerm, filtered, {
extract: (causeOfDeathConcept) => causeOfDeathConcept.display,
})
.sort((r1, r2) => r1.score - r2.score)
.map((result) => result.original);
}

return searchTerm
? fuzzy
.filter(searchTerm, causesOfDeath, {
extract: (causeOfDeathConcept) => causeOfDeathConcept.display,
})
.sort((r1, r2) => r1.score - r2.score)
.map((result) => result.original)
: causesOfDeath;
}, [searchTerm, causesOfDeath]);
filtered.push({ uuid: OTHER_CONCEPT_UUID, display: OTHER_CONCEPT_DISPLAY, name: OTHER_CONCEPT_DISPLAY });

return filtered;
}, [searchTerm, causesOfDeath, OTHER_CONCEPT_DISPLAY]);
Copy link
Member

Choose a reason for hiding this comment

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

You don't need any of these changes.

Comment on lines 90 to 98
useEffect(() => {
setShowOtherInputField(causeOfDeathValue === OTHER_CONCEPT_UUID);
}, [causeOfDeathValue]);

useEffect(() => {
if (causesOfDeath && causesOfDeath.length > 0) {
setShowOtherInputField(causeOfDeathValue === OTHER_CONCEPT_UUID);
}
}, [causesOfDeath, causeOfDeathValue]);
Copy link
Member

Choose a reason for hiding this comment

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

Remove this.

Comment on lines 123 to 125
const causeOfDeathToSubmit = causeOfDeath === OTHER_CONCEPT_UUID ? freeTextCauseOfDeath : causeOfDeath;

markPatientDeceased(deathDate, patientUuid, causeOfDeathToSubmit)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const causeOfDeathToSubmit = causeOfDeath === OTHER_CONCEPT_UUID ? freeTextCauseOfDeath : causeOfDeath;
markPatientDeceased(deathDate, patientUuid, causeOfDeathToSubmit)
markPatientDeceased(deathDate, patientUuid, causeOfDeath === freetextCauseOfDeathUuid ? freeTextCauseOfDeath : causeOfDeath)

Comment on lines 221 to 229
{filteredCausesOfDeath.map(({ uuid, display, name }) => (
<RadioButton
key={uuid}
className={styles.radioButton}
id={name}
labelText={display}
value={uuid}
/>
))}
Copy link
Member

Choose a reason for hiding this comment

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

I think we can undo this change as well

)}
/>
</div>
)}
Copy link
Member

@denniskigen denniskigen Jun 24, 2024

Choose a reason for hiding this comment

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

Move this below the <section> tag.

@@ -216,6 +240,24 @@ const MarkPatientDeceasedForm: React.FC<DefaultPatientWorkspaceProps> = ({ close
) : null}
</div>
{errors?.causeOfDeath && <p className={styles.errorMessage}>{errors?.causeOfDeath?.message}</p>}
{showOtherInputField && (
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{showOtherInputField && (
{causeOfDeathValue === freetextCauseOfDeathUuid && (

@denniskigen denniskigen changed the title (fix)O3-3365: Cause-of-death concepts are not loading in O3 (feat) O3-3365: Add the ability to record non-coded cause-of-death Jun 24, 2024
@jwnasambu
Copy link
Contributor Author

@denniskigen Thanks

@denniskigen
Copy link
Member

@ibacher what property should be used to record the freetext value to the backend? https://rest.openmrs.org/#create-a-person

@ibacher
Copy link
Member

ibacher commented Jun 24, 2024

causeOfDeathNonCoded

@jwnasambu
Copy link
Contributor Author

@denniskigen this is funny. We walking on the same issue at ago. Thanks am looking at some of the changes you have pushed and I can consent I wasn't thinking in that direction and I will be glad learning something from the coffee break session.

@jwnasambu
Copy link
Contributor Author

@denniskigen I was concentrating on validating this form since it can be submitted successfully with or without a date. Should I continue with the task or terminate it the task?

@jwnasambu jwnasambu marked this pull request as ready for review June 25, 2024 10:06
@jwnasambu
Copy link
Contributor Author

@denniskigen am so sorry for the late response I had issues with internet. Kindly I have tested and attached the current snapshot everything seems to be working as expected.

Copy link
Member

@denniskigen denniskigen left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -34,12 +35,12 @@ const MarkPatientDeceasedForm: React.FC<DefaultPatientWorkspaceProps> = ({ close
const { deathDate, isDead } = usePatientDeceasedStatus(patientUuid);
const [isSubmitting, setIsSubmitting] = useState(false);
const [searchTerm, setSearchTerm] = useState('');
const freetextCauseOfDeathUuid = '5622AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
Copy link
Member

Choose a reason for hiding this comment

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

@ibacher should this value be configurable?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. Just about anywhere we use a concept, the concept should be configurable. Technically, the platform only enforces that there is a True / False concept.

Copy link
Member

Choose a reason for hiding this comment

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

Let me work that in. Thanks

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.

3 participants