pha-hermes 1.26.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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.26.0",
2
+ "version": "1.27.0",
3
3
  "main": "dist/index.js",
4
4
  "typings": "dist/index.d.ts",
5
5
  "files": [
@@ -49,7 +49,7 @@ export class SFAccounts {
49
49
  this.axiosInstance = axiosInstance
50
50
  }
51
51
 
52
- async fetchAccounts<T extends Account>(type: AccountType, options?: { parentId?: string, pageSize?: number, pageNumber?: number, failfast?: boolean }): Promise<T[]> {
52
+ async fetchAccounts<T extends Account>(type: AccountType, options?: { parentId?: string, active?: boolean, failfast?: boolean }): Promise<T[]> {
53
53
  try {
54
54
  let accountType: 'Health Authority' | 'Hospital'
55
55
  switch (type) {
@@ -62,29 +62,26 @@ export class SFAccounts {
62
62
 
63
63
  let query = `SELECT ${ACCOUNT_FIELDS.join(',')} FROM Account WHERE Type = '${accountType}'`
64
64
  if (options?.parentId) query += ` AND ParentId = '${options.parentId}'`
65
- if (options?.pageSize) query += ` LIMIT ${options.pageSize}`
66
- if (options?.pageNumber) query += ` OFFSET ${options.pageNumber * options.pageSize}`
65
+ if (options?.active) query += ` AND Active__c = true`
67
66
 
68
- const response = await this.axiosInstance.get(`/services/data/v57.0/query?q=${query}`)
69
- const accounts: Account[] = response.data.records.map(record => this.buildAccount(record))
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 })
70
81
 
71
- for (const i in accounts) {
72
- if (accounts[i].accountTypeName === 'healthAuthority') {
73
- let pageNumber = 0
74
- const childAccounts = []
75
- let returnedPageSize = 0
76
- do {
77
- const pageAccounts = await this.fetchAccounts<Establishment>('establishment', { parentId: accounts[i].id, pageSize: options?.pageSize ?? 100, pageNumber, failfast: options?.failfast })
78
- childAccounts.push(...pageAccounts)
79
- returnedPageSize = pageAccounts.length
80
- pageNumber++
81
- } while (returnedPageSize > 0);
82
- (accounts[i] as HealthAuthority).children = childAccounts
83
- }
84
- }
85
82
  return accounts as T[]
86
83
  } catch (error) {
87
- console.error(`Error fetching ${type}s: `, error.message)
84
+ console.error(`Error fetching ${type} accounts: `, error.message)
88
85
  if (options?.failfast)
89
86
  throw error
90
87
  return []
@@ -100,10 +97,17 @@ export class SFAccounts {
100
97
  case 'Hospital':
101
98
  accountType = 'establishment'
102
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
+
103
107
  return {
104
108
  id: record.Id,
105
109
  name: record.Name,
106
- address: record.BillingAddress,
110
+ address: address,
107
111
  city: record.BillingCity,
108
112
  province: record.BillingState,
109
113
  postalCode: record.BillingPostalCode,
@@ -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
+