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

Merged
merged 7 commits into from
Jan 21, 2025
Merged

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 AFE 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 RFE :

{
      "label": "Test Diagnosis",
      "id": "DiagNosIS",
      "type": "diagnosis",
      "questionOptions": {
        "rendering": "repeating",
        "dataSource": "diagnoses",
        "diagnosis": {
          "isConfirmed": "true",
          "rank": 1,
          "conceptClasses": [
            "8d4918b0-c2cc-11de-8d13-0010c6dffd0f"
          ]
        }
      }
}

Screenshots

Screen.Recording.2024-11-27.at.15.11.12.mov

Related Issue

Other

@CynthiaKamau CynthiaKamau marked this pull request as draft May 28, 2024 11:49
Copy link

github-actions bot commented May 28, 2024

Size Change: -264 kB (-17.22%) 👏

Total Size: 1.27 MB

Filename Size Change
dist/891.js 0 B -264 kB (removed) 🏆
ℹ️ View Unchanged
Filename Size Change
dist/151.js 382 kB 0 B
dist/225.js 2.58 kB 0 B
dist/260.js 114 kB 0 B
dist/277.js 11.9 kB 0 B
dist/300.js 645 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 3.05 kB 0 B
dist/499.js 2.51 kB 0 B
dist/524.js 265 kB 0 B
dist/540.js 2.63 kB 0 B
dist/55.js 758 B 0 B
dist/606.js 2.24 kB 0 B
dist/635.js 14.4 kB 0 B
dist/658.js 1.85 kB 0 B
dist/727.js 87.2 kB 0 B
dist/979.js 6.87 kB 0 B
dist/99.js 691 B 0 B
dist/993.js 3.09 kB 0 B
dist/main.js 357 kB +66 B (+0.02%)
dist/openmrs-esm-form-engine-lib.js 3.8 kB -2 B (-0.05%)

compressed-size-action

@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 CynthiaKamau force-pushed the O3-3316 branch 2 times, most recently from a40ba8d to 2415c6d Compare September 16, 2024 19:12
@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 force-pushed the O3-3316 branch 2 times, most recently from e5de3c9 to 63ad98e Compare September 25, 2024 10:58
@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?

src/processors/encounter/encounter-processor-helper.ts Outdated Show resolved Hide resolved
src/processors/encounter/encounter-processor-helper.ts Outdated Show resolved Hide resolved
src/adapters/encounter-diagnosis-adapter.ts Outdated Show resolved Hide resolved
src/processors/encounter/encounter-form-processor.ts Outdated Show resolved Hide resolved
src/transformers/default-schema-transformer.ts Outdated Show resolved Hide resolved
@CynthiaKamau CynthiaKamau force-pushed the O3-3316 branch 2 times, most recently from bc33d5d to 089214e Compare September 30, 2024 10:54
src/adapters/encounter-diagnoses-adapter.ts Outdated Show resolved Hide resolved
src/adapters/encounter-diagnoses-adapter.ts Outdated Show resolved Hide resolved
src/adapters/encounter-diagnoses.test.ts Outdated Show resolved Hide resolved
src/processors/encounter/encounter-form-processor.ts Outdated Show resolved Hide resolved
src/processors/encounter/encounter-form-processor.ts Outdated Show resolved Hide resolved
src/processors/encounter/encounter-processor-helper.ts Outdated Show resolved Hide resolved
src/processors/encounter/encounter-processor-helper.ts Outdated Show resolved Hide resolved
@brandones
Copy link
Contributor

Ping @samuelmale

@samuelmale
Copy link
Member

@brandones I left a few more comments for @CynthiaKamau

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.

Thanks for the great work @CynthiaKamau!

To make this more generic and practical, we need a way to extend the data source to load concepts from custom concept classes and, optionally, sets.

   questionOptions: {
      diagnosis: {
         rank?: number;
         isConfirmed?: boolean;
         conceptClasses?: Array<string>;
         conceptSet?: string;
      }
   }

cc: @ibacher

src/adapters/encounter-diagnoses-adapter.ts Outdated Show resolved Hide resolved
src/types/schema.ts Outdated Show resolved Hide resolved
@CynthiaKamau
Copy link
Contributor Author

Thanks for the great work @CynthiaKamau!

To make this more generic and practical, we need a way to extend the data source to load concepts from custom concept classes and, optionally, sets.

   questionOptions: {
      diagnosis: {
         rank?: number;
         isConfirmed?: boolean;
         conceptClasses?: Array<string>;
         conceptSet?: string;
      }
   }

cc: @ibacher

Is it supported by the backend ? I remember the question with the type problem had the same challenge

@CynthiaKamau CynthiaKamau force-pushed the O3-3316 branch 2 times, most recently from c424cf2 to f306ec1 Compare January 6, 2025 09:46
@CynthiaKamau CynthiaKamau force-pushed the O3-3316 branch 2 times, most recently from 1bbba35 to 025ca74 Compare January 9, 2025 07:36
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.

@CynthiaKamau can we add some integration test case(s)? One capturing and editing diagnosis would be super imperative!

