Skip to content

Commit 0653249

Browse files
committed
(feat) : Additional enhancement for cases some control are left out
1 parent 43de6ab commit 0653249

File tree

4 files changed

+70
-23
lines changed

4 files changed

+70
-23
lines changed

projects/ngx-formentry/src/form-entry/form-factory/question.factory.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,6 @@ export class QuestionFactory {
905905
toModel(schema: any, renderType: string): any {
906906
this.quetionIndex++;
907907
if (renderType === 'ui-select-extended') {
908-
console.log(schema.type);
909908
renderType = schema.type;
910909
}
911910
if (!schema.id) {

projects/ngx-formentry/src/form-entry/value-adapters/appointment-helper.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,17 @@ export interface AppointmentResponsePayload {
5555
priority: unknown | null;
5656
recurring: boolean;
5757
}
58+
/**
59+
* Interface representing the structure of an appointment payload.
60+
*/
61+
export interface AppointmentPayload {
62+
status: string;
63+
appointmentKind: string;
64+
locationUuid: string;
65+
serviceUuid: string;
66+
providers: { uuid: string }[];
67+
startDateTime: string;
68+
endDateTime: string;
69+
dateAppointmentIssued?: string;
70+
uuid?: string;
71+
}

projects/ngx-formentry/src/form-entry/value-adapters/appointment.adapter.ts

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,39 @@ import { ValueAdapter } from './value.adapter';
33
import { Form } from '../form-factory';
44
import { GroupNode, LeafNode } from '../form-factory/form-node';
55
import moment from 'moment';
6-
import { AppointmentResponsePayload } from './appointment-helper';
7-
8-
interface AppointmentPayload {
9-
[key: string]: string | { uuid: string }[];
10-
providers: Array<{ uuid: string }>;
11-
locationUuid: string;
12-
serviceUuid: string;
13-
endDateTime: string;
14-
}
6+
import {
7+
AppointmentPayload,
8+
AppointmentResponsePayload
9+
} from './appointment-helper';
1510

1611
@Injectable({
1712
providedIn: 'root'
1813
})
1914
export class AppointmentAdapter implements ValueAdapter {
15+
/**
16+
* Generates the form payload for an appointment.
17+
* @param {Form} form - The form object.
18+
* @returns {AppointmentPayload} The generated appointment payload.
19+
*/
2020
public generateFormPayload(form: Form): AppointmentPayload {
2121
const uuid = form?.valueProcessingInfo?.appointmentUuid;
22+
const dateAppointmentIssued =
23+
form?.valueProcessingInfo?.dateAppointmentIssued;
2224

2325
const questionNodes = this.findAppointmentQuestionNodes(form.rootNode);
2426
const payload = this.generateFormPayloadForQuestion(questionNodes);
25-
const appointmentPayload = uuid ? { ...payload, uuid } : payload;
26-
return appointmentPayload;
27+
28+
// If in edit mode, add the uuid to the payload
29+
if (uuid) {
30+
payload.uuid = uuid;
31+
}
32+
33+
// Add dateAppointmentIssued to the payload if it exists
34+
if (dateAppointmentIssued) {
35+
payload.dateAppointmentIssued = dateAppointmentIssued;
36+
}
37+
38+
return payload;
2739
}
2840

2941
public populateForm(form: Form, payload: AppointmentResponsePayload): void {
@@ -86,13 +98,17 @@ export class AppointmentAdapter implements ValueAdapter {
8698
return appointmentNodes;
8799
}
88100

101+
/**
102+
* Generates the form payload for appointment questions.
103+
* @param {LeafNode[]} appointmentQuestionNodes - An array of leaf nodes representing appointment questions.
104+
* @returns {AppointmentPayload} The generated appointment payload.
105+
*/
89106
private generateFormPayloadForQuestion(
90107
appointmentQuestionNodes: LeafNode[]
91108
): AppointmentPayload {
92109
const formPayload = appointmentQuestionNodes.reduce<Record<string, string>>(
93110
(payload, node) => {
94-
const appointmentKey =
95-
node.question.extras.questionOptions.appointmentKey;
111+
const { appointmentKey } = node.question.extras.questionOptions;
96112
payload[appointmentKey] = node.control.value;
97113
return payload;
98114
},
@@ -105,26 +121,37 @@ export class AppointmentAdapter implements ValueAdapter {
105121
duration,
106122
service,
107123
location,
108-
...restPayload
124+
status = 'Scheduled',
125+
appointmentKind = 'Scheduled',
126+
...restOfPayload
109127
} = formPayload;
110128

129+
const endDateTime = duration
130+
? this.calculateEndDateTime(startDateTime, parseInt(duration, 10))
131+
: moment(startDateTime).endOf('day').toISOString();
132+
111133
return {
112-
...restPayload,
134+
...restOfPayload,
135+
status,
136+
appointmentKind,
113137
locationUuid: location,
114138
serviceUuid: service,
115139
providers: [{ uuid: providers }],
116140
startDateTime: moment(startDateTime).toISOString(),
117-
endDateTime: this.calculateEndDateTime(
118-
startDateTime,
119-
parseInt(duration, 10)
120-
)
141+
endDateTime
121142
};
122143
}
123144

145+
/**
146+
* Calculates the end date and time based on the start date and time and duration.
147+
* @param {string} startDateTime - The start date and time in ISO format.
148+
* @param {number} durationMinutes - The duration in minutes.
149+
* @returns {string} The calculated end date and time in ISO format.
150+
*/
124151
private calculateEndDateTime(
125-
startDatetime: string,
152+
startDateTime: string,
126153
durationMinutes: number
127154
): string {
128-
return moment(startDatetime).add(durationMinutes, 'minutes').toISOString();
155+
return moment(startDateTime).add(durationMinutes, 'minutes').toISOString();
129156
}
130157
}

src/app/app.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,10 @@ export class AppComponent implements OnInit {
384384
encounterUuid: 'encounterUuid',
385385
providerUuid: 'providerUuid',
386386
utcOffset: '+0300',
387-
locationUuid: 'some-location-uuid'
387+
locationUuid: 'some-location-uuid',
388+
dateAppointmentIssued: new Date().toISOString()
388389
};
390+
389391
if (this.form.valid) {
390392
this.form.showErrors = false;
391393
// const payload = this.encAdapter.generateFormPayload(this.form);
@@ -399,6 +401,11 @@ export class AppComponent implements OnInit {
399401

400402
// generate patient identifiers
401403
//const patientIdenfitiers = this.patientIdenfierAdapter.generateFormPayload(this.form,this.form.valueProcessingInfo['locationUuid']);
404+
// generate appointment payload
405+
// const appointmentPayload = this.appointmentsAdapter.generateFormPayload(
406+
// this.form
407+
// );
408+
// console.log('Appointment Payload', appointmentPayload);
402409
} else {
403410
this.form.showErrors = true;
404411
this.form.markInvalidControls(this.form.rootNode);

0 commit comments

Comments
 (0)