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-3316 Add support for encounter diagnosis #298

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

CynthiaKamau
Copy link
Contributor

@CynthiaKamau CynthiaKamau commented May 28, 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

This feature attempts to introduce encounter diagnosis in RFE
Current RFE Schema :

{
      "label": "Reason for hospitalization:",
      "id": "hospReason",
      "questionOptions": {
	      "concept": "a8a07a48-1350-11df-a1f1-0026b9348838",
	      "rendering": "problem",
	      "rank": 1
      },
      "type": "diagnosis",
      "validators": []
 }

Proposed schema as in AFE :

{ 
  "label": "Test Diagnosis",
  "id": "DiagNosIS",
  "type": "diagnosis",
  "questionOptions": { 
    "rendering": "repeating",
    "dataSource": "diagnoses",
    "rank": 1 
  }
}

Screenshots

Screen.Recording.2024-10-02.at.15.21.51.mov

Related Issue

Other

Copy link

github-actions bot commented May 28, 2024

Size Change: -252 kB (-18.04%) 👏

Total Size: 1.15 MB

Filename Size Change
dist/572.js 0 B -252 kB (removed) 🏆
ℹ️ View Unchanged
Filename Size Change
dist/151.js 300 kB 0 B
dist/225.js 2.57 kB 0 B
dist/277.js 1.84 kB 0 B
dist/300.js 642 B 0 B
dist/335.js 968 B 0 B
dist/353.js 3.02 kB 0 B
dist/41.js 3.37 kB 0 B
dist/422.js 6.8 kB 0 B
dist/501.js 108 kB 0 B
dist/540.js 2.63 kB 0 B
dist/55.js 758 B 0 B
dist/617.js 86.9 kB 0 B
dist/635.js 14.3 kB 0 B
dist/70.js 483 B 0 B
dist/901.js 11.8 kB 0 B
dist/936.js 253 kB 0 B
dist/99.js 691 B 0 B
dist/993.js 3.09 kB 0 B
dist/main.js 342 kB +49 B (+0.01%)
dist/openmrs-esm-form-engine-lib.js 3.67 kB +2 B (+0.05%)

compressed-size-action

Comment on lines 527 to 534
const saveDiagnoses = await EncounterFormManager.saveDiagnosis(fields, savedEncounter);
if (saveDiagnoses) {
showSnackbar({
title: t('encounterDiagnosisSaved', 'Encounter diagnosis saved successfully'),
kind: 'success',
isLowContrast: true,
});
}
Copy link
Member

Choose a reason for hiding this comment

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

So the EncounterResource supports diagnoses as a create-able property shouldn't we be creating the diagnoses in a single transaction with the encounter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me add it the same way we handle orders

@brandones
Copy link
Contributor

@CynthiaKamau Ping, are you still working on this? Any blockers?

@CynthiaKamau
Copy link
Contributor Author

@CynthiaKamau Ping, are you still working on this? Any blockers?

Yes, there some fixes that need to be done on the backend to complete the work

@brandones
Copy link
Contributor

@CynthiaKamau Please provide links to the work or issues you're talking about. If there is no linkable issue/PR/talk/Slack, please tell us what work needs to be completed before this can move forward.

@CynthiaKamau
Copy link
Contributor Author

CynthiaKamau commented Jun 19, 2024

@CynthiaKamau Please provide links to the work or issues you're talking about. If there is no linkable issue/PR/talk/Slack, please tell us what work needs to be completed before this can move forward.

This is the link to the backend pr

@brandones
Copy link
Contributor

Ok @CynthiaKamau , looks like that backend PR is merged. Can we move forward with this?

@CynthiaKamau
Copy link
Contributor Author

Ok @CynthiaKamau , looks like that backend PR is merged. Can we move forward with this?

Im working on it now

@CynthiaKamau CynthiaKamau marked this pull request as ready for review September 25, 2024 10:58
Copy link
Member

@samuelmale samuelmale left a comment

Choose a reason for hiding this comment

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

Nice work @CynthiaKamau! Are you planning on adding some test coverage?

@@ -300,6 +304,27 @@ export async function hydrateRepeatField(
}),
);
}

