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.
@@ -49,6 +49,15 @@ function _createForOfIteratorHelperLoose(r, e) {
49
49
  }
50
50
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
51
51
  }
52
+ function _extends() {
53
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
54
+ for (var e = 1; e < arguments.length; e++) {
55
+ var t = arguments[e];
56
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
57
+ }
58
+ return n;
59
+ }, _extends.apply(null, arguments);
60
+ }
52
61
  function _regeneratorRuntime() {
53
62
  _regeneratorRuntime = function () {
54
63
  return e;
@@ -827,12 +836,16 @@ function toTimesheetDayEntry(raw) {
827
836
 
828
837
  var SFPractitionerClient = /*#__PURE__*/function () {
829
838
  function SFPractitionerClient(axiosInstance) {
839
+ this.PRACTITIONER_FIELDS = {
840
+ "default": ['Id', 'FirstName__c', 'LastName__c', 'Email__c', 'StaffID__c', 'CreatedDate'],
841
+ "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']
842
+ };
830
843
  this.axiosInstance = axiosInstance;
831
844
  }
832
845
  var _proto = SFPractitionerClient.prototype;
833
846
  _proto.fetchPractitioners = /*#__PURE__*/function () {
834
847
  var _fetchPractitioners = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
835
- var conditions, whereClause, limitClause, url, query, _yield$this$axiosInst, records;
848
+ var conditions, whereClause, limitClause, url, fields, query, _yield$this$axiosInst, records;
836
849
  return _regeneratorRuntime().wrap(function _callee$(_context) {
837
850
  while (1) switch (_context.prev = _context.next) {
838
851
  case 0:
@@ -844,27 +857,28 @@ var SFPractitionerClient = /*#__PURE__*/function () {
844
857
  whereClause = conditions.length ? "WHERE " + conditions.join(' AND ') : '';
845
858
  limitClause = typeof (options == null ? void 0 : options.limit) === 'number' && options.limit > 0 ? "LIMIT " + Math.floor(options.limit) : '';
846
859
  url = "/services/data/" + SF_API_VERSION$1 + "/query";
847
- 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 ";
848
- _context.next = 9;
860
+ fields = (options != null && options.forExport ? this.PRACTITIONER_FIELDS["export"] : this.PRACTITIONER_FIELDS["default"]).join(', ');
861
+ query = "\n SELECT " + fields + "\n FROM Personnel__c\n " + whereClause + "\n ORDER BY CreatedDate ASC, StaffID__c ASC\n " + limitClause + "\n ";
862
+ _context.next = 10;
849
863
  return this.axiosInstance.get(url, {
850
864
  params: {
851
865
  q: query
852
866
  }
853
867
  });
854
- case 9:
868
+ case 10:
855
869
  _yield$this$axiosInst = _context.sent;
856
870
  records = _yield$this$axiosInst.data.records;
857
- return _context.abrupt("return", records.map(toPractitioner));
858
- case 14:
859
- _context.prev = 14;
871
+ return _context.abrupt("return", options != null && options.forExport ? records.map(toPractitionerExport) : records.map(toPractitioner));
872
+ case 15:
873
+ _context.prev = 15;
860
874
  _context.t0 = _context["catch"](0);
861
875
  console.error('Error fetching practitioners: ', _context.t0.message);
862
876
  throw _context.t0;
863
- case 18:
877
+ case 19:
864
878
  case "end":
865
879
  return _context.stop();
866
880
  }
867
- }, _callee, this, [[0, 14]]);
881
+ }, _callee, this, [[0, 15]]);
868
882
  }));
869
883
  function fetchPractitioners(_x) {
870
884
  return _fetchPractitioners.apply(this, arguments);
@@ -965,6 +979,21 @@ function toPractitioner(raw) {
965
979
  createdAt: raw.CreatedDate ? raw.CreatedDate.replace(/\+0000$/, 'Z') : undefined
966
980
  };
967
981
  }
982
+ function toPractitionerExport(raw) {
983
+ return _extends({}, toPractitioner(raw), {
984
+ phone: raw.DaytimePhone__c,
985
+ status: raw.Status__c,
986
+ professionalDesignation: raw.ProfessionalDesignation__c,
987
+ SIN: raw.CANSocialInsuranceNumber__c,
988
+ hiringDate: raw.Date_of_Hire__c,
989
+ dateApplied: raw.DateApplied__c,
990
+ birthdate: raw.Birthdate__c,
991
+ mailingStreetAddress: raw.MailingStreetAddress__c,
992
+ mailingCity: raw.MailingCity__c,
993
+ mailingProvince: raw.MailingStateProvince__c,
994
+ mailingZip: raw.MailingZipPostalCode__c
995
+ });
996
+ }
968
997
 
969
998
  var SFWorkorderClient = /*#__PURE__*/function () {
970
999
  function SFWorkorderClient(axiosInstance) {
@@ -1325,6 +1354,131 @@ var SFPriceClient = /*#__PURE__*/function () {
1325
1354
  return SFPriceClient;
1326
1355
  }();
1327
1356
 
1357
+ var ACCOUNT_FIELDS = ['Id', 'Name', 'BillingCity', 'BillingState', 'BillingPostalCode', 'BillingCountry', 'BillingAddress', 'Phone', 'Fax', 'Type'];
1358
+ var SFAccounts = /*#__PURE__*/function () {
1359
+ function SFAccounts(axiosInstance) {
1360
+ this.axiosInstance = axiosInstance;
1361
+ }
1362
+ var _proto = SFAccounts.prototype;
1363
+ _proto.fetchAccounts = /*#__PURE__*/function () {
1364
+ var _fetchAccounts = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(type, options) {
1365
+ var _this = this;
1366
+ var accountType, query, response, accounts, i, pageNumber, childAccounts, returnedPageSize, _options$pageSize, pageAccounts;
1367
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1368
+ while (1) switch (_context.prev = _context.next) {
1369
+ case 0:
1370
+ _context.prev = 0;
1371
+ _context.t0 = type;
1372
+ _context.next = _context.t0 === 'healthAuthority' ? 4 : _context.t0 === 'establishment' ? 6 : 7;
1373
+ break;
1374
+ case 4:
1375
+ accountType = 'Health Authority';
1376
+ return _context.abrupt("break", 7);
1377
+ case 6:
1378
+ accountType = 'Hospital';
1379
+ case 7:
1380
+ query = "SELECT " + ACCOUNT_FIELDS.join(',') + " FROM Account WHERE Type = '" + accountType + "'";
1381
+ if (options != null && options.parentId) query += " AND ParentId = '" + options.parentId + "'";
1382
+ if (options != null && options.pageSize) query += " LIMIT " + options.pageSize;
1383
+ if (options != null && options.pageNumber) query += " OFFSET " + options.pageNumber * options.pageSize;
1384
+ _context.next = 13;
1385
+ return this.axiosInstance.get("/services/data/v57.0/query?q=" + query);
1386
+ case 13:
1387
+ response = _context.sent;
1388
+ accounts = response.data.records.map(function (record) {
1389
+ return _this.buildAccount(record);
1390
+ });
1391
+ _context.t1 = _regeneratorRuntime().keys(accounts);
1392
+ case 16:
1393
+ if ((_context.t2 = _context.t1()).done) {
1394
+ _context.next = 32;
1395
+ break;
1396
+ }
1397
+ i = _context.t2.value;
1398
+ if (!(accounts[i].accountTypeName === 'healthAuthority')) {
1399
+ _context.next = 30;
1400
+ break;
1401
+ }
1402
+ pageNumber = 0;
1403
+ childAccounts = [];
1404
+ returnedPageSize = 0;
1405
+ case 22:
1406
+ _context.next = 24;
1407
+ return this.fetchAccounts('establishment', {
1408
+ parentId: accounts[i].id,
1409
+ pageSize: (_options$pageSize = options == null ? void 0 : options.pageSize) != null ? _options$pageSize : 100,
1410
+ pageNumber: pageNumber,
1411
+ failfast: options == null ? void 0 : options.failfast
1412
+ });
1413
+ case 24:
1414
+ pageAccounts = _context.sent;
1415
+ childAccounts.push.apply(childAccounts, pageAccounts);
1416
+ returnedPageSize = pageAccounts.length;
1417
+ pageNumber++;
1418
+ case 28:
1419
+ if (returnedPageSize > 0) {
1420
+ _context.next = 22;
1421
+ break;
1422
+ }
1423
+ case 29:
1424
+ accounts[i].children = childAccounts;
1425
+ case 30:
1426
+ _context.next = 16;
1427
+ break;
1428
+ case 32:
1429
+ return _context.abrupt("return", accounts);
1430
+ case 35:
1431
+ _context.prev = 35;
1432
+ _context.t3 = _context["catch"](0);
1433
+ console.error("Error fetching " + type + "s: ", _context.t3.message);
1434
+ if (!(options != null && options.failfast)) {
1435
+ _context.next = 40;
1436
+ break;
1437
+ }
1438
+ throw _context.t3;
1439
+ case 40:
1440
+ return _context.abrupt("return", []);
1441
+ case 41:
1442
+ case "end":
1443
+ return _context.stop();
1444
+ }
1445
+ }, _callee, this, [[0, 35]]);
1446
+ }));
1447
+ function fetchAccounts(_x, _x2) {
1448
+ return _fetchAccounts.apply(this, arguments);
1449
+ }
1450
+ return fetchAccounts;
1451
+ }();
1452
+ _proto.buildAccount = function buildAccount(record) {
1453
+ var accountType;
1454
+ switch (record.Type) {
1455
+ case 'Health Authority':
1456
+ accountType = 'healthAuthority';
1457
+ break;
1458
+ case 'Hospital':
1459
+ accountType = 'establishment';
1460
+ }
1461
+ return {
1462
+ id: record.Id,
1463
+ name: record.Name,
1464
+ address: record.BillingAddress,
1465
+ city: record.BillingCity,
1466
+ province: record.BillingState,
1467
+ postalCode: record.BillingPostalCode,
1468
+ geographicalAreaName: record.BillingGeocodeAccuracy,
1469
+ phone: record.Phone,
1470
+ fax: record.Fax,
1471
+ regionName: record.RegionName,
1472
+ accountTypeName: accountType,
1473
+ email: null,
1474
+ phone2: null,
1475
+ cellular: null,
1476
+ lang: 'eng'
1477
+ };
1478
+ };
1479
+ return SFAccounts;
1480
+ }();
1481
+
1328
1482
  var SF_API_VERSION = 'v57.0';
1329
1483
  var SFApiClient = /*#__PURE__*/function () {
1330
1484
  function SFApiClient() {
@@ -1346,10 +1500,11 @@ var SFApiClient = /*#__PURE__*/function () {
1346
1500
  this.payPeriodClient = new SFPayPeriodClient(this.axiosInstance);
1347
1501
  this.expenseClient = new SFExpenseClient(this.axiosInstance);
1348
1502
  this.priceClient = new SFPriceClient(this.axiosInstance);
1503
+ this.accountsClient = new SFAccounts(this.axiosInstance);
1349
1504
  // creates authenticator and adds token to axios instance
1350
- _context.next = 11;
1505
+ _context.next = 12;
1351
1506
  return this.authenticator.initializeAuth(sfClientId, sfClientSecret, onTokenRefresh);
1352
- case 11:
1507
+ case 12:
1353
1508
  case "end":
1354
1509
  return _context.stop();
1355
1510
  }