Skip to content

Commit e847086

Browse files
Merge pull request #2131 from openmsupply/2023-rework-form-schema-list-endpoint
Mutate patient follow ups
2 parents e4cc8e0 + a7f385a commit e847086

File tree

15 files changed

+189
-180
lines changed

15 files changed

+189
-180
lines changed

client/packages/common/src/types/schema.ts

+32-3
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,12 @@ export type ForeignKeyError = DeleteInboundShipmentLineErrorInterface & DeleteIn
11991199
key: ForeignKey;
12001200
};
12011201

1202+
export type FormSchemaConnector = {
1203+
__typename: 'FormSchemaConnector';
1204+
nodes: Array<FormSchemaNode>;
1205+
totalCount: Scalars['Int']['output'];
1206+
};
1207+
12021208
export type FormSchemaFilterInput = {
12031209
id?: InputMaybe<EqualFilterStringInput>;
12041210
type?: InputMaybe<EqualFilterStringInput>;
@@ -1212,6 +1218,22 @@ export type FormSchemaNode = {
12121218
uiSchema: Scalars['JSON']['output'];
12131219
};
12141220

1221+
export type FormSchemaResponse = FormSchemaConnector;
1222+
1223+
export enum FormSchemaSortFieldInput {
1224+
Id = 'id'
1225+
}
1226+
1227+
export type FormSchemaSortInput = {
1228+
/**
1229+
* Sort query result is sorted descending or ascending (if not provided the default is
1230+
* ascending)
1231+
*/
1232+
desc?: InputMaybe<Scalars['Boolean']['input']>;
1233+
/** Sort query result by `key` */
1234+
key: FormSchemaSortFieldInput;
1235+
};
1236+
12151237
export type FullSyncStatusNode = {
12161238
__typename: 'FullSyncStatusNode';
12171239
error?: Maybe<SyncErrorNode>;
@@ -2347,7 +2369,7 @@ export type Mutations = {
23472369
*/
23482370
insertProgramEnrolment: InsertProgramEnrolmentResponse;
23492371
/**
2350-
* Inserts a new program patient, i.e. a patient the can contain additional information stored
2372+
* Inserts a new program patient, i.e. a patient that can contain additional information stored
23512373
* in a document.
23522374
*/
23532375
insertProgramPatient: InsertProgramPatientResponse;
@@ -3376,7 +3398,7 @@ export type Queries = {
33763398
documents: DocumentResponse;
33773399
encounterFields: EncounterFieldsResponse;
33783400
encounters: EncounterResponse;
3379-
formSchema?: Maybe<FormSchemaNode>;
3401+
formSchemas: FormSchemaResponse;
33803402
/** Available without authorisation in operational and initialisation states */
33813403
initialisationStatus: InitialisationStatusNode;
33823404
insertPrescription: InsertPrescriptionResponse;
@@ -3536,8 +3558,10 @@ export type QueriesEncountersArgs = {
35363558
};
35373559

35383560

3539-
export type QueriesFormSchemaArgs = {
3561+
export type QueriesFormSchemasArgs = {
35403562
filter?: InputMaybe<FormSchemaFilterInput>;
3563+
page?: InputMaybe<PaginationInput>;
3564+
sort?: InputMaybe<Array<FormSchemaSortInput>>;
35413565
};
35423566

35433567

@@ -4844,6 +4868,11 @@ export type UpdateOutboundShipmentUnallocatedLineResponseWithId = {
48444868
response: UpdateOutboundShipmentUnallocatedLineResponse;
48454869
};
48464870

4871+
/**
4872+
* All fields in the input object will be used to update the patient record.
4873+
* This means that the caller also has to provide the fields that are not going to change.
4874+
* For example, if the last_name is not provided, the last_name in the patient record will be cleared.
4875+
*/
48474876
export type UpdatePatientInput = {
48484877
code: Scalars['String']['input'];
48494878
code2?: InputMaybe<Scalars['String']['input']>;

client/packages/programs/src/api/api.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,12 @@ export const getClinicianQueries = (sdk: Sdk, storeId: string) => ({
360360
export const getFormSchemaQueries = (sdk: Sdk) => ({
361361
get: {
362362
byType: async (type: string): Promise<FormSchemaFragment | undefined> => {
363-
const result = await sdk.formSchema({
363+
const result = await sdk.formSchemas({
364364
filter: { type: { equalTo: type } },
365365
});
366366

367-
if (!result.formSchema) {
368-
return undefined;
369-
}
370-
371-
if (result.formSchema?.__typename === 'FormSchemaNode') {
372-
return result.formSchema;
367+
if (result.formSchemas?.__typename === 'FormSchemaConnector') {
368+
return result.formSchemas.nodes[0];
373369
}
374370

375371
throw new Error('Error querying form schema');

client/packages/programs/src/api/operations.generated.ts

+19-14
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ export type CliniciansQuery = { __typename: 'Queries', clinicians: { __typename:
178178

179179
export type FormSchemaFragment = { __typename: 'FormSchemaNode', id: string, jsonSchema: any, type: string, uiSchema: any };
180180

181-
export type FormSchemaQueryVariables = Types.Exact<{
181+
export type FormSchemasQueryVariables = Types.Exact<{
182182
filter?: Types.InputMaybe<Types.FormSchemaFilterInput>;
183183
}>;
184184

185185

186-
export type FormSchemaQuery = { __typename: 'Queries', formSchema?: { __typename: 'FormSchemaNode', id: string, jsonSchema: any, type: string, uiSchema: any } | null };
186+
export type FormSchemasQuery = { __typename: 'Queries', formSchemas: { __typename: 'FormSchemaConnector', nodes: Array<{ __typename: 'FormSchemaNode', id: string, jsonSchema: any, type: string, uiSchema: any }> } };
187187

188188
export type ActiveProgramEventsQueryVariables = Types.Exact<{
189189
at?: Types.InputMaybe<Types.Scalars['String']['input']>;
@@ -603,11 +603,16 @@ export const CliniciansDocument = gql`
603603
}
604604
}
605605
${ClinicianFragmentDoc}`;
606-
export const FormSchemaDocument = gql`
607-
query formSchema($filter: FormSchemaFilterInput) {
608-
formSchema(filter: $filter) {
609-
__typename
610-
...FormSchema
606+
export const FormSchemasDocument = gql`
607+
query formSchemas($filter: FormSchemaFilterInput) {
608+
formSchemas(filter: $filter) {
609+
... on FormSchemaConnector {
610+
__typename
611+
nodes {
612+
__typename
613+
...FormSchema
614+
}
615+
}
611616
}
612617
}
613618
${FormSchemaFragmentDoc}`;
@@ -690,8 +695,8 @@ export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper =
690695
clinicians(variables: CliniciansQueryVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<CliniciansQuery> {
691696
return withWrapper((wrappedRequestHeaders) => client.request<CliniciansQuery>(CliniciansDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'clinicians', 'query');
692697
},
693-
formSchema(variables?: FormSchemaQueryVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<FormSchemaQuery> {
694-
return withWrapper((wrappedRequestHeaders) => client.request<FormSchemaQuery>(FormSchemaDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'formSchema', 'query');
698+
formSchemas(variables?: FormSchemasQueryVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<FormSchemasQuery> {
699+
return withWrapper((wrappedRequestHeaders) => client.request<FormSchemasQuery>(FormSchemasDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'formSchemas', 'query');
695700
},
696701
activeProgramEvents(variables: ActiveProgramEventsQueryVariables, requestHeaders?: GraphQLClientRequestHeaders): Promise<ActiveProgramEventsQuery> {
697702
return withWrapper((wrappedRequestHeaders) => client.request<ActiveProgramEventsQuery>(ActiveProgramEventsDocument, variables, {...requestHeaders, ...wrappedRequestHeaders}), 'activeProgramEvents', 'query');
@@ -993,16 +998,16 @@ export const mockCliniciansQuery = (resolver: ResponseResolver<GraphQLRequest<Cl
993998
* @param resolver a function that accepts a captured request and may return a mocked response.
994999
* @see https://mswjs.io/docs/basics/response-resolver
9951000
* @example
996-
* mockFormSchemaQuery((req, res, ctx) => {
1001+
* mockFormSchemasQuery((req, res, ctx) => {
9971002
* const { filter } = req.variables;
9981003
* return res(
999-
* ctx.data({ formSchema })
1004+
* ctx.data({ formSchemas })
10001005
* )
10011006
* })
10021007
*/
1003-
export const mockFormSchemaQuery = (resolver: ResponseResolver<GraphQLRequest<FormSchemaQueryVariables>, GraphQLContext<FormSchemaQuery>, any>) =>
1004-
graphql.query<FormSchemaQuery, FormSchemaQueryVariables>(
1005-
'formSchema',
1008+
export const mockFormSchemasQuery = (resolver: ResponseResolver<GraphQLRequest<FormSchemasQueryVariables>, GraphQLContext<FormSchemasQuery>, any>) =>
1009+
graphql.query<FormSchemasQuery, FormSchemasQueryVariables>(
1010+
'formSchemas',
10061011
resolver
10071012
)
10081013

client/packages/programs/src/api/operations.graphql

+9-4
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,15 @@ fragment FormSchema on FormSchemaNode {
430430
uiSchema
431431
}
432432

433-
query formSchema($filter: FormSchemaFilterInput) {
434-
formSchema(filter: $filter) {
435-
__typename
436-
...FormSchema
433+
query formSchemas($filter: FormSchemaFilterInput) {
434+
formSchemas(filter: $filter) {
435+
... on FormSchemaConnector {
436+
__typename
437+
nodes {
438+
__typename
439+
...FormSchema
440+
}
441+
}
437442
}
438443
}
439444

client/packages/system/src/Patient/CreatePatientModal/DefaultCreatePatientJsonForm.ts

-102
This file was deleted.

client/packages/system/src/Patient/CreatePatientModal/PatientFormTab.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import {
77
usePatientStore,
88
} from '@openmsupply-client/programs';
99
import { PatientPanel } from './PatientPanel';
10-
import { createPatient, createPatientUI } from './DefaultCreatePatientJsonForm';
1110
import { ObjUtils } from '@common/utils';
1211

12+
import defaultPatientSchema from '../DefaultPatientSchema.json';
13+
import defaultPatientUISchema from '../DefaultPatientUISchema.json';
14+
import { BasicSpinner } from '@openmsupply-client/common';
15+
1316
type Patient = {
1417
code?: string;
1518
code2?: string;
@@ -49,12 +52,14 @@ export const PatientFormTab: FC<PatientPanel> = ({ patient, value }) => {
4952
}
5053
};
5154

55+
if (isLoading) return <BasicSpinner />;
56+
5257
return (
5358
<PatientPanel value={value} patient={patient}>
5459
<JsonForm
5560
data={(patient as JsonData) || {}}
56-
jsonSchema={patientCreationUI?.jsonSchema || createPatient}
57-
uiSchema={patientCreationUI?.uiSchema || createPatientUI}
61+
jsonSchema={patientCreationUI?.jsonSchema || defaultPatientSchema}
62+
uiSchema={patientCreationUI?.uiSchema || defaultPatientUISchema}
5863
isError={patientCreationUI ? isError : false}
5964
isLoading={patientCreationUI ? isLoading : false}
6065
updateData={setPatient}

client/packages/system/src/Patient/PatientView/DefaultPatientSchema.json client/packages/system/src/Patient/DefaultPatientSchema.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
},
2323
"code": {
2424
"description": "Patient code, e.g. national id or other patient identifier",
25-
"type": "string"
25+
"type": "string",
26+
"minLength": 1
2627
},
2728
"code2": {
2829
"description": "Secondary patient code, e.g. another type of health id",

client/packages/system/src/Patient/PatientView/PatientView.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
useAuthContext,
1111
InsertPatientInput,
1212
UpdatePatientInput,
13+
BasicSpinner,
1314
} from '@openmsupply-client/common';
1415
import { usePatient } from '../api';
1516
import { AppBarButtons } from './AppBarButtons';
@@ -33,8 +34,8 @@ import {
3334
} from '@openmsupply-client/programs';
3435
import { Footer } from './Footer';
3536

36-
import defaultPatientSchema from './DefaultPatientSchema.json';
37-
import defaultPatientUISchema from './DefaultPatientUISchema.json';
37+
import defaultPatientSchema from '../DefaultPatientSchema.json';
38+
import defaultPatientUISchema from '../DefaultPatientUISchema.json';
3839

3940
const DEFAULT_SCHEMA: SchemaData = {
4041
formSchemaId: undefined,
@@ -96,7 +97,7 @@ const PatientDetailView = ({
9697
const patientId = usePatient.utils.id();
9798
const { data: currentPatient } = usePatient.document.get(patientId);
9899

99-
const { data: patientRegistries } =
100+
const { data: patientRegistries, isLoading } =
100101
useDocumentRegistry.get.documentRegistries({
101102
filter: {
102103
documentType: { equalTo: 'Patient' },
@@ -199,6 +200,8 @@ const PatientDetailView = ({
199200
title: t('heading.are-you-sure'),
200201
});
201202

203+
if (isLoading) return <BasicSpinner />;
204+
202205
return (
203206
<Box flex={1} display="flex" justifyContent="center">
204207
<Box style={{ maxWidth: 1200, flex: 1 }}>{JsonForm}</Box>

0 commit comments

Comments
 (0)