pha-hermes 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,9 @@ import axios, { AxiosInstance } from 'axios'
2
2
  import { SFAuthenticator } from './auth/auth'
3
3
  import { SFTimesheetClient } from './timesheet/timesheetClient'
4
4
  import { SFPractitionerClient } from './practitioner/practitionerClient'
5
- import { Role, Workorder } from '../models'
5
+ import { Role } from '../models'
6
+ import { SFWorkorderClient } from './workorder/workorderClient'
7
+
6
8
  export const SF_API_VERSION: string = 'v57.0'
7
9
 
8
10
  export class SFApiClient {
@@ -11,6 +13,7 @@ export class SFApiClient {
11
13
  private authenticator: SFAuthenticator
12
14
  private baseUrl: string
13
15
  timesheetClient: SFTimesheetClient
16
+ workorderClient: SFWorkorderClient
14
17
  practitionerClient: SFPractitionerClient
15
18
 
16
19
  constructor(baseUrl?: string) {
@@ -19,6 +22,7 @@ export class SFApiClient {
19
22
  baseUrl ?? 'https://do0000000d247eaa--phealth.sandbox.my.salesforce.com'
20
23
  this.authenticator = new SFAuthenticator(this.axiosInstance, this.baseUrl)
21
24
  this.timesheetClient = new SFTimesheetClient(this.axiosInstance)
25
+ this.workorderClient = new SFWorkorderClient(this.axiosInstance)
22
26
  this.practitionerClient = new SFPractitionerClient(this.axiosInstance)
23
27
  }
24
28
 
@@ -34,37 +38,6 @@ export class SFApiClient {
34
38
  return this.instance
35
39
  }
36
40
 
37
- async fetchWorkOrders(assignedStaffId?: string): Promise<Workorder[]> {
38
- try {
39
- const url = `/services/data/${SF_API_VERSION}/query`
40
- const query = assignedStaffId
41
- ? `SELECT Id, HospitalID__c, HospitalName__c, ProfessionalDesignation__c, Personnel__c, startdate__c, EndDate__c, CreatedDate, LastModifiedDate FROM WorkOrder__c WHERE Personnel__c = '${assignedStaffId}'`
42
- : `SELECT Id, HospitalID__c, HospitalName__c, ProfessionalDesignation__c, Personnel__c, startdate__c, EndDate__c, CreatedDate, LastModifiedDate FROM WorkOrder__c`
43
- return await this.axiosInstance
44
- .get(url, {
45
- params: { q: query }
46
- })
47
- .then(({ data: { records } }) =>
48
- records.map(
49
- (record): Workorder => ({
50
- id: record.Id,
51
- establishmentId: record.HospitalID__c,
52
- establishmentName: record.HospitalName__c,
53
- role: record.ProfessionalDesignation__c,
54
- assignedStaffId: record.Personnel__c,
55
- startDate: new Date(record.startdate__c),
56
- endDate: new Date(record.EndDate__c),
57
- createdAt: new Date(record.CreatedDate),
58
- updatedAt: new Date(record.LastModifiedDate)
59
- })
60
- )
61
- )
62
- } catch (error) {
63
- console.error('Error fetching work orders: ', error.message)
64
- throw error
65
- }
66
- }
67
-
68
41
  async fetchRoles(): Promise<Role[]> {
69
42
  try {
70
43
  const url = `/services/data/${SF_API_VERSION}/query`
@@ -1,98 +1,132 @@
1
- import { AxiosInstance } from 'axios'
2
- import { TimesheetDayEntry } from '../../models'
3
- import { SF_API_VERSION } from '../apiClient'
4
-
5
- export class SFTimesheetClient {
6
- private axiosInstance: AxiosInstance
7
-
8
- constructor(axiosInstance: AxiosInstance) {
9
- this.axiosInstance = axiosInstance
10
- }
11
-
12
- async updateTimesheetHour(timesheetHourId: string, timesheet: TimesheetDayEntry) {
13
- try {
14
- const url = `/services/data/${SF_API_VERSION}/sobjects/TimeSheetHour__c/${timesheetHourId}`
15
- const response = await this.axiosInstance.patch(url, {
16
- Date__c: timesheet.date,
17
- Callback__c: timesheet.callbackHours,
18
- HoursEBAdjusted__c: timesheet.regularHours,
19
- Misc__c: timesheet.miscHours,
20
- OT1__c: timesheet.overtime1Hours,
21
- OT2__c: timesheet.overtime2Hours,
22
- OnCall__c: timesheet.onCallHours,
23
- Misc1__c: timesheet.misc1HoursA,
24
- Misc_1_Hours__c: timesheet.misc1HoursB,
25
- Misc_2_Hours__c: timesheet.misc2Hours,
26
- Misc_3_Hours__c: timesheet.misc3Hours,
27
- Misc_4_Hours__c: timesheet.misc4Hours,
28
- Stat1__c: timesheet.stat1Hours,
29
- Stat2__c: timesheet.stat2Hours,
30
- In_Charge__c: timesheet.inChargeHours,
31
- Shift_Travel_Stipend__c: timesheet.shiftTravelPerDiemHours
32
- })
33
-
34
- if (![200, 204, 304].includes(response.status))
35
- throw new Error(`got error status code ${response.status}`)
36
- } catch (error) {
37
- console.error('Error Updating Timesheet Hour: ', error.message)
38
- }
39
- }
40
-
41
- async getTimesheetId(workorderId: string): Promise<string> {
42
- // First we find the correct timesheet id
43
- const url = `/services/data/${SF_API_VERSION}/query`
44
- const query = `SELECT Id FROM Timesheet__c WHERE WorkOrder__c = '${workorderId}' LIMIT 1`
45
- const {
46
- data: { records }
47
- } = await this.axiosInstance.get(url, {
48
- params: { q: query }
49
- })
50
- return records[0].Id
51
- }
52
-
53
- async getTimesheetHoursIds(workorderId: string): Promise<string[]> {
54
- const timesheetId = await this.getTimesheetId(workorderId)
55
- // First we find the correct timesheet hours id
56
- const url = `/services/data/${SF_API_VERSION}/query`
57
- const query = `SELECT Id FROM TimesheetHour__c WHERE Timesheet__c = '${timesheetId}'`
58
- const {
59
- data: { records }
60
- } = await this.axiosInstance.get(url, {
61
- params: { q: query }
62
- })
63
- return records.map(({ Id }) => Id)
64
- }
65
-
66
- async getTimesheetHours(workorderId: string): Promise<TimesheetDayEntry[]> {
67
- const timesheetHourIds = await this.getTimesheetHoursIds(workorderId)
68
- return Promise.all(
69
- timesheetHourIds.map(async id =>
70
- this.axiosInstance
71
- .get(`/services/data/${SF_API_VERSION}/sobjects/TimeSheetHour__c/${id}`)
72
- .then(res => res.data)
73
- .then(toTimesheetDayEntry)
74
- )
75
- )
76
- }
77
- }
78
-
79
- function toTimesheetDayEntry(raw: any): TimesheetDayEntry {
80
- return {
81
- date: raw.Date__c,
82
- callbackHours: raw.Callback__c,
83
- regularHours: raw.HoursEBAdjusted__c,
84
- miscHours: raw.Misc__c,
85
- overtime1Hours: raw.OT1__c,
86
- overtime2Hours: raw.OT2__c,
87
- onCallHours: raw.OnCall__c,
88
- misc1HoursA: raw.Misc1__c,
89
- misc1HoursB: raw.Misc_1_Hours__c,
90
- misc2Hours: raw.Misc_2_Hours__c,
91
- misc3Hours: raw.Misc_3_Hours__c,
92
- misc4Hours: raw.Misc_4_Hours__c,
93
- stat1Hours: raw.Stat1__c,
94
- stat2Hours: raw.Stat2__c,
95
- inChargeHours: raw.In_Charge__c,
96
- shiftTravelPerDiemHours: raw.Shift_Travel_Stipend__c
97
- }
98
- }
1
+ import { AxiosInstance } from 'axios'
2
+ import { TimesheetDayEntry } from '../../models'
3
+ import { SF_API_VERSION } from '../apiClient'
4
+
5
+ export class SFTimesheetClient {
6
+ private axiosInstance: AxiosInstance
7
+
8
+ constructor(axiosInstance: AxiosInstance) {
9
+ this.axiosInstance = axiosInstance
10
+ }
11
+
12
+ async updateTimesheetHour(timesheetHourId: string, timesheet: TimesheetDayEntry) {
13
+ try {
14
+ const url = `/services/data/${SF_API_VERSION}/sobjects/TimeSheetHour__c/${timesheetHourId}`
15
+ const response = await this.axiosInstance.patch(url, {
16
+ Date__c: timesheet.date,
17
+ Callback__c: timesheet.callbackHours,
18
+ HoursEBAdjusted__c: timesheet.regularHours,
19
+ Misc__c: timesheet.miscHours,
20
+ OT1__c: timesheet.overtime1Hours,
21
+ OT2__c: timesheet.overtime2Hours,
22
+ OnCall__c: timesheet.onCallHours,
23
+ Misc1__c: timesheet.misc1HoursA,
24
+ Misc_1_Hours__c: timesheet.misc1HoursB,
25
+ Misc_2_Hours__c: timesheet.misc2Hours,
26
+ Misc_3_Hours__c: timesheet.misc3Hours,
27
+ Misc_4_Hours__c: timesheet.misc4Hours,
28
+ Stat1__c: timesheet.stat1Hours,
29
+ Stat2__c: timesheet.stat2Hours,
30
+ In_Charge__c: timesheet.inChargeHours,
31
+ Shift_Travel_Stipend__c: timesheet.shiftTravelPerDiemHours
32
+ })
33
+
34
+ if (![200, 204, 304].includes(response.status))
35
+ throw new Error(`got error status code ${response.status}`)
36
+ } catch (error) {
37
+ console.error('Error Updating Timesheet Hour: ', error.message)
38
+ }
39
+ }
40
+
41
+ async getTimesheetId(workorderId: string): Promise<string> {
42
+ // First we find the correct timesheet id
43
+ const url = `/services/data/${SF_API_VERSION}/query`
44
+ const query = `SELECT Id
45
+ FROM Timesheet__c
46
+ WHERE WorkOrder__c = '${workorderId}'
47
+ LIMIT 1`
48
+ const {
49
+ data: { records }
50
+ } = await this.axiosInstance.get(url, {
51
+ params: { q: query }
52
+ })
53
+ return records[0].Id
54
+ }
55
+
56
+ async getTimesheetsForPractitioner(personnelID: string) {
57
+ const url = `/services/data/${SF_API_VERSION}/query`
58
+
59
+ const query = `SELECT FIELDS(STANDARD), WorkOrder__c
60
+ FROM TimeSheet__c
61
+ WHERE WorkOrder__c IN (SELECT Id
62
+ FROM WorkOrder__c
63
+ WHERE Personnel__c = '${personnelID}')`
64
+
65
+ const data = await this.axiosInstance.get(url, { params: { q: query } })
66
+
67
+ return data.data.records
68
+ }
69
+
70
+ async getTimesheetsIdAndDateForPractitioner(personnelID: string) {
71
+ const url = `/services/data/${SF_API_VERSION}/query`
72
+
73
+ const query = `SELECT Id, LastModifiedDate
74
+ FROM TimeSheet__c
75
+ WHERE WorkOrder__c IN (SELECT Id
76
+ FROM WorkOrder__c
77
+ WHERE Personnel__c = '${personnelID}')`
78
+
79
+ const data = await this.axiosInstance.get(url, { params: { q: query } })
80
+
81
+ return data.data.records.map(({Id, LastModifiedDate}) => ({Id, LastModifiedDate}))
82
+ }
83
+
84
+
85
+ async getTimesheetHoursIds(workorderId: string): Promise<string[]> {
86
+ const timesheetId = await this.getTimesheetId(workorderId)
87
+ // First we find the correct timesheet hours id
88
+ const url = `/services/data/${SF_API_VERSION}/query`
89
+ const query = `SELECT Id
90
+ FROM TimesheetHour__c
91
+ WHERE Timesheet__c = '${timesheetId}'`
92
+ const {
93
+ data: { records }
94
+ } = await this.axiosInstance.get(url, {
95
+ params: { q: query }
96
+ })
97
+ return records.map(({ Id }) => Id)
98
+ }
99
+
100
+ async getTimesheetHours(workorderId: string): Promise<TimesheetDayEntry[]> {
101
+ const timesheetHourIds = await this.getTimesheetHoursIds(workorderId)
102
+ return Promise.all(
103
+ timesheetHourIds.map(async id =>
104
+ this.axiosInstance
105
+ .get(`/services/data/${SF_API_VERSION}/sobjects/TimeSheetHour__c/${id}`)
106
+ .then(res => res.data)
107
+ .then(toTimesheetDayEntry)
108
+ )
109
+ )
110
+ }
111
+ }
112
+
113
+ function toTimesheetDayEntry(raw: any): TimesheetDayEntry {
114
+ return {
115
+ date: raw.Date__c,
116
+ callbackHours: raw.Callback__c,
117
+ regularHours: raw.HoursEBAdjusted__c,
118
+ miscHours: raw.Misc__c,
119
+ overtime1Hours: raw.OT1__c,
120
+ overtime2Hours: raw.OT2__c,
121
+ onCallHours: raw.OnCall__c,
122
+ misc1HoursA: raw.Misc1__c,
123
+ misc1HoursB: raw.Misc_1_Hours__c,
124
+ misc2Hours: raw.Misc_2_Hours__c,
125
+ misc3Hours: raw.Misc_3_Hours__c,
126
+ misc4Hours: raw.Misc_4_Hours__c,
127
+ stat1Hours: raw.Stat1__c,
128
+ stat2Hours: raw.Stat2__c,
129
+ inChargeHours: raw.In_Charge__c,
130
+ shiftTravelPerDiemHours: raw.Shift_Travel_Stipend__c
131
+ }
132
+ }
@@ -0,0 +1,43 @@
1
+ import { AxiosInstance } from 'axios'
2
+ import { SF_API_VERSION } from '../apiClient'
3
+ import { Workorder } from '../../models'
4
+
5
+ export class SFWorkorderClient {
6
+ private axiosInstance: AxiosInstance
7
+
8
+ constructor(axiosInstance: AxiosInstance) {
9
+ this.axiosInstance = axiosInstance
10
+ }
11
+
12
+
13
+ async getWorkordersForPractitioner(assignedStaffId?: string): Promise<Workorder[]> {
14
+ try {
15
+ const url = `/services/data/${SF_API_VERSION}/query`
16
+ const query = assignedStaffId
17
+ ? `SELECT Id, HospitalID__c, HospitalName__c, ProfessionalDesignation__c, Personnel__c, startdate__c, EndDate__c, CreatedDate, LastModifiedDate FROM WorkOrder__c WHERE Personnel__c = '${assignedStaffId}'`
18
+ : `SELECT Id, HospitalID__c, HospitalName__c, ProfessionalDesignation__c, Personnel__c, startdate__c, EndDate__c, CreatedDate, LastModifiedDate FROM WorkOrder__c`
19
+ return await this.axiosInstance
20
+ .get(url, {
21
+ params: { q: query }
22
+ })
23
+ .then(({ data: { records } }) =>
24
+ records.map(
25
+ (record): Workorder => ({
26
+ id: record.Id,
27
+ establishmentId: record.HospitalID__c,
28
+ establishmentName: record.HospitalName__c,
29
+ role: record.ProfessionalDesignation__c,
30
+ assignedStaffId: record.Personnel__c,
31
+ startDate: new Date(record.startdate__c),
32
+ endDate: new Date(record.EndDate__c),
33
+ createdAt: new Date(record.CreatedDate),
34
+ updatedAt: new Date(record.LastModifiedDate)
35
+ })
36
+ )
37
+ )
38
+ } catch (error) {
39
+ console.error('Error fetching work orders: ', error.message)
40
+ throw error
41
+ }
42
+ }
43
+ }