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

(fix) O3-2654: Process visit attributes separately from the visit payload #1616

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9879415
fix: fix error can't update visit attributes
usamaidrsk Jan 4, 2024
e1cb687
fix: fix content-type in post headers
usamaidrsk Jan 4, 2024
ba7c760
fix: update visit attributes after details update
usamaidrsk Jan 5, 2024
03c8a6d
refactor: handle edit, create, and delete visit attributes
usamaidrsk Jan 24, 2024
5384299
fix: tests
usamaidrsk Jan 24, 2024
50edb4f
refactor: update checks for if attribute was updated or not
usamaidrsk Jan 29, 2024
963dc59
refactor: don't close workspace if there are erros on editing attributes
usamaidrsk Jan 31, 2024
e32b4df
refactor: extract translations
usamaidrsk Jan 31, 2024
8935fe2
fix: fix failing tests
usamaidrsk Jan 31, 2024
7485e79
refactor: improve code
usamaidrsk Feb 1, 2024
1365fb2
add unit tests
usamaidrsk Feb 12, 2024
368d7d7
fix tests
usamaidrsk Feb 12, 2024
67b7082
Merge branch 'main' into fix-error-on-update-visit-attributes
usamaidrsk Mar 11, 2024
831c818
Update test labels
jayasanka-sack Mar 12, 2024
5aa9965
Remove magic uuids
jayasanka-sack Mar 12, 2024
77e61fb
refactor: remove insurance number magic uuid
usamaidrsk Mar 26, 2024
310bd42
Merge branch 'main' into fix-error-on-update-visit-attributes
usamaidrsk May 13, 2024
5dcf38d
Merge remote-tracking branch 'origin/fix-error-on-update-visit-attrib…
usamaidrsk May 13, 2024
c6436d8
fix: fix build fail
usamaidrsk May 13, 2024
a883e60
fix: fix tests
usamaidrsk May 13, 2024
48cfa48
Merge branch 'main' into fix-error-on-update-visit-attributes
usamaidrsk May 22, 2024
252be8e
refactor: remove none en translation updates
usamaidrsk May 23, 2024
9e4068a
refactor: fix error message on couldn't create attribute
usamaidrsk May 23, 2024
3bb11b9
Merge branch 'main' into fix-error-on-update-visit-attributes
usamaidrsk May 23, 2024
d401423
fix: fix failing tests
usamaidrsk May 23, 2024
f5a83d4
Merge branch 'main' into fix-error-on-update-visit-attributes
usamaidrsk May 27, 2024
479329a
refactor: code cleanup
usamaidrsk May 27, 2024
254a08c
refactor: fix visitattributetype endpoint
usamaidrsk May 27, 2024
07c72e4
refactor: code cleanup
usamaidrsk May 27, 2024
810c07c
fix: fix tests
usamaidrsk May 27, 2024
9677331
Fixup
denniskigen May 27, 2024
56af777
Attempt to fix flaky test
denniskigen May 28, 2024
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
151 changes: 151 additions & 0 deletions __mocks__/visits.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,154 @@ export const mockEncounters2 = [
resourceVersion: '2.2',
},
];

