pha-hermes 1.25.0 → 1.27.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.
@@ -0,0 +1,125 @@
1
+ import { AxiosInstance } from "axios"
2
+
3
+ export interface Account {
4
+ id: string
5
+ name: string
6
+ accountTypeName: AccountType
7
+ regionName: string
8
+ geographicalAreaName: string | null
9
+ address: string | null
10
+ city: string | null
11
+ province: string | null
12
+ postalCode: string | null
13
+ phone: string | null
14
+ phone2: string | null
15
+ cellular: string | null
16
+ fax: string | null
17
+ email: string
18
+ lang: 'eng' | 'fra'
19
+ }
20
+
21
+ export interface HealthAuthority extends Account {
22
+ accountTypeName: 'healthAuthority'
23
+ children: Establishment[]
24
+ }
25
+
26
+ export interface Establishment extends Account {
27
+ accountTypeName: 'establishment'
28
+ }
29
+
30
+ type AccountType = 'healthAuthority' | 'establishment'
31
+
32
+ const ACCOUNT_FIELDS = [
33
+ 'Id',
34
+ 'Name',
35
+ 'BillingCity',
36
+ 'BillingState',
37
+ 'BillingPostalCode',
38
+ 'BillingCountry',
39
+ 'BillingAddress',
40
+ 'Phone',
41
+ 'Fax',
42
+ 'Type'
43
+ ] as const
44
+
45
+ export class SFAccounts {
46
+ private axiosInstance: AxiosInstance
47
+
48
+ constructor(axiosInstance: AxiosInstance) {
49
+ this.axiosInstance = axiosInstance
50
+ }
51
+
52
+ async fetchAccounts<T extends Account>(type: AccountType, options?: { parentId?: string, active?: boolean, failfast?: boolean }): Promise<T[]> {
53
+ try {
54
+ let accountType: 'Health Authority' | 'Hospital'
55
+ switch (type) {
56
+ case 'healthAuthority':
57
+ accountType = 'Health Authority'
58
+ break
59
+ case 'establishment':
60
+ accountType = 'Hospital'
61
+ }
62
+
63
+ let query = `SELECT ${ACCOUNT_FIELDS.join(',')} FROM Account WHERE Type = '${accountType}'`
64
+ if (options?.parentId) query += ` AND ParentId = '${options.parentId}'`
65
+ if (options?.active) query += ` AND Active__c = true`
66
+
67
+ let records = []
68
+ let done = false
69
+ let url = `/services/data/v57.0/query`
70
+ do {
71
+ const { data: { records: pageRecords, nextRecordsUrl, done: isDone } } = await this.axiosInstance.get(url, { params: { q: query } })
72
+ records.push(...pageRecords)
73
+ done = isDone
74
+ url = nextRecordsUrl
75
+ } while (!done)
76
+ const accounts: Account[] = records.map(record => this.buildAccount(record))
77
+
78
+ for (const i in accounts)
79
+ if (accounts[i].accountTypeName === 'healthAuthority')
80
+ (accounts[i] as HealthAuthority).children = await this.fetchAccounts<Establishment>('establishment', { parentId: accounts[i].id, active: options?.active })
81
+
82
+ return accounts as T[]
83
+ } catch (error) {
84
+ console.error(`Error fetching ${type} accounts: `, error.message)
85
+ if (options?.failfast)
86
+ throw error
87
+ return []
88
+ }
89
+ }
90
+ private buildAccount(record: any): Account {
91
+ let accountType: AccountType
92
+
93
+ switch (record.Type) {
94
+ case 'Health Authority':
95
+ accountType = 'healthAuthority'
96
+ break
97
+ case 'Hospital':
98
+ accountType = 'establishment'
99
+ }
100
+
101
+ const fields = ['street', 'city', 'state', 'country', 'postalCode']
102
+ const address = fields
103
+ .map(field => record.BillingAddress?.[field]?.trim() ?? '')
104
+ .filter(Boolean)
105
+ .join('\n')
106
+
107
+ return {
108
+ id: record.Id,
109
+ name: record.Name,
110
+ address: address,
111
+ city: record.BillingCity,
112
+ province: record.BillingState,
113
+ postalCode: record.BillingPostalCode,
114
+ geographicalAreaName: record.BillingGeocodeAccuracy,
115
+ phone: record.Phone,
116
+ fax: record.Fax,
117
+ regionName: record.RegionName,
118
+ accountTypeName: accountType,
119
+ email: null,
120
+ phone2: null,
121
+ cellular: null,
122
+ lang: 'eng'
123
+ }
124
+ }
125
+ }
@@ -7,6 +7,7 @@ import { SFWorkorderClient } from './workorder/workorderClient'
7
7
  import { SFPayPeriodClient } from './payperiod/payperiodClient'
8
8
  import { SFExpenseClient } from './expenses/expenseClient'