src/adapters/encounter-diagnosis-adapter.ts Outdated Show resolved Hide resolved
src/adapters/encounter-diagnosis-adapter.ts Outdated Show resolved Hide resolved
src/processors/encounter/encounter-processor-helper.ts Outdated Show resolved Hide resolved
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.

@CynthiaKamau any chance we can add some integrational tests? Here is an example of the "Obs Group": https://github.com/openmrs/openmrs-esm-form-engine-lib/blob/main/src/form-engine.test.tsx#L878-L1007

src/adapters/encounter-diagnosis-adapter.ts Outdated Show resolved Hide resolved
src/adapters/encounter-diagnosis-adapter.ts Outdated Show resolved Hide resolved
@CynthiaKamau
Copy link
Contributor Author

@samuelmale please review the latest changes

return previousDiagnosis.value !== newValue;
}

export function voidDiagnosis(obs: OpenmrsObs) {
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
export function voidDiagnosis(obs: OpenmrsObs) {
export function voidDiagnosis(diagnosis: OpenmrsResource) {

Comment on lines 107 to 120
return Promise.resolve([
{
uuid: 'aaa-1',
display: 'Kololo',
},
{
uuid: 'aaa-2',
display: 'Naguru',
},
{
uuid: 'aaa-3',
display: 'Muyenga',
},
]);
Copy link
Member

Choose a reason for hiding this comment

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

Do you need locations for your test case?

@@ -1047,6 +1098,86 @@ describe('Form engine component', () => {
});
});

describe('Diagnisis field', () => {
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
describe('Diagnisis field', () => {
describe('Encounter Diagnosis', () => {

Comment on lines 1106 to 1107
const addButtons = screen.getAllByRole('button', { name: 'Add' });
expect(addButtons.length).toBeGreaterThan(0);
Copy link
Member

Choose a reason for hiding this comment

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

We always have a single "Add" button in a repeat section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2025-01-17 at 12 22 15

This is the form im using as my mock

});
const addButtons = screen.getAllByRole('button', { name: 'Add' });
expect(addButtons.length).toBeGreaterThan(0);
screen.debug(addButtons);
Copy link
Member

Choose a reason for hiding this comment

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

Is this a debug leftover?

Comment on lines 1127 to 1181
it('should save diagnosis field on form submission', async () => {
await act(async () => {
renderForm(null, diagnosisForm);
});
const saveEncounterMock = jest.spyOn(api, 'saveEncounter');

const combobox = await screen.findByRole('combobox', { name: /test diagnosis 1/i });
expect(combobox).toBeInTheDocument();

await userEvent.click(combobox);
await waitFor(() => {
expect(screen.getByText('stage 1')).toBeInTheDocument();
expect(screen.getByText('stage 2')).toBeInTheDocument();
});
await user.click(screen.getByText('stage 1'));
await user.click(screen.getByRole('button', { name: /save/i }));
expect(saveEncounterMock).toHaveBeenCalledTimes(1);
const [_, encounter] = saveEncounterMock.mock.calls[0];
expect(encounter.diagnoses.length).toBe(1);
expect(encounter.diagnoses[0]).toEqual({
patient: '8673ee4f-e2ab-4077-ba55-4980f408773e',
condition: null,
diagnosis: {
coded: 'stage-1-uuid',
},
certainty: 'CONFIRMED',
rank: 1,
formFieldPath: `rfe-forms-diagnosis1`,
formFieldNamespace: 'rfe-forms',
});
});
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 also add a unit test validating that the "repeating container" is properly constructed in edit mode?

@@ -276,3 +279,31 @@ function handleQuestionsWithObsComments(sectionQuestions: Array<FormField>): Arr

return augmentedQuestions;
}

function handleDiagnosis(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.

@CynthiaKamau can you also configure the field to be search-able?

question.questionOptions.isSearchable = true;

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

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.

This is close! just a few more comments.

return previousDiagnosis.value !== newValue;
}

export function voidDiagnosis(obs: OpenmrsResource) {
Copy link
Member

Choose a reason for hiding this comment

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

I guess this voids a diagnosis not an obs

@@ -1047,14 +1102,128 @@ describe('Form engine component', () => {
});
});

function renderForm(formUUID, formJson, intent?: string, mode?: SessionMode) {
describe('Encounter diagnisis', () => {
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
describe('Encounter diagnisis', () => {
describe('Encounter diagnosis, () => {

expect(screen.getByRole('button', { name: /Remove/i })).toBeInTheDocument();
});

it('should render diagnosis field', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

"should render all diagnosis fields" reads better

Comment on lines 1134 to 1137

const addButtons = screen.getAllByRole('button', { name: 'Add' });
expect(addButtons.length).toBeGreaterThan(0);
await user.click(addButtons[0]);
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 do something like this:

const testDiagnosis1AddButton = screen.getAllByRole('button', { name: 'Add' })[0];
await user.click(testDiagnosis1AddButton);

@samuelmale samuelmale dismissed their stale review January 21, 2025 11:02

Overtaken by events

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.

LGTM, thank you @CynthiaKamau for the great work!

@samuelmale samuelmale merged commit 694ab02 into main Jan 21, 2025
6 checks passed
@samuelmale samuelmale deleted the O3-3316 branch January 21, 2025 11:05
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.

5 participants