Skip to content

Commit 95e78ee

Browse files
Merge pull request #2122 from openmsupply/2023-mutate-patient-without-program-config
2023 mutate patient without program config
2 parents 9c5277b + e847086 commit 95e78ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1259
-426
lines changed

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

+89-11
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>;
@@ -1522,10 +1544,13 @@ export type InsertOutboundShipmentUnallocatedLineResponseWithId = {
15221544
};
15231545

15241546
export type InsertPatientInput = {
1525-
/** Patient document data */
1526-
data: Scalars['JSON']['input'];
1527-
/** The schema id used for the patient data */
1528-
schemaId: Scalars['String']['input'];
1547+
code: Scalars['String']['input'];
1548+
code2?: InputMaybe<Scalars['String']['input']>;
1549+
dateOfBirth?: InputMaybe<Scalars['NaiveDate']['input']>;
1550+
firstName?: InputMaybe<Scalars['String']['input']>;
1551+
gender?: InputMaybe<GenderInput>;
1552+
id: Scalars['String']['input'];
1553+
lastName?: InputMaybe<Scalars['String']['input']>;
15291554
};
15301555

15311556
export type InsertPatientResponse = PatientNode;
@@ -1590,6 +1615,15 @@ export type InsertProgramEnrolmentInput = {
15901615

15911616
export type InsertProgramEnrolmentResponse = ProgramEnrolmentNode;
15921617

1618+
export type InsertProgramPatientInput = {
1619+
/** Patient document data */
1620+
data: Scalars['JSON']['input'];
1621+
/** The schema id used for the patient data */
1622+
schemaId: Scalars['String']['input'];
1623+
};
1624+
1625+
export type InsertProgramPatientResponse = PatientNode;
1626+
15931627
export type InsertProgramRequestRequisitionError = {
15941628
__typename: 'InsertProgramRequestRequisitionError';
15951629
error: InsertProgramRequestRequisitionErrorInterface;
@@ -2325,6 +2359,7 @@ export type Mutations = {
23252359
insertOutboundShipmentLine: InsertOutboundShipmentLineResponse;
23262360
insertOutboundShipmentServiceLine: InsertOutboundShipmentServiceLineResponse;
23272361
insertOutboundShipmentUnallocatedLine: InsertOutboundShipmentUnallocatedLineResponse;
2362+
/** Inserts a new patient (without document data) */
23282363
insertPatient: InsertPatientResponse;
23292364
insertPrescription: InsertPrescriptionResponse;
23302365
insertPrescriptionLine: InsertPrescriptionLineResponse;
@@ -2333,12 +2368,18 @@ export type Mutations = {
23332368
* Every patient can only have one program document of each program type.
23342369
*/
23352370
insertProgramEnrolment: InsertProgramEnrolmentResponse;
2371+
/**
2372+
* Inserts a new program patient, i.e. a patient that can contain additional information stored
2373+
* in a document.
2374+
*/
2375+
insertProgramPatient: InsertProgramPatientResponse;
23362376
insertProgramRequestRequisition: InsertProgramRequestRequisitionResponse;
23372377
insertRepack: InsertRepackResponse;
23382378
insertRequestRequisition: InsertRequestRequisitionResponse;
23392379
insertRequestRequisitionLine: InsertRequestRequisitionLineResponse;
23402380
insertStocktake: InsertStocktakeResponse;
23412381
insertStocktakeLine: InsertStocktakeLineResponse;
2382+
/** Links a patient to a store and thus effectively to a site */
23422383
linkPatientToStore: LinkPatientToStoreResponse;
23432384
manualSync: Scalars['String']['output'];
23442385
/** Set supply quantity to requested quantity */
@@ -2357,11 +2398,17 @@ export type Mutations = {
23572398
updateOutboundShipmentName: UpdateOutboundShipmentNameResponse;
23582399
updateOutboundShipmentServiceLine: UpdateOutboundShipmentServiceLineResponse;
23592400
updateOutboundShipmentUnallocatedLine: UpdateOutboundShipmentUnallocatedLineResponse;
2401+
/** Updates a new patient (without document data) */
23602402
updatePatient: UpdatePatientResponse;
23612403
updatePrescription: UpdatePrescriptionResponse;
23622404
updatePrescriptionLine: UpdatePrescriptionLineResponse;
23632405
/** Updates an existing program document belonging to a patient. */
23642406
updateProgramEnrolment: UpdateProgramEnrolmentResponse;
2407+
/**
2408+
* Updates a new program patient, i.e. a patient the can contain additional information stored
2409+
* in a document.
2410+
*/
2411+
updateProgramPatient: UpdateProgramPatientResponse;
23652412
updateRequestRequisition: UpdateRequestRequisitionResponse;
23662413
updateRequestRequisitionLine: UpdateRequestRequisitionLineResponse;
23672414
updateResponseRequisition: UpdateResponseRequisitionResponse;
@@ -2631,6 +2678,12 @@ export type MutationsInsertProgramEnrolmentArgs = {
26312678
};
26322679

26332680

2681+
export type MutationsInsertProgramPatientArgs = {
2682+
input: InsertProgramPatientInput;
2683+
storeId: Scalars['String']['input'];
2684+
};
2685+
2686+
26342687
export type MutationsInsertProgramRequestRequisitionArgs = {
26352688
input: InsertProgramRequestRequisitionInput;
26362689
storeId: Scalars['String']['input'];
@@ -2786,6 +2839,12 @@ export type MutationsUpdateProgramEnrolmentArgs = {
27862839
};
27872840

27882841

2842+
export type MutationsUpdateProgramPatientArgs = {
2843+
input: UpdateProgramPatientInput;
2844+
storeId: Scalars['String']['input'];
2845+
};
2846+
2847+
27892848
export type MutationsUpdateRequestRequisitionArgs = {
27902849
input: UpdateRequestRequisitionInput;
27912850
storeId: Scalars['String']['input'];
@@ -3339,7 +3398,7 @@ export type Queries = {
33393398
documents: DocumentResponse;
33403399
encounterFields: EncounterFieldsResponse;
33413400
encounters: EncounterResponse;
3342-
formSchema?: Maybe<FormSchemaNode>;
3401+
formSchemas: FormSchemaResponse;
33433402
/** Available without authorisation in operational and initialisation states */
33443403
initialisationStatus: InitialisationStatusNode;
33453404
insertPrescription: InsertPrescriptionResponse;
@@ -3499,8 +3558,10 @@ export type QueriesEncountersArgs = {
34993558
};
35003559

35013560

3502-
export type QueriesFormSchemaArgs = {
3561+
export type QueriesFormSchemasArgs = {
35033562
filter?: InputMaybe<FormSchemaFilterInput>;
3563+
page?: InputMaybe<PaginationInput>;
3564+
sort?: InputMaybe<Array<FormSchemaSortInput>>;
35043565
};
35053566

35063567

@@ -4807,12 +4868,19 @@ export type UpdateOutboundShipmentUnallocatedLineResponseWithId = {
48074868
response: UpdateOutboundShipmentUnallocatedLineResponse;
48084869
};
48094870

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+
*/
48104876
export type UpdatePatientInput = {
4811-
/** Patient document data */
4812-
data: Scalars['JSON']['input'];
4813-
parent: Scalars['String']['input'];
4814-
/** The schema id used for the patient data */
4815-
schemaId: Scalars['String']['input'];
4877+
code: Scalars['String']['input'];
4878+
code2?: InputMaybe<Scalars['String']['input']>;
4879+
dateOfBirth?: InputMaybe<Scalars['NaiveDate']['input']>;
4880+
firstName?: InputMaybe<Scalars['String']['input']>;
4881+
gender?: InputMaybe<GenderInput>;
4882+
id: Scalars['String']['input'];
4883+
lastName?: InputMaybe<Scalars['String']['input']>;
48164884
};
48174885

48184886
export type UpdatePatientResponse = PatientNode;
@@ -4886,6 +4954,16 @@ export type UpdateProgramEnrolmentInput = {
48864954

48874955
export type UpdateProgramEnrolmentResponse = ProgramEnrolmentNode;
48884956

4957+
export type UpdateProgramPatientInput = {
4958+
/** Patient document data */
4959+
data: Scalars['JSON']['input'];
4960+
parent: Scalars['String']['input'];
4961+
/** The schema id used for the patient data */
4962+
schemaId: Scalars['String']['input'];
4963+
};
4964+
4965+
export type UpdateProgramPatientResponse = PatientNode;
4966+
48894967
export type UpdateRequestRequisitionError = {
48904968
__typename: 'UpdateRequestRequisitionError';
48914969
error: UpdateRequestRequisitionErrorInterface;
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './common';
22
export * from './useJsonForms';
3+
export * from './useDocumentFormData';

client/packages/programs/src/JsonForms/useDocumentLoader.ts client/packages/programs/src/JsonForms/useDocumentFormData.ts

+28-19
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,33 @@ import {
22
useDocument,
33
FormInputData,
44
SchemaData,
5+
JsonFormData,
56
} from '@openmsupply-client/programs';
67
import { useEffect, useState } from 'react';
7-
import { JsonData } from './common';
88

9-
export interface DocumentDataResponse {
10-
isLoading: boolean;
11-
error?: string;
12-
documentId?: string;
13-
data?: JsonData;
14-
schema?: SchemaData;
15-
}
9+
export type SavedDocument = {
10+
name: string;
11+
};
12+
13+
export type SaveDocumentMutation = (
14+
jsonData: unknown,
15+
formSchemaId: string,
16+
parent?: string
17+
) => Promise<SavedDocument>;
18+
19+
export type DocumentFormData = JsonFormData<SavedDocument>;
1620

17-
// eslint-disable-next-line valid-jsdoc
1821
/**
1922
* Manages the document data for a JSON form.
2023
* Data is taken either:
2124
* - from an api call (if the document already exist)
22-
* - from the createDoc (if the document is going to be created)
25+
* - from the formInputData (e.g. if the document is going to be created)
2326
*/
24-
export const useDocumentLoader = (
27+
export const useDocumentDataAccessor = (
2528
docName: string | undefined,
26-
createDoc?: FormInputData
27-
): DocumentDataResponse => {
29+
formInputData?: FormInputData,
30+
handleSave?: SaveDocumentMutation
31+
): DocumentFormData => {
2832
const [error, setError] = useState<string | undefined>();
2933
// the current document id (undefined if its a new document)
3034
const [documentId, setDocumentId] = useState<string | undefined>();
@@ -68,18 +72,23 @@ export const useDocumentLoader = (
6872
}
6973
}, [databaseResponse]);
7074

71-
// user createDoc if there is one
75+
// use schema from the formInputData if there is one
7276
useEffect(() => {
73-
if (createDoc) {
74-
setSchema(createDoc.schema);
77+
if (formInputData) {
78+
setSchema(formInputData.schema);
7579
}
76-
}, [createDoc]);
80+
}, [formInputData]);
7781

7882
return {
7983
isLoading,
8084
error,
81-
documentId,
82-
data: createDoc?.data ?? databaseResponse?.data,
85+
loadedData: formInputData?.data ?? databaseResponse?.data,
86+
isCreating: formInputData?.isCreating ?? false,
8387
schema,
88+
save: handleSave
89+
? async (data: unknown) => {
90+
return await handleSave(data, schema.formSchemaId ?? '', documentId);
91+
}
92+
: undefined,
8493
};
8594
};

0 commit comments

Comments
 (0)