9
9
  import { SFPriceClient } from './prices/priceClient'
10
+ import { SFAccounts } from './accounts/accounts'
10
11
 
11
12
  export const SF_API_VERSION: string = 'v57.0'
12
13
 
@@ -21,6 +22,7 @@ export class SFApiClient {
21
22
  payPeriodClient: SFPayPeriodClient
22
23
  expenseClient: SFExpenseClient
23
24
  priceClient: SFPriceClient
25
+ accountsClient: SFAccounts
24
26
 
25
27
  async init(
26
28
  baseUrl: string,
@@ -37,6 +39,7 @@ export class SFApiClient {
37
39
  this.payPeriodClient = new SFPayPeriodClient(this.axiosInstance)
38
40
  this.expenseClient = new SFExpenseClient(this.axiosInstance)
39
41
  this.priceClient = new SFPriceClient(this.axiosInstance)
42
+ this.accountsClient = new SFAccounts(this.axiosInstance)
40
43
  // creates authenticator and adds token to axios instance
41
44
  await this.authenticator.initializeAuth(sfClientId, sfClientSecret, onTokenRefresh)
42
45
  }
@@ -59,7 +59,7 @@ export class SFPractitionerClient {
59
59
  typeof options?.limit === 'number' && options.limit > 0
60
60
  ? `LIMIT ${Math.floor(options.limit)}`
61
61
  : ''
62
- const url = `/services/data/${SF_API_VERSION}/query`
62
+ let url = `/services/data/${SF_API_VERSION}/query`
63
63
  const fields = (
64
64
  options?.forExport
65
65
  ? this.PRACTITIONER_FIELDS.export
@@ -73,11 +73,18 @@ export class SFPractitionerClient {
73
73
  ORDER BY CreatedDate ASC, StaffID__c ASC
74
74
  ${limitClause}
75
75
  `
76
- const {
77
- data: { records }
78
- } = await this.axiosInstance.get(url, {
79
- params: { q: query }
80
- })
76
+ const records = []
77
+ let done = false
78
+ do {
79
+ const {
80
+ data: { records: pageRecords, nextRecordsUrl, done: isDone }
81
+ } = await this.axiosInstance.get(url, {
82
+ params: { q: query }
83
+ })
84
+ records.push(...pageRecords)
85
+ done = isDone
86
+ url = nextRecordsUrl
87
+ } while (!done)
81
88
 
82
89
  return options?.forExport
83
90
  ? records.map(toPractitionerExport)
package/src/index.ts CHANGED
@@ -15,3 +15,4 @@ export { LiphePractitionerClient } from './api/liphe_legacy/practitioner/practit
15
15
 
16
16
  // Common Models
17
17
  export { Practitioner, Role, TimesheetDayEntry, Workorder, Agency, Period } from './models'
18
+ export { LipheRegion, Province, LipheGeographicalArea } from './models/regions'
@@ -0,0 +1,168 @@
1
+ export enum LipheRegion {
2
+ 'Abitibi-Témiscaminque',
3
+ 'Alberta',
4
+ 'Autre',
5
+ 'Baie d\'Hudson',
6
+ 'Baie James',
7
+ 'Bas St-Laurent',
8
+ 'British Columbia',
9
+ 'Charlevoix',
10
+ 'Estrie',
11
+ 'Gaspésie',
12
+ 'Haut St-Maurice',
13
+ 'Iles de la Madeleine',
14
+ 'Lanaudière',
15
+ 'Laurentides',
16
+ 'Laval',
17
+ 'Manitoba',
18
+ 'Mauricie',
19
+ 'Montérégie',
20
+ 'Montréal',
21
+ 'New Brunswick',
22
+ 'Newfoundland and Labrador',
23
+ 'Northwest Territories',
24
+ 'Nova Scotia',
25
+ 'Nunavut',
26
+ 'Ontario',
27
+ 'Outaouais',
28
+ 'Prince Edward Island',
29
+ 'Québec',
30
+ 'Rivière du Loup / Matane',
31
+ 'Saguenay',
32
+ 'Saskatchewan',
33
+ 'Sept-Iles / Côte-Nord',
34
+ 'Thetford Mines',
35
+ 'Ungava',
36
+ 'Yukon',
37
+ }
38
+
39
+ export enum LipheGeographicalArea {
40
+ 'Berthierville',
41
+ 'Bordeaux-Cartierville',
42
+ 'Labelle',
43
+ 'Laval',
44
+ 'Le Gardeur',
45
+ 'Lindsay - Gingras',
46
+ 'Montréal',
47
+ 'Montréal - Est',
48
+ 'Montréal - Ouest',
49
+ 'Outaouais',
50
+ 'Rive - Sud',
51
+ 'Ste - Adèle',
52
+ 'Ste - Agathe',
53
+ 'St - Eustache',
54
+ 'St - Jérôme',
55
+ 'Verdun',
56
+ 'Mont - Tremblant',
57
+ 'Montréal(centre - ville)',
58
+ 'Basses Laurentides',
59
+ 'Valleyfield',
60
+ 'Argenteuil',
61
+ 'Lachute',
62
+ 'Lanaudière SUD',
63
+ 'Lanaudière NORD',
64
+ 'Granby',
65
+ 'Sorel',
66
+ 'Longueuil',
67
+ 'Châteauguay',
68
+ 'St - Jean sur Richelieu',
69
+ 'St - Hyacinthe',
70
+ 'Drummondville',
71
+ 'Blainville',
72
+ 'La Prairie',
73
+ 'Mont - Laurier',
74
+ 'Pierre - Boucher',
75
+ 'Berthiaume du Tremblay',
76
+ 'Grand Nord',
77
+ 'Montréal Nord',
78
+ 'Rouyn Noranda',
79
+ 'Chicoutimi',
80
+ 'Québec',
81
+ 'Sherbrooke',
82
+ 'Trois - Rivières',
83
+ 'Gaspésie',
84
+ 'Côte - Nord',
85
+ 'Abitibi - Témiscamingue',
86
+ 'Portneuf',
87
+ 'Charlevoix',
88
+ 'CHUQ',
89
+ 'Thetford Mines',
90
+ 'Chaudière - Appalaches',
91
+ 'Saint - Raymond',
92
+ 'Limoilou',
93
+ 'Ancienne - Lorette',
94
+ 'Malbaie',
95
+ 'Baie - Saint - Paul',
96
+ 'St - Anne de Beaupré',
97
+ 'Loretteville',
98
+ 'Valcartier',
99
+ 'Rivière - du - Loup',
100
+ 'Maria',
101
+ 'Manicouagan',
102
+ 'Sept - Iles',
103
+ 'Basse - Côte - Nord',
104
+ 'Port - Cartier',
105
+ 'Sherfferville',
106
+ 'Minganie',
107
+ 'Natashquan',
108
+ 'Chibougamau',
109
+ 'Mauricie',
110
+ 'Maskinongé',
111
+ 'Parent',
112
+ 'Mémphrémagog',
113
+ 'Coaticook',
114
+ 'Victoriaville',
115
+ 'Rimouski',
116
+ 'Shawinigan',
117
+ 'Matane',
118
+ 'Santa - Cabrini',
119
+ 'Marie - Clarac',
120
+ 'Hôpital lachine',
121
+ 'Rivière - Rouge',
122
+ 'Jeanne - Mance',
123
+ 'Le Repair',
124
+ 'Montérégie',
125
+ 'Estrie',
126
+ 'Villa - Medica',
127
+ 'Laurentides',
128
+ 'Hors - Qc',
129
+ 'Hors - Can',
130
+ 'Hors Pays',
131
+ 'Hors Province',
132
+ 'Baie James',
133
+ 'Nunavut',
134
+ 'Ungava',
135
+ 'Inuulitsivik',
136
+ 'Bas Saint - Laurent',
137
+ 'Lévis',
138
+ 'Îles de la Madeleine',
139
+ 'Saguenay',
140
+ 'Alberta',
141
+ 'British Columbia',
142
+ 'Yukon',
143
+ 'Northwest Territories',
144
+ 'Saskatchewan',
145
+ 'Manitoba',
146
+ 'Ontario',
147
+ 'New Brunswick',
148
+ 'Newfoundland and Labrador',
149
+ 'Prince Edward Island',
150
+ 'Nova Scotia',
151
+ }
152
+
153
+ export enum Province {
154
+ AB = 'AB',
155
+ BC = 'BC',
156
+ MB = 'MB',
157
+ NB = 'NB',
158
+ NL = 'NL',
159
+ NS = 'NS',
160
+ NT = 'NT',
161
+ NU = 'NU',
162
+ ON = 'ON',
163
+ PE = 'PE',
164
+ QC = 'QC',
165
+ SK = 'SK',
166
+ YT = 'YT'
167
+ }
168
+
package/src/api/.env DELETED
@@ -1,5 +0,0 @@
1
- I THINK THIS ONE IS WRONG
2
- SF_CLIENT_ID=3MVG9TZvGM_0NqB09H2fPRxeiDEsovly3D10kwNjOYJNTwBhMc5JHQgCdaSM.2N1V04tb_Tuyj_qktBPNueQd
3
- SF_CLIENT_SECRET=6F4D40003CF5B156A2AD2BFAD384E74AA9FFFD574E8753EAC485E3C478C50F9F
4
- GRANT_TYPE=client_credentials
5
- SALESFORCE_URL=https://do0000000d247eaa--phealth.sandbox.my.salesforce.com