pha-hermes 1.24.0 → 1.26.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,38 @@
1
+ import { AxiosInstance } from "axios";
2
+ export interface Account {
3
+ id: string;
4
+ name: string;
5
+ accountTypeName: AccountType;
6
+ regionName: string;
7
+ geographicalAreaName: string | null;
8
+ address: string | null;
9
+ city: string | null;
10
+ province: string | null;
11
+ postalCode: string | null;
12
+ phone: string | null;
13
+ phone2: string | null;
14
+ cellular: string | null;
15
+ fax: string | null;
16
+ email: string;
17
+ lang: 'eng' | 'fra';
18
+ }
19
+ export interface HealthAuthority extends Account {
20
+ accountTypeName: 'healthAuthority';
21
+ children: Establishment[];
22
+ }
23
+ export interface Establishment extends Account {
24
+ accountTypeName: 'establishment';
25
+ }
26
+ declare type AccountType = 'healthAuthority' | 'establishment';
27
+ export declare class SFAccounts {
28
+ private axiosInstance;
29
+ constructor(axiosInstance: AxiosInstance);
30
+ fetchAccounts<T extends Account>(type: AccountType, options?: {
31
+ parentId?: string;
32
+ pageSize?: number;
33
+ pageNumber?: number;
34
+ failfast?: boolean;
35
+ }): Promise<T[]>;
36
+ private buildAccount;
37
+ }
38
+ export {};
@@ -5,6 +5,7 @@ import { SFWorkorderClient } from './workorder/workorderClient';
5
5
  import { SFPayPeriodClient } from './payperiod/payperiodClient';
6
6
  import { SFExpenseClient } from './expenses/expenseClient';
7
7
  import { SFPriceClient } from './prices/priceClient';
8
+ import { SFAccounts } from './accounts/accounts';
8
9
  export declare const SF_API_VERSION: string;