export const mockVisitWithAttributes = {
...mockVisits.data.results[0],
attributes: [
{
attributeType: {
uuid: 'aac48226-d143-4274-80e0-264db4e368ee',
display: 'Insurance Policy Number',
links: [
{
rel: 'self',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/visitattributetype/aac48226-d143-4274-80e0-264db4e368ee',
resourceAlias: 'visitattributetype',
},
],
},
display: 'Insurance Policy Number: 832832',
uuid: 'd6d7d26a-5975-4f03-8abb-db073c948897',
value: '832832',
},
{
attributeType: {
uuid: '57ea0cbb-064f-4d09-8cf4-e8228700491c',
display: 'Punctuality',
links: [
{
rel: 'self',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/visitattributetype/57ea0cbb-064f-4d09-8cf4-e8228700491c',
resourceAlias: 'visitattributetype',
},
],
},
display: 'Punctuality: Concept #1092',
uuid: 'c98e66d7-7db5-47ae-b46f-91a0f3b6dda1',
value: {
uuid: '66cdc0a1-aa19-4676-af51-80f66d78d9eb',
display: 'On time',
name: {
display: 'On time',
uuid: '03f6dd3e-d270-3ea6-a833-f867e49a40bb',
name: 'On time',
locale: 'en',
localePreferred: true,
conceptNameType: 'FULLY_SPECIFIED',
links: [
{
rel: 'self',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/concept/66cdc0a1-aa19-4676-af51-80f66d78d9eb/name/03f6dd3e-d270-3ea6-a833-f867e49a40bb',
resourceAlias: 'name',
},
{
rel: 'full',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/concept/66cdc0a1-aa19-4676-af51-80f66d78d9eb/name/03f6dd3e-d270-3ea6-a833-f867e49a40bb?v=full',
resourceAlias: 'name',
},
],
resourceVersion: '1.9',
},
datatype: {
uuid: '8d4a4c94-c2cc-11de-8d13-0010c6dffd0f',
display: 'N/A',
links: [
{
rel: 'self',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/conceptdatatype/8d4a4c94-c2cc-11de-8d13-0010c6dffd0f',
resourceAlias: 'conceptdatatype',
},
],
},
conceptClass: {
uuid: '8d492774-c2cc-11de-8d13-0010c6dffd0f',
display: 'Misc',
links: [
{
rel: 'self',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/conceptclass/8d492774-c2cc-11de-8d13-0010c6dffd0f',
resourceAlias: 'conceptclass',
},
],
},
set: false,
version: null,
retired: false,
names: [
{
uuid: 'dc2adaff-ae4d-30d2-9ce8-0b6ae2518f11',
display: 'À temps',
links: [
{
rel: 'self',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/concept/66cdc0a1-aa19-4676-af51-80f66d78d9eb/name/dc2adaff-ae4d-30d2-9ce8-0b6ae2518f11',
resourceAlias: 'name',
},
],
},
{
uuid: '03f6dd3e-d270-3ea6-a833-f867e49a40bb',
display: 'On time',
links: [
{
rel: 'self',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/concept/66cdc0a1-aa19-4676-af51-80f66d78d9eb/name/03f6dd3e-d270-3ea6-a833-f867e49a40bb',
resourceAlias: 'name',
},
],
},
{
uuid: '9c3ecda9-dd54-331e-aebf-d7426e358752',
display: 'À temps',
links: [
{
rel: 'self',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/concept/66cdc0a1-aa19-4676-af51-80f66d78d9eb/name/9c3ecda9-dd54-331e-aebf-d7426e358752',
resourceAlias: 'name',
},
],
},
{
uuid: '0ab86d36-0a8f-38f9-963e-8138251fc619',
display: 'On time',
links: [
{
rel: 'self',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/concept/66cdc0a1-aa19-4676-af51-80f66d78d9eb/name/0ab86d36-0a8f-38f9-963e-8138251fc619',
resourceAlias: 'name',
},
],
},
],
descriptions: [],
mappings: [],
answers: [],
setMembers: [],
attributes: [],
links: [
{
rel: 'self',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/concept/66cdc0a1-aa19-4676-af51-80f66d78d9eb',
resourceAlias: 'concept',
},
{
rel: 'full',
uri: 'http://dev3.openmrs.org/openmrs/ws/rest/v1/concept/66cdc0a1-aa19-4676-af51-80f66d78d9eb?v=full',
resourceAlias: 'concept',
},
],
resourceVersion: '2.0',
},
},
]
}
6 changes: 3 additions & 3 deletions e2e/specs/visit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('Start and end a visit', async ({ page }) => {
await chartPage.goTo(patient.uuid);
});

