pha-hermes 1.26.0 → 1.28.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.28.0",
3
3
  "main": "dist/index.js",
4
4
  "typings": "dist/index.d.ts",
5
5
  "files": [
@@ -1,4 +1,4 @@
1
- import { AxiosInstance } from "axios"
1
+ import { AxiosInstance } from 'axios'
2
2
 
3
3
  export interface Account {
4
4
  id: string
@@ -16,6 +16,7 @@ export interface Account {
16
16
  fax: string | null
17
17
  email: string
18
18
  lang: 'eng' | 'fra'
19
+ clientNumber: string
19
20
  }
20
21
 
21
22
  export interface HealthAuthority extends Account {
@@ -39,7 +40,8 @@ const ACCOUNT_FIELDS = [
39
40
  'BillingAddress',
40
41
  'Phone',
41
42
  'Fax',
42
- 'Type'
43
+ 'Type',
44
+ 'Client_Number__c'
43
45
  ] as const
44
46
 
45
47
  export class SFAccounts {
@@ -49,7 +51,10 @@ export class SFAccounts {
49
51
  this.axiosInstance = axiosInstance
50
52
  }
51
53
 
52
- async fetchAccounts<T extends Account>(type: AccountType, options?: { parentId?: string, pageSize?: number, pageNumber?: number, failfast?: boolean }): Promise<T[]> {
54
+ async fetchAccounts<T extends Account>(
55
+ type: AccountType,
56
+ options?: { parentId?: string; active?: boolean; failfast?: boolean }
57
+ ): Promise<T[]> {
53
58
  try {
54
59
  let accountType: 'Health Authority' | 'Hospital'
55
60
  switch (type) {
@@ -62,31 +67,33 @@ export class SFAccounts {
62
67
 
63
68
  let query = `SELECT ${ACCOUNT_FIELDS.join(',')} FROM Account WHERE Type = '${accountType}'`
64
69
  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}`
70
+ if (options?.active) query += ` AND Active__c = true`
67
71
 
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))
72
+ let records = []
73
+ let done = false
74
+ let url = `/services/data/v57.0/query`
75
+ do {
76
+ const {
77
+ data: { records: pageRecords, nextRecordsUrl, done: isDone }
78
+ } = await this.axiosInstance.get(url, { params: { q: query } })
79
+ records.push(...pageRecords)
80
+ done = isDone
81
+ url = nextRecordsUrl
82
+ } while (!done)
83
+ const accounts: Account[] = records.map(record => this.buildAccount(record))
84
+
85
+ for (const i in accounts)
86
+ if (accounts[i].accountTypeName === 'healthAuthority')
87
+ (accounts[i] as HealthAuthority).children =
88
+ await this.fetchAccounts<Establishment>('establishment', {
89
+ parentId: accounts[i].id,
90
+ active: options?.active
91
+ })
70
92
 
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
93
  return accounts as T[]
86
94
  } catch (error) {
87
- console.error(`Error fetching ${type}s: `, error.message)
88
- if (options?.failfast)
89
- throw error
95
+ console.error(`Error fetching ${type} accounts: `, error.message)
96
+ if (options?.failfast) throw error
90
97
  return []
91
98
  }
92
99
  }
@@ -100,10 +107,17 @@ export class SFAccounts {
100
107
  case 'Hospital':
101
108
  accountType = 'establishment'
102
109
  }
110
+
111
+ const fields = ['street', 'city', 'state', 'country', 'postalCode']
112
+ const address = fields
113
+ .map(field => record.BillingAddress?.[field]?.trim() ?? '')
114
+ .filter(Boolean)
115
+ .join('\n')
116
+
103
117
  return {
104
118
  id: record.Id,
105
119
  name: record.Name,
106
- address: record.BillingAddress,
120
+ address: address,
107
121
  city: record.BillingCity,
108
122
  province: record.BillingState,
109
123
  postalCode: record.BillingPostalCode,
@@ -115,7 +129,8 @@ export class SFAccounts {
115
129
  email: null,
116
130
  phone2: null,
117
131
  cellular: null,
118
- lang: 'eng'
132
+ lang: 'eng',
133
+ clientNumber: record.Client_Number__c
119
134
  }
120
135
  }
121
- }
136
+ }
@@ -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
+