pha-hermes 1.23.0 → 1.25.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.
@@ -1,11 +1,19 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { Practitioner } 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>;
18
+ fetchRoles(): Promise<Role[]>;
11
19
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export declare const SF_API_VERSION: string;
1
2
  export { SFApiClient } from './api/salesforce/apiClient';
2
3
  export { SFPractitionerClient } from './api/salesforce/practitioner/practitionerClient';
3
4
  export { SFTimesheetClient } from './api/salesforce/timesheet/timesheetClient';
@@ -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;
@@ -531,7 +540,7 @@ var SFTimesheetClient = /*#__PURE__*/function () {
531
540
  while (1) switch (_context.prev = _context.next) {
532
541
  case 0:
533
542
  _context.prev = 0;
534
- url = "/services/data/" + SF_API_VERSION + "/sobjects/TimeSheetHour__c/" + timesheetHourId;
543
+ url = "/services/data/" + SF_API_VERSION$1 + "/sobjects/TimeSheetHour__c/" + timesheetHourId;
535
544
  _context.next = 4;
536
545
  return this.axiosInstance.patch(url, {
537
546
  Date__c: timesheet.date,
@@ -583,7 +592,7 @@ var SFTimesheetClient = /*#__PURE__*/function () {
583
592
  while (1) switch (_context2.prev = _context2.next) {
584
593
  case 0:
585
594
  // Find all timesheet Ids that belong to this WO
586
- url = "/services/data/" + SF_API_VERSION + "/query";
595
+ url = "/services/data/" + SF_API_VERSION$1 + "/query";
587
596
  query = "SELECT Id\n FROM Timesheet__c\n WHERE WorkOrder__c = '" + workorderId + "'";
588
597
  try {
589
598
  if (periodStartDate && periodEndDate) {
@@ -621,7 +630,7 @@ var SFTimesheetClient = /*#__PURE__*/function () {
621
630
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
622
631
  while (1) switch (_context3.prev = _context3.next) {
623
632
  case 0:
624
- url = "/services/data/" + SF_API_VERSION + "/query";
633
+ url = "/services/data/" + SF_API_VERSION$1 + "/query";
625
634
  query = "SELECT FIELDS(STANDARD), WorkOrder__c\n FROM TimeSheet__c\n WHERE WorkOrder__c IN (SELECT Id\n FROM WorkOrder__c\n WHERE Personnel__c = '" + personnelID + "')";
626
635
  _context3.next = 4;
627
636
  return this.axiosInstance.get(url, {
@@ -663,7 +672,7 @@ var SFTimesheetClient = /*#__PURE__*/function () {
663
672
  case 2:
664
673
  timesheetIds = _context4.sent;
665
674
  allHours = [];
666
- url = "/services/data/" + SF_API_VERSION + "/query";
675
+ url = "/services/data/" + SF_API_VERSION$1 + "/query";
667
676
  _iterator2 = _createForOfIteratorHelperLoose(timesheetIds);
668
677
  case 6:
669
678
  if ((_step2 = _iterator2()).done) {
@@ -673,7 +682,7 @@ var SFTimesheetClient = /*#__PURE__*/function () {
673
682
  timesheetId = _step2.value;
674
683
  query = "\n SELECT " + ((fields == null ? void 0 : fields.join(',')) || 'FIELDS(STANDARD)') + "\n FROM TimesheetHour__c\n WHERE Timesheet__c = '" + timesheetId + "'";
675
684
  _context4.prev = 9;
676
- if (fields != null && fields.length) {
685
+ if (fields != null && fields.length && periodStartDate && periodEndDate) {
677
686
  query += "\n AND Date__c >= " + new Date(periodStartDate).toISOString().substring(0, 10) + "\n AND Date__c <= " + new Date(periodEndDate).toISOString().substring(0, 10);
678
687
  }
679
688
  _context4.next = 13;
@@ -714,7 +723,7 @@ var SFTimesheetClient = /*#__PURE__*/function () {
714
723
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
715
724
  while (1) switch (_context5.prev = _context5.next) {
716
725
  case 0:
717
- url = "/services/data/" + SF_API_VERSION + "/query";
726
+ url = "/services/data/" + SF_API_VERSION$1 + "/query";
718
727
  query = "SELECT Name,\n StartDate__c,\n EndDate__c\n FROM PayPeriod__c";
719
728
  _context5.next = 4;
720
729
  return this.axiosInstance.get(url, {
@@ -764,14 +773,14 @@ var SFTimesheetClient = /*#__PURE__*/function () {
764
773
  contentType: 'application/octet-stream'
765
774
  });
766
775
  _context6.next = 6;
767
- return this.axiosInstance.post("/services/data/" + SF_API_VERSION + "/sobjects/ContentVersion", form, {
776
+ return this.axiosInstance.post("/services/data/" + SF_API_VERSION$1 + "/sobjects/ContentVersion", form, {
768
777
  headers: form.getHeaders()
769
778
  });
770
779
  case 6:
771
780
  uploadRes = _context6.sent;
772
781
  versionId = uploadRes.data.id; //get ContentDocumentId
773
782
  _context6.next = 10;
774
- return this.axiosInstance.get("/services/data/" + SF_API_VERSION + "/query", {
783
+ return this.axiosInstance.get("/services/data/" + SF_API_VERSION$1 + "/query", {
775
784
  params: {
776
785
  q: "SELECT ContentDocumentId FROM ContentVersion WHERE Id = '" + versionId + "'"
777
786
  }
@@ -781,7 +790,7 @@ var SFTimesheetClient = /*#__PURE__*/function () {
781
790
  data = _yield$this$axiosInst3.data;
782
791
  contentDocumentId = data.records[0].ContentDocumentId;
783
792
  _context6.next = 15;
784
- return this.axiosInstance.post("/services/data/" + SF_API_VERSION + "/sobjects/ContentDocumentLink", {
793
+ return this.axiosInstance.post("/services/data/" + SF_API_VERSION$1 + "/sobjects/ContentDocumentLink", {
785
794
  ContentDocumentId: contentDocumentId,
786
795
  LinkedEntityId: timesheetId,
787
796
  ShareType: 'V',
@@ -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:
@@ -849,28 +862,29 @@ var SFPractitionerClient = /*#__PURE__*/function () {
849
862
  }
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
- url = "/services/data/" + SF_API_VERSION + "/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;
865
+ url = "/services/data/" + SF_API_VERSION$1 + "/query";
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);
@@ -884,7 +898,7 @@ var SFPractitionerClient = /*#__PURE__*/function () {
884
898
  while (1) switch (_context2.prev = _context2.next) {
885
899
  case 0:
886
900
  _context2.prev = 0;
887
- url = "/services/data/" + SF_API_VERSION + "/query";
901
+ url = "/services/data/" + SF_API_VERSION$1 + "/query";
888
902
  query = "\n SELECT Id, FirstName__c, LastName__c, Email__c, StaffID__c, CreatedDate\n FROM Personnel__c\n WHERE Status__c = 'Active' AND Email__c = '" + email + "'\n ";
889
903
  _context2.next = 5;
890
904
  return this.axiosInstance.get(url, {
@@ -918,6 +932,47 @@ var SFPractitionerClient = /*#__PURE__*/function () {
918
932
  }
919
933
  return fetchPractitionerByEmail;
920
934
  }();
935
+ _proto.fetchRoles = /*#__PURE__*/function () {
936
+ var _fetchRoles = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
937
+ var url, query;
938
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
939
+ while (1) switch (_context3.prev = _context3.next) {
940
+ case 0:
941
+ _context3.prev = 0;
942
+ url = "/services/data/" + SF_API_VERSION$1 + "/query";
943
+ query = "SELECT Label, Value FROM PicklistValueInfo WHERE EntityParticle.EntityDefinition.QualifiedApiName = 'WorkOrder__c' AND EntityParticle.QualifiedApiName = 'ProfessionalDesignation__c' AND isActive = true";
944
+ return _context3.abrupt("return", this.axiosInstance.get(url, {
945
+ params: {
946
+ q: query
947
+ }
948
+ }).then(function (_ref) {
949
+ var records = _ref.data.records;
950
+ return records.map(function (record) {
951
+ return {
952
+ label: record.Label,
953
+ value: record.Value
954
+ };
955
+ });
956
+ })["catch"](function (error) {
957
+ console.error('Error fetching roles: ', error.message);
958
+ throw error;
959
+ }));
960
+ case 6:
961
+ _context3.prev = 6;
962
+ _context3.t0 = _context3["catch"](0);
963
+ console.error('Error fetching roles: ', _context3.t0.message);
964
+ throw _context3.t0;
965
+ case 10:
966
+ case "end":
967
+ return _context3.stop();
968
+ }
969
+ }, _callee3, this, [[0, 6]]);
970
+ }));
971
+ function fetchRoles() {
972
+ return _fetchRoles.apply(this, arguments);
973
+ }
974
+ return fetchRoles;
975
+ }();
921
976
  return SFPractitionerClient;
922
977
  }();
923
978
  function toPractitioner(raw) {
@@ -927,9 +982,24 @@ function toPractitioner(raw) {
927
982
  lastName: raw.LastName__c,
928
983
  email: raw.Email__c,
929
984
  staffId: raw.StaffID__c,
930
- createdAt: raw.CreatedDate.replace(/\+0000$/, 'Z')
985
+ createdAt: raw.CreatedDate ? raw.CreatedDate.replace(/\+0000$/, 'Z') : undefined
931
986
  };
932
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
+ }
933
1003
 
934
1004
  var SFWorkorderClient = /*#__PURE__*/function () {
935
1005
  function SFWorkorderClient(axiosInstance) {
@@ -962,7 +1032,7 @@ var SFWorkorderClient = /*#__PURE__*/function () {
962
1032
  filters.push("Region__c IN (" + provincesList + ")");
963
1033
  }
964
1034
  whereClause = filters.length ? "WHERE " + filters.join(' AND ') : '';
965
- url = "/services/data/" + SF_API_VERSION + "/query";
1035
+ url = "/services/data/" + SF_API_VERSION$1 + "/query";
966
1036
  query = "SELECT Id,\n Region__c,\n Name,\n HospitalID__c,\n HospitalName__c,\n ProfessionalDesignation__c,\n Personnel__c,\n startdate__c,\n EndDate__c,\n CreatedDate,\n LastModifiedDate,\n Unit__c,\n HealthAuthority__c,\n UnitPrice__r.Price__c,\n TravelDate__c,\n ReturnDate__c\n FROM WorkOrder__c " + whereClause;
967
1037
  _context.next = 11;
968
1038
  return this.axiosInstance.get(url, {
@@ -1034,7 +1104,7 @@ var SFPayPeriodClient = /*#__PURE__*/function () {
1034
1104
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1035
1105
  while (1) switch (_context.prev = _context.next) {
1036
1106
  case 0:
1037
- url = "/services/data/" + SF_API_VERSION + "/query";
1107
+ url = "/services/data/" + SF_API_VERSION$1 + "/query";
1038
1108
  query = "SELECT PayPeriod__c, ID\n FROM Timesheet__c\n WHERE WorkOrder__c = '" + workorderID + "'";
1039
1109
  _context.next = 4;
1040
1110
  return this.axiosInstance.get(url, {
@@ -1070,7 +1140,7 @@ var SFPayPeriodClient = /*#__PURE__*/function () {
1070
1140
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1071
1141
  while (1) switch (_context2.prev = _context2.next) {
1072
1142
  case 0:
1073
- url = "/services/data/" + SF_API_VERSION + "/query";
1143
+ url = "/services/data/" + SF_API_VERSION$1 + "/query";
1074
1144
  query = "SELECT ID, StartDate__c, EndDate__c\n FROM PayPeriod__c\n WHERE id IN " + listOfIdsForQuery(payPeriodIDs);
1075
1145
  _context2.next = 4;
1076
1146
  return this.axiosInstance.get(url, {
@@ -1104,7 +1174,7 @@ var SFPayPeriodClient = /*#__PURE__*/function () {
1104
1174
  return SFPayPeriodClient;
1105
1175
  }();
1106
1176
  var listOfIdsForQuery = function listOfIdsForQuery(payPeriodIDs) {
1107
- return "('" + payPeriodIDs.join('\', \'') + "')";
1177
+ return "('" + payPeriodIDs.join("', '") + "')";
1108
1178
  };
1109
1179
 
1110
1180
  var EXPENSE_FIELD_MAP = {
@@ -1125,7 +1195,7 @@ var SFExpenseClient = /*#__PURE__*/function () {
1125
1195
  while (1) switch (_context.prev = _context.next) {
1126
1196
  case 0:
1127
1197
  _context.prev = 0;
1128
- url = "/services/data/" + SF_API_VERSION + "/sobjects/Timesheet__c/" + timesheetId;
1198
+ url = "/services/data/" + SF_API_VERSION$1 + "/sobjects/Timesheet__c/" + timesheetId;
1129
1199
  _context.next = 4;
1130
1200
  return this.axiosInstance.get(url, {
1131
1201
  params: {
@@ -1164,7 +1234,7 @@ var SFExpenseClient = /*#__PURE__*/function () {
1164
1234
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1165
1235
  while (1) switch (_context2.prev = _context2.next) {
1166
1236
  case 0:
1167
- url = "/services/data/" + SF_API_VERSION + "/sobjects/Timesheet__c/" + timesheetId;
1237
+ url = "/services/data/" + SF_API_VERSION$1 + "/sobjects/Timesheet__c/" + timesheetId;
1168
1238
  _context2.next = 3;
1169
1239
  return this.axiosInstance.patch(url, body);
1170
1240
  case 3:
@@ -1238,7 +1308,7 @@ var SFPriceClient = /*#__PURE__*/function () {
1238
1308
  while (1) switch (_context.prev = _context.next) {
1239
1309
  case 0:
1240
1310
  _context.prev = 0;
1241
- url = "/services/data/" + SF_API_VERSION + "/query";
1311
+ url = "/services/data/" + SF_API_VERSION$1 + "/query";
1242
1312
  query = "SELECT UnitPrice__r.Price__r.Id,\n UnitPrice__r.Price__r.Name,\n UnitPrice__r.Price__r.MileageBillingRate__c,\n UnitPrice__r.Price__r.MileageWageRate__c,\n UnitPrice__r.Price__r.BillingRate__c,\n UnitPrice__r.Price__r.WageRate__c,\n UnitPrice__r.Price__r.Overtime1BillingRate__c,\n UnitPrice__r.Price__r.Overtime1WageRate__c,\n UnitPrice__r.Price__r.Overtime2BillingRate__c,\n UnitPrice__r.Price__r.Overtime2WageRate__c,\n UnitPrice__r.Price__r.CallBackBillingRate__c,\n UnitPrice__r.Price__r.CallBackWageRate__c,\n UnitPrice__r.Price__r.OnCallBillingRate__c,\n UnitPrice__r.Price__r.OnCallWageRate__c,\n UnitPrice__r.Price__r.Additional_Billing_Information__c,\n UnitPrice__r.Price__r.Additional_Wage_Information__c\n FROM WorkOrder__c WHERE Id = '" + workorderId + "' ";
1243
1313
  _context.next = 5;
1244
1314
  return this.axiosInstance.get(url, {
@@ -1841,6 +1911,8 @@ var LipheApiClient = /*#__PURE__*/function () {
1841
1911
  Agency["SSI"] = "99";
1842
1912
  })(exports.Agency || (exports.Agency = {}));
1843
1913
 
1914
+ var SF_API_VERSION$1 = 'v57.0';
1915
+
1844
1916
  exports.LipheApiClient = LipheApiClient;
1845
1917
  exports.LipheAuthenticator = LipheAuthenticator;
1846
1918
  exports.LiphePractitionerClient = LiphePractitionerClient;
@@ -1850,4 +1922,5 @@ exports.SFExpenseClient = SFExpenseClient;
1850
1922
  exports.SFPractitionerClient = SFPractitionerClient;
1851
1923
  exports.SFPriceClient = SFPriceClient;
1852
1924
  exports.SFTimesheetClient = SFTimesheetClient;
1925
+ exports.SF_API_VERSION = SF_API_VERSION$1;
1853
1926
  //# sourceMappingURL=pha-hermes.cjs.development.js.map