9
10
  export declare class SFApiClient {
10
11
  private instance;
@@ -17,6 +18,7 @@ export declare class SFApiClient {
17
18
  payPeriodClient: SFPayPeriodClient;
18
19
  expenseClient: SFExpenseClient;
19
20
  priceClient: SFPriceClient;
21
+ accountsClient: SFAccounts;
20
22
  init(baseUrl: string, sfClientId: string, sfClientSecret: string, onTokenRefresh?: () => Promise<{
21
23
  clientId: string;
22
24
  clientSecret: string;
@@ -1,11 +1,18 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { Practitioner, Role } from '../../../models';
2
+ import { Practitioner, PractitionerExport, Role } from '../../../models';
3
3
  export declare class SFPractitionerClient {
4
+ private PRACTITIONER_FIELDS;
4
5
  private axiosInstance;
5
6
  constructor(axiosInstance: AxiosInstance);
7
+ fetchPractitioners(options: {
8
+ createdAt?: string;
9
+ limit?: number;
10
+ forExport: true;
11
+ }): Promise<PractitionerExport[]>;
6
12
  fetchPractitioners(options?: {
7
13
  createdAt?: string;
8
14
  limit?: number;
15
+ forExport?: false | undefined;
9
16
  }): Promise<Practitioner[]>;
10
17
  fetchPractitionerByEmail(email: string): Promise<Practitioner | null>;
11
18
  fetchRoles(): Promise<Role[]>;
@@ -6,6 +6,19 @@ export interface Practitioner {
6
6
  staffId: string;
7
7
  createdAt?: string;
8
8
  }
9
+ export interface PractitionerExport extends Practitioner {
10
+ phone: string | null;
11
+ status: string | null;
12
+ professionalDesignation: string | null;
13
+ SIN: string | null;
14
+ hiringDate: string | null;
15
+ dateApplied: string | null;
16
+ birthdate: string | null;
17
+ mailingStreetAddress: string | null;
18
+ mailingCity: string | null;
19
+ mailingProvince: string | null;
20
+ mailingZip: string | null;
21
+ }
9
22
  export interface Role {
10
23
  label: string;
11
24
  value: string;
@@ -55,6 +55,15 @@ function _createForOfIteratorHelperLoose(r, e) {
55
55
  }
56
56
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57
57
  }
58
+ function _extends() {
59
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
60
+ for (var e = 1; e < arguments.length; e++) {
61
+ var t = arguments[e];
62
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
63
+ }
64
+ return n;
65
+ }, _extends.apply(null, arguments);
66
+ }
58
67
  function _regeneratorRuntime() {
59
68
  _regeneratorRuntime = function () {
60
69
  return e;
@@ -833,12 +842,16 @@ function toTimesheetDayEntry(raw) {
833
842
 
834
843
  var SFPractitionerClient = /*#__PURE__*/function () {
835
844
  function SFPractitionerClient(axiosInstance) {
845
+ this.PRACTITIONER_FIELDS = {
846
+ "default": ['Id', 'FirstName__c', 'LastName__c', 'Email__c', 'StaffID__c', 'CreatedDate'],
847
+ "export": ['Id', 'FirstName__c', 'LastName__c', 'Email__c', 'StaffID__c', 'CreatedDate', 'DaytimePhone__c', 'Status__c', 'ProfessionalDesignation__c', 'CANSocialInsuranceNumber__c', 'Date_of_Hire__c', 'DateApplied__c', 'Birthdate__c', 'MailingStreetAddress__c', 'MailingCity__c', 'MailingStateProvince__c', 'MailingZipPostalCode__c']
848
+ };
836
849
  this.axiosInstance = axiosInstance;
837
850
  }
838
851
  var _proto = SFPractitionerClient.prototype;
839
852
  _proto.fetchPractitioners = /*#__PURE__*/function () {
840
853
  var _fetchPractitioners = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
841
- var conditions, whereClause, limitClause, url, query, _yield$this$axiosInst, records;
854
+ var conditions, whereClause, limitClause, url, fields, query, _yield$this$axiosInst, records;
842
855
  return _regeneratorRuntime().wrap(function _callee$(_context) {
843
856
  while (1) switch (_context.prev = _context.next) {
844
857
  case 0:
@@ -850,27 +863,28 @@ var SFPractitionerClient = /*#__PURE__*/function () {
850
863
  whereClause = conditions.length ? "WHERE " + conditions.join(' AND ') : '';
851
864
  limitClause = typeof (options == null ? void 0 : options.limit) === 'number' && options.limit > 0 ? "LIMIT " + Math.floor(options.limit) : '';
852
865
  url = "/services/data/" + SF_API_VERSION$1 + "/query";
853
- query = "\n SELECT Id, FirstName__c, LastName__c, Email__c, StaffID__c, CreatedDate\n FROM Personnel__c\n " + whereClause + "\n ORDER BY CreatedDate ASC, StaffID__c ASC\n " + limitClause + "\n ";
854
- _context.next = 9;
866
+ fields = (options != null && options.forExport ? this.PRACTITIONER_FIELDS["export"] : this.PRACTITIONER_FIELDS["default"]).join(', ');
867
+ query = "\n SELECT " + fields + "\n FROM Personnel__c\n " + whereClause + "\n ORDER BY CreatedDate ASC, StaffID__c ASC\n " + limitClause + "\n ";
868
+ _context.next = 10;
855
869
  return this.axiosInstance.get(url, {
856
870
  params: {
857
871
  q: query
858
872
  }
859
873
  });
860
- case 9:
874
+ case 10:
861
875
  _yield$this$axiosInst = _context.sent;
862
876
  records = _yield$this$axiosInst.data.records;
863
- return _context.abrupt("return", records.map(toPractitioner));
864
- case 14:
865
- _context.prev = 14;
877
+ return _context.abrupt("return", options != null && options.forExport ? records.map(toPractitionerExport) : records.map(toPractitioner));
878
+ case 15:
879
+ _context.prev = 15;
866
880
  _context.t0 = _context["catch"](0);
867
881
  console.error('Error fetching practitioners: ', _context.t0.message);
868
882
  throw _context.t0;
869
- case 18:
883
+ case 19:
870
884
  case "end":
871
885
  return _context.stop();
872
886
  }
873
- }, _callee, this, [[0, 14]]);
887
+ }, _callee, this, [[0, 15]]);
874
888
  }));
875
889
  function fetchPractitioners(_x) {
876
890
  return _fetchPractitioners.apply(this, arguments);
@@ -971,6 +985,21 @@ function toPractitioner(raw) {
971
985
  createdAt: raw.CreatedDate ? raw.CreatedDate.replace(/\+0000$/, 'Z') : undefined
972
986
  };
973
987
  }
988
+ function toPractitionerExport(raw) {
989
+ return _extends({}, toPractitioner(raw), {
990
+ phone: raw.DaytimePhone__c,
991
+ status: raw.Status__c,
992
+ professionalDesignation: raw.ProfessionalDesignation__c,
993
+ SIN: raw.CANSocialInsuranceNumber__c,
994
+ hiringDate: raw.Date_of_Hire__c,
995
+ dateApplied: raw.DateApplied__c,
996
+ birthdate: raw.Birthdate__c,
997
+ mailingStreetAddress: raw.MailingStreetAddress__c,
998
+ mailingCity: raw.MailingCity__c,
999
+ mailingProvince: raw.MailingStateProvince__c,
1000
+ mailingZip: raw.MailingZipPostalCode__c
1001
+ });
1002
+ }
974
1003
 
975
1004
  var SFWorkorderClient = /*#__PURE__*/function () {
976
1005
  function SFWorkorderClient(axiosInstance) {
@@ -1331,6 +1360,131 @@ var SFPriceClient = /*#__PURE__*/function () {
1331
1360
  return SFPriceClient;
1332
1361
  }();
1333
1362
 
1363
+ var ACCOUNT_FIELDS = ['Id', 'Name', 'BillingCity', 'BillingState', 'BillingPostalCode', 'BillingCountry', 'BillingAddress', 'Phone', 'Fax', 'Type'];
1364
+ var SFAccounts = /*#__PURE__*/function () {
1365
+ function SFAccounts(axiosInstance) {
1366
+ this.axiosInstance = axiosInstance;
1367
+ }
1368
+ var _proto = SFAccounts.prototype;
1369
+ _proto.fetchAccounts = /*#__PURE__*/function () {
1370
+ var _fetchAccounts = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(type, options) {
1371
+ var _this = this;
1372
+ var accountType, query, response, accounts, i, pageNumber, childAccounts, returnedPageSize, _options$pageSize, pageAccounts;
1373
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1374
+ while (1) switch (_context.prev = _context.next) {
1375
+ case 0:
1376
+ _context.prev = 0;
1377
+ _context.t0 = type;
1378
+ _context.next = _context.t0 === 'healthAuthority' ? 4 : _context.t0 === 'establishment' ? 6 : 7;
1379
+ break;
1380
+ case 4:
1381
+ accountType = 'Health Authority';
1382
+ return _context.abrupt("break", 7);
1383
+ case 6:
1384
+ accountType = 'Hospital';
1385
+ case 7:
1386
+ query = "SELECT " + ACCOUNT_FIELDS.join(',') + " FROM Account WHERE Type = '" + accountType + "'";
1387
+ if (options != null && options.parentId) query += " AND ParentId = '" + options.parentId + "'";
1388
+ if (options != null && options.pageSize) query += " LIMIT " + options.pageSize;
1389
+ if (options != null && options.pageNumber) query += " OFFSET " + options.pageNumber * options.pageSize;
1390
+ _context.next = 13;
1391
+ return this.axiosInstance.get("/services/data/v57.0/query?q=" + query);
1392
+ case 13:
1393
+ response = _context.sent;
1394
+ accounts = response.data.records.map(function (record) {
1395
+ return _this.buildAccount(record);
1396
+ });
1397
+ _context.t1 = _regeneratorRuntime().keys(accounts);
1398
+ case 16:
1399
+ if ((_context.t2 = _context.t1()).done) {
1400
+ _context.next = 32;
1401
+ break;
1402
+ }
1403
+ i = _context.t2.value;
1404
+ if (!(accounts[i].accountTypeName === 'healthAuthority')) {
1405
+ _context.next = 30;
1406
+ break;
1407
+ }
1408
+ pageNumber = 0;
1409
+ childAccounts = [];
1410
+ returnedPageSize = 0;
1411
+ case 22:
1412
+ _context.next = 24;
1413
+ return this.fetchAccounts('establishment', {
1414
+ parentId: accounts[i].id,
1415
+ pageSize: (_options$pageSize = options == null ? void 0 : options.pageSize) != null ? _options$pageSize : 100,
1416
+ pageNumber: pageNumber,
1417
+ failfast: options == null ? void 0 : options.failfast
1418
+ });
1419
+ case 24:
1420
+ pageAccounts = _context.sent;
1421
+ childAccounts.push.apply(childAccounts, pageAccounts);
1422
+ returnedPageSize = pageAccounts.length;
1423
+ pageNumber++;
1424
+ case 28:
1425
+ if (returnedPageSize > 0) {
1426
+ _context.next = 22;
1427
+ break;
1428
+ }
1429
+ case 29:
1430
+ accounts[i].children = childAccounts;
1431
+ case 30:
1432
+ _context.next = 16;
1433
+ break;
1434
+ case 32:
1435
+ return _context.abrupt("return", accounts);
1436
+ case 35:
1437
+ _context.prev = 35;
1438
+ _context.t3 = _context["catch"](0);
1439
+ console.error("Error fetching " + type + "s: ", _context.t3.message);
1440
+ if (!(options != null && options.failfast)) {
1441
+ _context.next = 40;
1442
+ break;
1443
+ }
1444
+ throw _context.t3;
1445
+ case 40:
1446
+ return _context.abrupt("return", []);
1447
+ case 41:
1448
+ case "end":
1449
+ return _context.stop();
1450
+ }
1451
+ }, _callee, this, [[0, 35]]);
1452
+ }));
1453
+ function fetchAccounts(_x, _x2) {
1454
+ return _fetchAccounts.apply(this, arguments);
1455
+ }
1456
+ return fetchAccounts;
1457
+ }();
1458
+ _proto.buildAccount = function buildAccount(record) {
1459
+ var accountType;
1460
+ switch (record.Type) {
1461
+ case 'Health Authority':
1462
+ accountType = 'healthAuthority';
1463
+ break;
1464
+ case 'Hospital':
1465
+ accountType = 'establishment';
1466
+ }
1467
+ return {
1468
+ id: record.Id,
1469
+ name: record.Name,
1470
+ address: record.BillingAddress,
1471
+ city: record.BillingCity,
1472
+ province: record.BillingState,
1473
+ postalCode: record.BillingPostalCode,
1474
+ geographicalAreaName: record.BillingGeocodeAccuracy,
1475
+ phone: record.Phone,
1476
+ fax: record.Fax,
1477
+ regionName: record.RegionName,
1478
+ accountTypeName: accountType,
1479
+ email: null,
1480
+ phone2: null,
1481
+ cellular: null,
1482
+ lang: 'eng'
1483
+ };
1484
+ };
1485
+ return SFAccounts;
1486
+ }();
1487
+
1334
1488
  var SF_API_VERSION = 'v57.0';
1335
1489
  var SFApiClient = /*#__PURE__*/function () {
1336
1490
  function SFApiClient() {
@@ -1352,10 +1506,11 @@ var SFApiClient = /*#__PURE__*/function () {
1352
1506
  this.payPeriodClient = new SFPayPeriodClient(this.axiosInstance);
1353
1507
  this.expenseClient = new SFExpenseClient(this.axiosInstance);
1354
1508
  this.priceClient = new SFPriceClient(this.axiosInstance);
1509
+ this.accountsClient = new SFAccounts(this.axiosInstance);
1355
1510
  // creates authenticator and adds token to axios instance
1356
- _context.next = 11;
1511
+ _context.next = 12;
1357
1512
  return this.authenticator.initializeAuth(sfClientId, sfClientSecret, onTokenRefresh);
1358
- case 11:
1513
+ case 12:
1359
1514
  case "end":
1360
1515
  return _context.stop();
1361
1516
  }