//handle diagnoses
const unMappedDiagnosis = encounter.diagnoses.filter((diagnosis) => {
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 unMappedDiagnosis = encounter.diagnoses.filter((diagnosis) => {
const unMappedDiagnoses = encounter.diagnoses.filter((diagnosis) => {

@@ -28,6 +29,7 @@ export function prepareEncounter(
const obsForSubmission = [];
prepareObs(obsForSubmission, formFields);
const ordersForSubmission = prepareOrders(formFields);
const diagnosisForSubmission = prepareDiagnosis(formFields);
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 diagnosisForSubmission = prepareDiagnosis(formFields);
const diagnosesForSubmission = prepareDiagnosis(formFields);

context: FormProcessorContextProps,
): Promise<any> {
const availableDiagnoses = sourceObject ?? (context.domainObjectValue as OpenmrsEncounter);
const matchedDiagnosis = availableDiagnoses.diagnoses?.find(
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 matchedDiagnosis = availableDiagnoses.diagnoses?.find(
const matchedDiagnoses = availableDiagnoses.diagnoses?.find(

@@ -166,6 +166,7 @@ export class EncounterFormProcessor extends FormProcessor {
try {
const { data: savedEncounter } = await saveEncounter(abortController, encounter, encounter.uuid);
const saveOrders = savedEncounter.orders.map((order) => order.orderNumber);
const saveDiagnosis = savedEncounter.diagnoses.map((diagnosis) => diagnosis.display);
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 saveDiagnosis = savedEncounter.diagnoses.map((diagnosis) => diagnosis.display);
const savedDiagnoses = savedEncounter.diagnoses.map((diagnosis) => diagnosis.display);

@@ -237,3 +240,19 @@ function handleQuestionsWithObsComments(sectionQuestions: Array<FormField>): Arr

return augmentedQuestions;
}

function handleDiagnosesDataSource(question: FormField) {
Copy link
Member

Choose a reason for hiding this comment

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

I would simply name this: handleDiagnosis(...)

sourceObject: OpenmrsResource,
context: FormProcessorContextProps,
): Promise<any> {
const availableDiagnoses = sourceObject ?? (context.domainObjectValue as OpenmrsEncounter);
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 availableDiagnoses = sourceObject ?? (context.domainObjectValue as OpenmrsEncounter);
const encounter = sourceObject ?? (context.domainObjectValue as OpenmrsEncounter);

context: FormProcessorContextProps,
): Promise<any> {
const availableDiagnoses = sourceObject ?? (context.domainObjectValue as OpenmrsEncounter);
const matchedDiagnoses = availableDiagnoses.diagnoses.find(
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 matchedDiagnoses = availableDiagnoses.diagnoses.find(
const matchedDiagnosis = availableDiagnoses.diagnoses.find(

},
];

describe('EncounterDiagnosesAdapter', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add test case(s) around:

  • editing a value and the fact that the edited value gets voided

@@ -166,6 +166,7 @@ export class EncounterFormProcessor extends FormProcessor {
try {
const { data: savedEncounter } = await saveEncounter(abortController, encounter, encounter.uuid);
const saveOrders = savedEncounter.orders.map((order) => order.orderNumber);
const saveDiagnoses = savedEncounter.diagnoses.map((diagnosis) => diagnosis.display);
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 saveDiagnoses = savedEncounter.diagnoses.map((diagnosis) => diagnosis.display);
const savedDiagnoses = savedEncounter.diagnoses.map((diagnosis) => diagnosis.display);

(I would also rename saveOrders -> savedOrders)

// handle diagnoses
if (saveDiagnoses.length) {
showSnackbar({
title: translateFn('diagnosisSaved', 'Diagnosis(s) saved successfully'),
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
title: translateFn('diagnosisSaved', 'Diagnosis(s) saved successfully'),
title: translateFn('diagnosisSaved', 'Diagnosis(es) saved successfully'),

@@ -300,6 +304,40 @@ export async function hydrateRepeatField(
}),
);
}

const unMappedDiagnoses = encounter.diagnoses.filter((diagnosis) => {
return !assignedDiagnosesIds.includes(diagnosis?.diagnosis?.coded.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 the Diagnosis should include the field's ID in it's formFieldPath otherwise we may end up including past diagnoses.

sortedDiagnoses
.filter((diagnosis) => !diagnosis.voided)
.map(async (diagnosis) => {
const clone = cloneRepeatField(field, diagnosis, counter++);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a demo where we capture diagnoses with "repeat controls"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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