await test.step('And I click on the `Start a visit` button ', async () => {
await test.step('And I click on the `Start visit` button ', async () => {
await chartPage.page.getByRole('button', { name: /start a visit/i }).click();
});

Expand All @@ -33,7 +33,7 @@ test('Start and end a visit', async ({ page }) => {
await expect(chartPage.page.getByLabel(/Offline Visit/i)).toBeVisible();
await expect(chartPage.page.getByLabel(/Group Session/i)).toBeVisible();
await expect(chartPage.page.getByRole('button', { name: /discard/i })).toBeVisible();
await expect(chartPage.page.locator('form').getByRole('button', { name: /start a visit/i })).toBeVisible();
await expect(chartPage.page.locator('form').getByRole('button', { name: /start visit/i })).toBeVisible();
});

await test.step('When I select the visit type: `OPD Visit`', async () => {
Expand All @@ -43,7 +43,7 @@ test('Start and end a visit', async ({ page }) => {
await test.step('And I click on the `Start Visit` button', async () => {
await chartPage.page
.locator('form')
.getByRole('button', { name: /start a visit/i })
.getByRole('button', { name: /start visit/i })
.click();
});

Expand Down
12 changes: 6 additions & 6 deletions packages/esm-patient-chart-app/src/root.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
@use '@carbon/styles/scss/spacing';
@use '@carbon/styles/scss/type';
@import '@openmrs/esm-styleguide/src/vars';
@use '@carbon/colors';
@use '@carbon/layout';
@use '@carbon/type';

.patientChartWrapper {
display: flex;
position: relative;
}

.patientChartWrapper {
&>nav {
& > nav {
padding-bottom: 3rem;
scrollbar-width: none;
}
Expand Down Expand Up @@ -56,11 +56,11 @@
}

.text01 {
color: $ui-05;
color: colors.$gray-100;
}

.text02 {
color: $text-02;
color: colors.$gray-70;
}

.label01 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react';
import { type FetchResponse, openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
import { useEffect, useMemo } from 'react';
import useSWRImmutable from 'swr/immutable';

interface VisitAttributeType {
Expand Down Expand Up @@ -34,25 +34,46 @@ interface Concept {
const visitAttributeTypeCustomRepresentation =
'custom:(uuid,display,name,description,datatypeClassname,datatypeConfig)';

export function useVisitAttributeTypes() {
const { data, error, isLoading } = useSWRImmutable<FetchResponse<{ results: VisitAttributeType[] }>, Error>(
`/ws/rest/v1/visitattributetype?v=${visitAttributeTypeCustomRepresentation}`,
openmrsFetch,
);

if (error) {
console.error('Failed to fetch visit attribute types: ', error);
}

const results = useMemo(
() => ({
isLoading,
error,
visitAttributeTypes: data?.data?.results ?? [],
}),
[data, error, isLoading],
);

return results;
}

export function useVisitAttributeType(uuid) {
const { data, error, isLoading } = useSWRImmutable<FetchResponse<VisitAttributeType>, Error>(
`${restBaseUrl}/visitattributetype/${uuid}?v=${visitAttributeTypeCustomRepresentation}`,
openmrsFetch,
);

useEffect(() => {
if (error) {
console.error(error);
}
}, [error]);
if (error) {
console.error(`Failed to fetch visit attribute type ${uuid}: `, error);
}

const results = useMemo(() => {
return {
const results = useMemo(
() => ({
isLoading,
error: error,
data: data?.data,
};
}, [data, error, isLoading]);
}),
[data, error, isLoading],
);

return results;
}
Expand All @@ -63,20 +84,19 @@ export function useConceptAnswersForVisitAttributeType(conceptUuid) {
openmrsFetch,
);

useEffect(() => {
if (error) {
console.error(error);
}
}, [error]);
if (error) {
console.error(`Failed to fetch concept answers for visit attribute type ${conceptUuid}: `, error);
}

const results = useMemo(() => {
return {
const results = useMemo(
() => ({
isLoading,
error: error,
data: data?.data,
answers: data?.data?.answers,
};
}, [data, error, isLoading]);
}),
[data, error, isLoading],
);

return results;
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ const AttributeTypeField: React.FC<AttributeTypeFieldProps> = ({
return (
<TextInput
{...fieldProps}
id={uuid}
labelText={labelText}
placeholder={labelText}
invalid={!!errors.visitAttributes?.[uuid]}
invalidText={errors.visitAttributes?.[uuid]?.message}
/>
Expand Down
Loading
Loading