pha-hermes 1.23.0 → 1.25.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.
@@ -1,18 +1,54 @@
1
1
  import { AxiosInstance } from 'axios'
2
- import { Practitioner } from '../../../models'
3
- import { SF_API_VERSION } from '../apiClient'
2
+ import { Practitioner, PractitionerExport, Role } from '../../../models'
3
+ import { SF_API_VERSION } from '../../../index'
4
4
 
5
5
  export class SFPractitionerClient {
6
+ private PRACTITIONER_FIELDS = {
7
+ default: ['Id', 'FirstName__c', 'LastName__c', 'Email__c', 'StaffID__c', 'CreatedDate'],
8
+ export: [
9
+ 'Id',
10
+ 'FirstName__c',
11
+ 'LastName__c',
12
+ 'Email__c',
13
+ 'StaffID__c',
14
+ 'CreatedDate',
15
+ 'DaytimePhone__c',
16
+ 'Status__c',
17
+ 'ProfessionalDesignation__c',
18
+ 'CANSocialInsuranceNumber__c',
19
+ 'Date_of_Hire__c',
20
+ 'DateApplied__c',
21
+ 'Birthdate__c',
22
+ 'MailingStreetAddress__c',
23
+ 'MailingCity__c',
24
+ 'MailingStateProvince__c',
25
+ 'MailingZipPostalCode__c'
26
+ ]
27
+ } as const
28
+
6
29
  private axiosInstance: AxiosInstance
7
30
 
8
31
  constructor(axiosInstance: AxiosInstance) {
9
32
  this.axiosInstance = axiosInstance
10
33
  }
11
34
 
35
+ async fetchPractitioners(options: {
36
+ createdAt?: string
37
+ limit?: number
38
+ forExport: true
39
+ }): Promise<PractitionerExport[]>
40
+
12
41
  async fetchPractitioners(options?: {
13
42
  createdAt?: string
14
43
  limit?: number
15
- }): Promise<Practitioner[]> {
44
+ forExport?: false | undefined
45
+ }): Promise<Practitioner[]>
46
+
47
+ async fetchPractitioners(options?: {
48
+ createdAt?: string
49
+ limit?: number
50
+ forExport?: boolean
51
+ }): Promise<Practitioner[] | PractitionerExport[]> {
16
52
  try {
17
53
  const conditions: string[] = [`Status__c = 'Active'`]
18
54
  if (options?.createdAt) {
@@ -24,8 +60,14 @@ export class SFPractitionerClient {
24
60
  ? `LIMIT ${Math.floor(options.limit)}`
25
61
  : ''
26
62
  const url = `/services/data/${SF_API_VERSION}/query`
63
+ const fields = (
64
+ options?.forExport
65
+ ? this.PRACTITIONER_FIELDS.export
66
+ : this.PRACTITIONER_FIELDS.default
67
+ ).join(', ')
68
+
27
69
  const query = `
28
- SELECT Id, FirstName__c, LastName__c, Email__c, StaffID__c, CreatedDate
70
+ SELECT ${fields}
29
71
  FROM Personnel__c
30
72
  ${whereClause}
31
73
  ORDER BY CreatedDate ASC, StaffID__c ASC
@@ -37,7 +79,9 @@ export class SFPractitionerClient {
37
79
  params: { q: query }
38
80
  })
39
81
 
40
- return records.map(toPractitioner)
82
+ return options?.forExport
83
+ ? records.map(toPractitionerExport)
84
+ : records.map(toPractitioner)
41
85
  } catch (error) {
42
86
  console.error('Error fetching practitioners: ', error.message)
43
87
  throw error
@@ -66,6 +110,35 @@ export class SFPractitionerClient {
66
110
  throw error
67
111
  }
68
112
  }
113
+
114
+ async fetchRoles(): Promise<Role[]> {
115
+ try {
116
+ const url = `/services/data/${SF_API_VERSION}/query`
117
+ const query = `SELECT Label, Value FROM PicklistValueInfo \
118
+ WHERE EntityParticle.EntityDefinition.QualifiedApiName = 'WorkOrder__c'\
119
+ AND EntityParticle.QualifiedApiName = 'ProfessionalDesignation__c' \
120
+ AND isActive = true`
121
+ return this.axiosInstance
122
+ .get(url, {
123
+ params: { q: query }
124
+ })
125
+ .then(({ data: { records } }) =>
126
+ records.map(
127
+ (record): Role => ({
128
+ label: record.Label,
129
+ value: record.Value
130
+ })
131
+ )
132
+ )
133
+ .catch(error => {
134
+ console.error('Error fetching roles: ', error.message)
135
+ throw error
136
+ })
137
+ } catch (error) {
138
+ console.error('Error fetching roles: ', error.message)
139
+ throw error
140
+ }
141
+ }
69
142
  }
70
143
 
71
144
  function toPractitioner(raw: any): Practitioner {
@@ -75,6 +148,23 @@ function toPractitioner(raw: any): Practitioner {
75
148
  lastName: raw.LastName__c,
76
149
  email: raw.Email__c,
77
150
  staffId: raw.StaffID__c,
78
- createdAt: raw.CreatedDate.replace(/\+0000$/, 'Z')
151
+ createdAt: raw.CreatedDate ? raw.CreatedDate.replace(/\+0000$/, 'Z') : undefined
152
+ }
153
+ }
154
+
155
+ function toPractitionerExport(raw: any): PractitionerExport {
156
+ return {
157
+ ...toPractitioner(raw),
158
+ phone: raw.DaytimePhone__c,
159
+ status: raw.Status__c,
160
+ professionalDesignation: raw.ProfessionalDesignation__c,
161
+ SIN: raw.CANSocialInsuranceNumber__c,
162
+ hiringDate: raw.Date_of_Hire__c,
163
+ dateApplied: raw.DateApplied__c,
164
+ birthdate: raw.Birthdate__c,
165
+ mailingStreetAddress: raw.MailingStreetAddress__c,
166
+ mailingCity: raw.MailingCity__c,
167
+ mailingProvince: raw.MailingStateProvince__c,
168
+ mailingZip: raw.MailingZipPostalCode__c
79
169
  }
80
170
  }
@@ -1,6 +1,6 @@
1
1
  import { AxiosInstance } from 'axios'
2
2
  import { Price } from '../../../models/price'
3
- import { SF_API_VERSION } from '../apiClient'
3
+ import { SF_API_VERSION } from '../../../index'
4
4
 
5
5
  export class SFPriceClient {
6
6
  private axiosInstance: AxiosInstance
@@ -1,6 +1,6 @@
1
1
  import { AxiosInstance } from 'axios'
2
2
  import { TimesheetDayEntry } from '../../../models'
3
- import { SF_API_VERSION } from '../apiClient'
3
+ import { SF_API_VERSION } from '../../../index'
4
4
  import FormData from 'form-data'
5
5
 
6
6
  interface SFTimesheetHourField {
@@ -61,7 +61,11 @@ export class SFTimesheetClient {
61
61
  }
62
62
  }
63
63
 
64
- async getTimesheetIds(workorderId: string, periodStartDate?: Date, periodEndDate?: Date): Promise<string[]> {
64
+ async getTimesheetIds(
65
+ workorderId: string,
66
+ periodStartDate?: Date,
67
+ periodEndDate?: Date
68
+ ): Promise<string[]> {
65
69
  // Find all timesheet Ids that belong to this WO
66
70
  const url = `/services/data/${SF_API_VERSION}/query`
67
71
  let query = `SELECT Id
@@ -74,8 +78,7 @@ export class SFTimesheetClient {
74
78
  AND PayPeriodEndDate__c >= ${new Date(periodEndDate).toISOString().substring(0, 10)}
75
79
  `
76
80
  }
77
- }
78
- catch (error) {
81
+ } catch (error) {
79
82
  console.error('Invalid period dates', error)
80
83
  }
81
84
  const {
@@ -110,7 +113,12 @@ export class SFTimesheetClient {
110
113
  return timesheets
111
114
  }
112
115
 
113
- async getTimesheetHours(workorderId: string, fields?: SFTimesheetHourFieldKeys[], periodStartDate?: Date, periodEndDate?: Date): Promise<TimesheetDayEntry[]> {
116
+ async getTimesheetHours(
117
+ workorderId: string,
118
+ fields?: SFTimesheetHourFieldKeys[],
119
+ periodStartDate?: Date,
120
+ periodEndDate?: Date
121
+ ): Promise<TimesheetDayEntry[]> {
114
122
  const timesheetIds = await this.getTimesheetIds(workorderId, periodStartDate, periodEndDate)
115
123
 
116
124
  const allHours: SFTimesheetHourField[] = []
@@ -121,7 +129,7 @@ export class SFTimesheetClient {
121
129
  FROM TimesheetHour__c
122
130
  WHERE Timesheet__c = '${timesheetId}'`
123
131
  try {
124
- if (fields?.length) {
132
+ if (fields?.length && periodStartDate && periodEndDate) {
125
133
  query += `
126
134
  AND Date__c >= ${new Date(periodStartDate).toISOString().substring(0, 10)}
127
135
  AND Date__c <= ${new Date(periodEndDate).toISOString().substring(0, 10)}`
@@ -1,5 +1,5 @@
1
1
  import { AxiosInstance } from 'axios'
2
- import { SF_API_VERSION } from '../apiClient'
2
+ import { SF_API_VERSION } from '../../../index'
3
3
  import { Workorder } from '../../../models'
4
4
 
5
5
  export class SFWorkorderClient {
package/src/index.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export const SF_API_VERSION: string = 'v57.0'
2
+
1
3
  // Salesforce API
2
4
  export { SFApiClient } from './api/salesforce/apiClient'
3
5
  export { SFPractitionerClient } from './api/salesforce/practitioner/practitionerClient'
@@ -7,6 +7,20 @@ export interface Practitioner {
7
7
  createdAt?: string
8
8
  }
9
9
 
10
+ export interface PractitionerExport extends Practitioner {
11
+ phone: string | null
12
+ status: string | null
13
+ professionalDesignation: string | null
14
+ SIN: string | null
15
+ hiringDate: string | null
16
+ dateApplied: string | null
17
+ birthdate: string | null
18
+ mailingStreetAddress: string | null
19
+ mailingCity: string | null
20
+ mailingProvince: string | null
21
+ mailingZip: string | null
22
+ }
23
+
10
24
  export interface Role {
11
25
  label: string
12
26
  value: string