@unite-us/app-create-referral 0.15.176 → 0.15.177

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.
@@ -3,7 +3,8 @@ import moment from 'moment';
3
3
  import { feeScheduleProgramUtils } from '@unite-us/app-components';
4
4
  import { isUnlistedProgram, referralIsOON, referralIsGrouped } from '../pages/builder/utils';
5
5
  import { resolveAttachmentFields } from '../utils/attachmentUtils';
6
- import { useCreateRecord, useUpdateRecord } from '../api/ApiHooks';
6
+ import { atomicOperations as atomicOperationBuilders } from '@unite-us/json-api-resources';
7
+ import { useAtomicOperations, useCreateRecord, useUpdateRecord } from '../api/ApiHooks';
7
8
  import { CALLBACKS, coreApi } from '../api/config';
8
9
  import { useAppCreateReferralContext } from '../context/AppCreateReferralProvider';
9
10
  import { useFeatureFlag } from '../utils/useFeatureFlag';
@@ -222,6 +223,10 @@ export default function useCreateReferrals() {
222
223
  const hint542SupersetUnlistedPrograms = useFeatureFlag('hint542SupersetUnlistedPrograms', false);
223
224
  const pays5590RefactorInsuranceFilters = useFeatureFlag('pays5590RefactorInsuranceFilters', false);
224
225
  const showClientNeed = useFeatureFlag('crtb2130MultipleClientNeeds', false);
226
+ const atomicReferralCreationEnabled = useFeatureFlag('pays11587AtomicReferralCreation', false);
227
+ const {
228
+ atomicOperations
229
+ } = useAtomicOperations();
225
230
  const {
226
231
  createRecord: createReferral
227
232
  } = useCreateRecord('referral');
@@ -247,27 +252,37 @@ export default function useCreateReferrals() {
247
252
  updateRecord: updateServiceAuthorization
248
253
  } = useUpdateRecord('service_authorization');
249
254
  const createErrorMessage = error => {
250
- return error.response.data.errors.map(error => error.title).join(', ');
255
+ const errors = get(error, 'response.data.errors', []);
256
+ return errors.length ? errors.map(_ref7 => {
257
+ let {
258
+ title
259
+ } = _ref7;
260
+ return title;
261
+ }).join(', ') : error?.message || 'Unknown error';
251
262
  };
252
- const getAttachmentOperations = function (referral, caseToUploadDoc) {
253
- let {
254
- removePersistedDocuments = false
255
- } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
263
+ const getExistingAttachedDocuments = referral => {
256
264
  const attachableDocuments = get(referral, 'attachableDocuments', []);
257
265
  const filteredDocuments = attachableDocuments.filter(doc => doc?.attached === true);
258
- const attachedDocuments = filteredDocuments.map(ad => ({
266
+ return filteredDocuments.map(ad => ({
259
267
  title: get(ad, 'document.title'),
260
268
  id: get(ad, 'document.id')
261
269
  }));
270
+ };
271
+ const getAttachmentOperations = function (referral, caseToUploadDoc) {
272
+ let {
273
+ removePersistedDocuments = false,
274
+ skipExistingDocumentRelationship = false
275
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
276
+ const attachedDocuments = skipExistingDocumentRelationship ? [] : getExistingAttachedDocuments(referral);
262
277
  const operations = [];
263
278
  if (!isEmpty(attachedDocuments)) {
264
279
  operations.push({
265
280
  operation: 'relationship',
266
- name: attachedDocuments.map(_ref7 => {
281
+ name: attachedDocuments.map(_ref8 => {
267
282
  let {
268
283
  title,
269
284
  id
270
- } = _ref7;
285
+ } = _ref8;
271
286
  return title || id;
272
287
  }).join(', '),
273
288
  execute: () => coreApi.setRelationship('case', caseToUploadDoc.id, {
@@ -278,10 +293,10 @@ export default function useCreateReferrals() {
278
293
  }
279
294
  const uploadedDocuments = get(referral, 'pendingAttachments', []);
280
295
  if (!isEmpty(uploadedDocuments)) {
281
- operations.push(...uploadedDocuments.map(_ref8 => {
296
+ operations.push(...uploadedDocuments.map(_ref9 => {
282
297
  let {
283
298
  file
284
- } = _ref8;
299
+ } = _ref9;
285
300
  return {
286
301
  operation: 'upload',
287
302
  name: file?.name || 'attachment',
@@ -301,10 +316,10 @@ export default function useCreateReferrals() {
301
316
  };
302
317
  const processAttachments = async (referral, caseToUploadDoc, options) => {
303
318
  const operations = getAttachmentOperations(referral, caseToUploadDoc, options);
304
- const settledOperations = await Promise.allSettled(operations.map(_ref9 => {
319
+ const settledOperations = await Promise.allSettled(operations.map(_ref0 => {
305
320
  let {
306
321
  execute
307
- } = _ref9;
322
+ } = _ref0;
308
323
  return Promise.resolve().then(execute);
309
324
  }));
310
325
  return {
@@ -316,11 +331,11 @@ export default function useCreateReferrals() {
316
331
  }] : errors, [])
317
332
  };
318
333
  };
319
- const submitAssessments = _ref0 => {
334
+ const submitAssessments = _ref1 => {
320
335
  let {
321
336
  cases,
322
337
  latestResponses
323
- } = _ref0;
338
+ } = _ref1;
324
339
  let promises = [];
325
340
  map(cases, serviceCase => {
326
341
  map(latestResponses || formResponses, assessment => {
@@ -343,13 +358,13 @@ export default function useCreateReferrals() {
343
358
  throw err;
344
359
  });
345
360
  };
346
- const fetchActiveInsurance = async _ref1 => {
361
+ const fetchActiveInsurance = async _ref10 => {
347
362
  let {
348
363
  personId,
349
364
  feeScheduleId,
350
365
  requestedStartDate,
351
366
  requestedEndDate
352
- } = _ref1;
367
+ } = _ref10;
353
368
  const queryInsuranceParams = {
354
369
  person: personId,
355
370
  state: 'active',
@@ -361,17 +376,16 @@ export default function useCreateReferrals() {
361
376
  const responseInsurances = await coreApi.query('insurance', queryInsuranceParams);
362
377
  return responseInsurances?.data?.data?.[0];
363
378
  };
364
- const saveServiceAuthorization = async _ref10 => {
379
+ const getAuthorizationPayload = async _ref11 => {
365
380
  let {
366
381
  referral,
367
- caseId,
368
382
  personId,
369
383
  draft,
370
384
  serviceAuthorizationId
371
- } = _ref10;
385
+ } = _ref11;
372
386
  const feeScheduleProgram = referral.programs[0].fee_schedule_program;
373
387
  if (!feeScheduleProgram?.authorization_required) {
374
- return false;
388
+ return null;
375
389
  }
376
390
  const {
377
391
  requestedStartDate,
@@ -386,7 +400,7 @@ export default function useCreateReferrals() {
386
400
  const amountRequested = referral.paymentAuthForm.amount_requested;
387
401
  const icd10CodeId = get(referral, 'paymentAuthForm.icd10_code.id');
388
402
  const icd10Codes = icd10CodeId ? [icd10CodeId] : [];
389
- const payload = {
403
+ return {
390
404
  ...buildServiceAuthorizationStatePayload({
391
405
  serviceAuthorizationId,
392
406
  draft
@@ -403,6 +417,24 @@ export default function useCreateReferrals() {
403
417
  person: personId,
404
418
  clinical_modifications: icd10Codes
405
419
  };
420
+ };
421
+ const saveServiceAuthorization = async _ref12 => {
422
+ let {
423
+ referral,
424
+ caseId,
425
+ personId,
426
+ draft,
427
+ serviceAuthorizationId
428
+ } = _ref12;
429
+ const payload = await getAuthorizationPayload({
430
+ referral,
431
+ personId,
432
+ draft,
433
+ serviceAuthorizationId
434
+ });
435
+ if (!payload) {
436
+ return false;
437
+ }
406
438
  if (serviceAuthorizationId) {
407
439
  await updateServiceAuthorization(serviceAuthorizationId, payload);
408
440
  } else {
@@ -413,13 +445,13 @@ export default function useCreateReferrals() {
413
445
  }
414
446
  return true;
415
447
  };
416
- const createAuthorizationIfNeeded = async _ref11 => {
448
+ const createAuthorizationIfNeeded = async _ref13 => {
417
449
  let {
418
450
  referral,
419
451
  caseId,
420
452
  personId,
421
453
  draft
422
- } = _ref11;
454
+ } = _ref13;
423
455
  return saveServiceAuthorization({
424
456
  referral,
425
457
  caseId,
@@ -427,7 +459,7 @@ export default function useCreateReferrals() {
427
459
  draft
428
460
  });
429
461
  };
430
- const createCaseForReferral = async _ref12 => {
462
+ const createCaseForReferral = async _ref14 => {
431
463
  let {
432
464
  referral,
433
465
  index,
@@ -435,7 +467,7 @@ export default function useCreateReferrals() {
435
467
  isOON,
436
468
  draft,
437
469
  result
438
- } = _ref12;
470
+ } = _ref14;
439
471
  const caseValues = getCaseValues({
440
472
  referral,
441
473
  personId,
@@ -481,14 +513,12 @@ export default function useCreateReferrals() {
481
513
  return null;
482
514
  }
483
515
  };
484
- const createUnlistedProgramNote = async _ref13 => {
516
+ const getUnlistedProgramNoteValues = _ref15 => {
485
517
  let {
486
518
  programData,
487
- caseId,
488
- index,
489
- result
490
- } = _ref13;
491
- const createNoteForUnlistedProgramValues = {
519
+ caseId
520
+ } = _ref15;
521
+ return {
492
522
  subjectType: 'case',
493
523
  subject: caseId,
494
524
  employee: currentEmployee.id,
@@ -496,6 +526,18 @@ export default function useCreateReferrals() {
496
526
  category: 'external_provider',
497
527
  text: `Referred off platform to ${programData.name}`
498
528
  };
529
+ };
530
+ const createUnlistedProgramNote = async _ref16 => {
531
+ let {
532
+ programData,
533
+ caseId,
534
+ index,
535
+ result
536
+ } = _ref16;
537
+ const createNoteForUnlistedProgramValues = getUnlistedProgramNoteValues({
538
+ programData,
539
+ caseId
540
+ });
499
541
  const missingNoteValues = validateRequiredValues('note', createNoteForUnlistedProgramValues);
500
542
  if (missingNoteValues.length) {
501
543
  result.shippingDetail[index].error = `The following fields for the unlisted program are required: ${missingNoteValues.join(', ')}`;
@@ -517,18 +559,15 @@ export default function useCreateReferrals() {
517
559
  return false;
518
560
  }
519
561
  };
520
- const createProgramReferral = async _ref14 => {
562
+ const getProgramReferralValues = _ref17 => {
521
563
  let {
522
564
  referral,
523
565
  programData,
524
566
  state,
525
567
  isGrouped,
526
- caseId,
527
- index,
528
- result,
529
- createdReferrals
530
- } = _ref14;
531
- const referralValues = {
568
+ caseId
569
+ } = _ref17;
570
+ return {
532
571
  state,
533
572
  case: caseId,
534
573
  is_grouped: isGrouped,
@@ -539,6 +578,25 @@ export default function useCreateReferrals() {
539
578
  sending_network: referral.network.id,
540
579
  ...personConditionsPayload(referral.client_need)
541
580
  };
581
+ };
582
+ const createProgramReferral = async _ref18 => {
583
+ let {
584
+ referral,
585
+ programData,
586
+ state,
587
+ isGrouped,
588
+ caseId,
589
+ index,
590
+ result,
591
+ createdReferrals
592
+ } = _ref18;
593
+ const referralValues = getProgramReferralValues({
594
+ referral,
595
+ programData,
596
+ state,
597
+ isGrouped,
598
+ caseId
599
+ });
542
600
  const missingReferralValues = validateRequiredValues('referral', referralValues);
543
601
  if (missingReferralValues.length) {
544
602
  result.shippingDetail[index].error = `The following fields for the referral are required: ${missingReferralValues.join(', ')}`;
@@ -561,7 +619,7 @@ export default function useCreateReferrals() {
561
619
  return null;
562
620
  }
563
621
  };
564
- const processProgramForReferral = async _ref15 => {
622
+ const processProgramForReferral = async _ref19 => {
565
623
  let {
566
624
  referral,
567
625
  programData,
@@ -573,7 +631,7 @@ export default function useCreateReferrals() {
573
631
  index,
574
632
  result,
575
633
  createdReferrals
576
- } = _ref15;
634
+ } = _ref19;
577
635
  const state = getReferralState({
578
636
  draft,
579
637
  isOON,
@@ -598,13 +656,159 @@ export default function useCreateReferrals() {
598
656
  createdReferrals
599
657
  });
600
658
  };
601
- const processDraftReferral = async _ref16 => {
659
+ const getAtomicResultData = (response, index) => get(response, ['data', 'atomic:results', index, 'data'], null);
660
+ const processAtomicReferral = async _ref20 => {
602
661
  let {
603
662
  referral,
604
663
  index,
605
664
  draft,
665
+ personId,
606
666
  result
607
- } = _ref16;
667
+ } = _ref20;
668
+ const referredToPrograms = get(referral, 'programs', []);
669
+ const isGrouped = referralIsGrouped(referral);
670
+ const isOON = referralIsOON(referral);
671
+ const caseLid = `case-${index}`;
672
+ const caseValues = getCaseValues({
673
+ referral,
674
+ personId,
675
+ isOON,
676
+ formSubmissionId,
677
+ screeningId
678
+ });
679
+ const missingCaseValues = validateRequiredValues('case', caseValues);
680
+ if (missingCaseValues.length) {
681
+ result.shippingDetail[index].error = `Unexpected error: The following fields for the case are required: ${missingCaseValues.join(', ')}`;
682
+ return;
683
+ }
684
+ try {
685
+ const operations = [atomicOperationBuilders.createRecord('case', caseValues, {
686
+ lid: caseLid
687
+ })];
688
+ const authorizationPayload = await getAuthorizationPayload({
689
+ referral,
690
+ personId,
691
+ draft
692
+ });
693
+ if (authorizationPayload) {
694
+ operations.push(atomicOperationBuilders.createRecord('service_authorization', {
695
+ ...authorizationPayload,
696
+ case: {
697
+ lid: caseLid
698
+ }
699
+ }));
700
+ }
701
+ for (const programData of referredToPrograms) {
702
+ if (hint542SupersetUnlistedPrograms && isUnlistedProgram(programData)) {
703
+ const noteValues = getUnlistedProgramNoteValues({
704
+ programData,
705
+ caseId: caseLid
706
+ });
707
+ const missingNoteValues = validateRequiredValues('note', noteValues);
708
+ if (missingNoteValues.length) {
709
+ result.shippingDetail[index].error = `The following fields for the unlisted program are required: ${missingNoteValues.join(', ')}`;
710
+ return;
711
+ }
712
+ operations.push(atomicOperationBuilders.createRecord('note', {
713
+ ...noteValues,
714
+ subject: {
715
+ lid: caseLid
716
+ }
717
+ }));
718
+ continue;
719
+ }
720
+ const state = getReferralState({
721
+ draft,
722
+ isOON,
723
+ authorizationCreated: Boolean(authorizationPayload)
724
+ });
725
+ const referralValues = getProgramReferralValues({
726
+ referral,
727
+ programData,
728
+ state,
729
+ isGrouped,
730
+ caseId: caseLid
731
+ });
732
+ const missingReferralValues = validateRequiredValues('referral', referralValues);
733
+ if (missingReferralValues.length) {
734
+ result.shippingDetail[index].error = `The following fields for the referral are required: ${missingReferralValues.join(', ')}`;
735
+ return;
736
+ }
737
+ operations.push(atomicOperationBuilders.createRecord('referral', {
738
+ ...referralValues,
739
+ case: {
740
+ lid: caseLid
741
+ }
742
+ }));
743
+ }
744
+ const existingAttachedDocuments = getExistingAttachedDocuments(referral);
745
+ if (!isEmpty(existingAttachedDocuments)) {
746
+ operations.push(atomicOperationBuilders.addToRelationship('case', {
747
+ lid: caseLid
748
+ }, {
749
+ relationship: 'file_uploads',
750
+ relationshipModel: 'file_upload',
751
+ value: existingAttachedDocuments.map(_ref21 => {
752
+ let {
753
+ id
754
+ } = _ref21;
755
+ return id;
756
+ })
757
+ }));
758
+ }
759
+ const response = await atomicOperations(operations);
760
+ const createdCase = getAtomicResultData(response, 0);
761
+ if (!createdCase?.id) {
762
+ const missingCaseError = new Error('Atomic referral creation did not return a case');
763
+ missingCaseError.response = response;
764
+ throw missingCaseError;
765
+ }
766
+ result.cases.push(createdCase);
767
+ updateShippingDetail(result.shippingDetail, index, {
768
+ caseId: createdCase.id,
769
+ sent: true
770
+ });
771
+ const createdReferrals = [];
772
+ operations.slice(1).forEach((operation, operationIndex) => {
773
+ const createdResource = getAtomicResultData(response, operationIndex + 1);
774
+ if (operation.model === 'referral' && createdResource) {
775
+ result.referrals.push({
776
+ ...createdResource,
777
+ referralIndex: index
778
+ });
779
+ createdReferrals.push(createdResource);
780
+ } else if (operation.model === 'note') {
781
+ result.referrals.push({
782
+ index,
783
+ sent: true,
784
+ referralIndex: index
785
+ });
786
+ }
787
+ });
788
+ mergeAttachmentOutcome(result.shippingDetail, index, await processAttachments(referral, createdCase, {
789
+ skipExistingDocumentRelationship: true
790
+ }));
791
+ const referralData = await referralToConsent({
792
+ originalReferral: referral,
793
+ createdReferrals
794
+ });
795
+ if (referralData) {
796
+ result.referralsToConsent.push(referralData);
797
+ }
798
+ } catch (err) {
799
+ result.shippingDetail[index].error = `Error creating the Referral: ${createErrorMessage(err)}`;
800
+ // Non-rendered debug field: source.pointer on each entry is `/atomic:operations/{index}`,
801
+ // which combined with the operation order identifies exactly which operation failed.
802
+ result.shippingDetail[index].rawAtomicErrors = get(err, 'response.data.errors', null) || get(err, 'response.data', null);
803
+ }
804
+ };
805
+ const processDraftReferral = async _ref22 => {
806
+ let {
807
+ referral,
808
+ index,
809
+ draft,
810
+ result
811
+ } = _ref22;
608
812
  const resultDraft = await updateDraftReferralCrtb1239(referral, draft);
609
813
  updateShippingDetail(result.shippingDetail, index, {
610
814
  sent: true,
@@ -628,14 +832,24 @@ export default function useCreateReferrals() {
628
832
  }
629
833
  }
630
834
  };
631
- const processNonDraftReferral = async _ref17 => {
835
+ const processNonDraftReferral = async _ref23 => {
632
836
  let {
633
837
  referral,
634
838
  index,
635
839
  draft,
636
840
  personId,
637
841
  result
638
- } = _ref17;
842
+ } = _ref23;
843
+ if (atomicReferralCreationEnabled && !(assistanceRequestId && index === 0)) {
844
+ await processAtomicReferral({
845
+ referral,
846
+ index,
847
+ draft,
848
+ personId,
849
+ result
850
+ });
851
+ return;
852
+ }
639
853
  const referredToPrograms = get(referral, 'programs', []);
640
854
  const isGrouped = referralIsGrouped(referral);
641
855
  const isOON = referralIsOON(referral);
@@ -687,12 +901,12 @@ export default function useCreateReferrals() {
687
901
  result.referralsToConsent.push(referralData);
688
902
  }
689
903
  };
690
- const createReferrals = async _ref18 => {
904
+ const createReferrals = async _ref24 => {
691
905
  let {
692
906
  referrals,
693
907
  person,
694
908
  draft
695
- } = _ref18;
909
+ } = _ref24;
696
910
  const result = {
697
911
  referrals: [],
698
912
  cases: [],
@@ -707,7 +921,8 @@ export default function useCreateReferrals() {
707
921
  error: null,
708
922
  caseId: null,
709
923
  attachmentStatus: 'not_requested',
710
- attachmentErrors: []
924
+ attachmentErrors: [],
925
+ rawAtomicErrors: null
711
926
  });
712
927
  try {
713
928
  const referral = {
@@ -763,21 +978,21 @@ export default function useCreateReferrals() {
763
978
 
764
979
  // Each entry compares the existing referral's relationship against the newly desired one and,
765
980
  // when they differ, contributes that field to the update payload.
766
- const buildReferralRelationshipFieldChanges = _ref19 => {
981
+ const buildReferralRelationshipFieldChanges = _ref25 => {
767
982
  let {
768
983
  currentReferral,
769
984
  existingReferral,
770
985
  program
771
- } = _ref19;
772
- return [['receiving_program', get(existingReferral, 'receiving_program.id'), get(program, 'id')], ['receiving_provider', get(existingReferral, 'receiving_provider.id'), get(program, 'provider.id')], ['receiving_network', get(existingReferral, 'receiving_network.id'), get(currentReferral, 'network.id')], ['sending_provider', get(existingReferral, 'sending_provider.id'), get(currentReferral, 'sendingProvider.id')], ['sending_network', get(existingReferral, 'sending_network.id'), get(currentReferral, 'network.id')]].reduce((changes, _ref20) => {
773
- let [field, previousId, nextId] = _ref20;
986
+ } = _ref25;
987
+ return [['receiving_program', get(existingReferral, 'receiving_program.id'), get(program, 'id')], ['receiving_provider', get(existingReferral, 'receiving_provider.id'), get(program, 'provider.id')], ['receiving_network', get(existingReferral, 'receiving_network.id'), get(currentReferral, 'network.id')], ['sending_provider', get(existingReferral, 'sending_provider.id'), get(currentReferral, 'sendingProvider.id')], ['sending_network', get(existingReferral, 'sending_network.id'), get(currentReferral, 'network.id')]].reduce((changes, _ref26) => {
988
+ let [field, previousId, nextId] = _ref26;
774
989
  return previousId !== nextId ? {
775
990
  ...changes,
776
991
  [field]: nextId
777
992
  } : changes;
778
993
  }, {});
779
994
  };
780
- const buildReferralUpdatePayload = _ref21 => {
995
+ const buildReferralUpdatePayload = _ref27 => {
781
996
  let {
782
997
  currentReferral,
783
998
  existingReferral,
@@ -785,7 +1000,7 @@ export default function useCreateReferrals() {
785
1000
  targetState,
786
1001
  isGrouped,
787
1002
  stateOwnedByAuthorization = false
788
- } = _ref21;
1003
+ } = _ref27;
789
1004
  const payload = {
790
1005
  ...buildReferralRelationshipFieldChanges({
791
1006
  currentReferral,
@@ -800,17 +1015,17 @@ export default function useCreateReferrals() {
800
1015
  if (existingReferral.is_grouped !== isGrouped) payload.is_grouped = isGrouped;
801
1016
  return payload;
802
1017
  };
803
- const processReferralUpdates = (toUpdate, currentReferral, _ref22) => {
1018
+ const processReferralUpdates = (toUpdate, currentReferral, _ref28) => {
804
1019
  let {
805
1020
  targetState,
806
1021
  isGrouped,
807
1022
  stateOwnedByAuthorization = false
808
- } = _ref22;
809
- return toUpdate.map(_ref23 => {
1023
+ } = _ref28;
1024
+ return toUpdate.map(_ref29 => {
810
1025
  let {
811
1026
  existingReferral,
812
1027
  program
813
- } = _ref23;
1028
+ } = _ref29;
814
1029
  const updatePayload = buildReferralUpdatePayload({
815
1030
  currentReferral,
816
1031
  existingReferral,
@@ -829,13 +1044,13 @@ export default function useCreateReferrals() {
829
1044
  });
830
1045
  });
831
1046
  };
832
- const processReferralCreations = (toCreate, _ref24) => {
1047
+ const processReferralCreations = (toCreate, _ref30) => {
833
1048
  let {
834
1049
  targetState,
835
1050
  isGrouped,
836
1051
  oldCase,
837
1052
  referral
838
- } = _ref24;
1053
+ } = _ref30;
839
1054
  return toCreate.map(program => createReferral({
840
1055
  state: targetState,
841
1056
  case: oldCase.id,
@@ -894,12 +1109,12 @@ export default function useCreateReferrals() {
894
1109
  const caseResponse = isEmpty(serviceCasePayload) ? oldCase : await updateCase(referral.case.id, serviceCasePayload);
895
1110
  return caseResponse;
896
1111
  };
897
- const validateDraftAuthorizationUpdate = _ref25 => {
1112
+ const validateDraftAuthorizationUpdate = _ref31 => {
898
1113
  let {
899
1114
  referral,
900
1115
  oldCase,
901
1116
  serviceAuthorizationId
902
- } = _ref25;
1117
+ } = _ref31;
903
1118
  if (!serviceAuthorizationId) {
904
1119
  return;
905
1120
  }
@@ -909,13 +1124,13 @@ export default function useCreateReferrals() {
909
1124
  throw new Error(DRAFT_AUTHORIZATION_PROGRAM_CHANGE_MESSAGE);
910
1125
  }
911
1126
  };
912
- const saveServiceAuthorizationIfNeeded = async _ref26 => {
1127
+ const saveServiceAuthorizationIfNeeded = async _ref32 => {
913
1128
  let {
914
1129
  referral,
915
1130
  oldCase,
916
1131
  draft,
917
1132
  serviceAuthorizationId
918
- } = _ref26;
1133
+ } = _ref32;
919
1134
  if (!referralNeedsAuthorization(referral)) {
920
1135
  return;
921
1136
  }
@@ -930,7 +1145,7 @@ export default function useCreateReferrals() {
930
1145
 
931
1146
  // Deletes and updates target referrals that already exist, and core only allows either while the
932
1147
  // referral is still in draft. They must therefore be applied before the authorization request.
933
- const applyDraftReferralRemovalsAndUpdates = async _ref27 => {
1148
+ const applyDraftReferralRemovalsAndUpdates = async _ref33 => {
934
1149
  let {
935
1150
  referral,
936
1151
  toDelete,
@@ -938,7 +1153,7 @@ export default function useCreateReferrals() {
938
1153
  targetState,
939
1154
  isGrouped,
940
1155
  stateOwnedByAuthorization
941
- } = _ref27;
1156
+ } = _ref33;
942
1157
  const deletePromises = toDelete.map(r => coreApi.deleteRecord('referral', r.id));
943
1158
  const updatePromises = processReferralUpdates(toUpdate, referral, {
944
1159
  targetState,
@@ -951,14 +1166,14 @@ export default function useCreateReferrals() {
951
1166
 
952
1167
  // New referrals are created after the authorization request, where core accepts an explicit
953
1168
  // pending_authorization state, matching how referrals are created from scratch.
954
- const applyDraftReferralCreations = async _ref28 => {
1169
+ const applyDraftReferralCreations = async _ref34 => {
955
1170
  let {
956
1171
  referral,
957
1172
  oldCase,
958
1173
  toCreate,
959
1174
  targetState,
960
1175
  isGrouped
961
- } = _ref28;
1176
+ } = _ref34;
962
1177
  const responses = await Promise.all(processReferralCreations(toCreate, {
963
1178
  targetState,
964
1179
  isGrouped,
@@ -1127,10 +1342,7 @@ export default function useCreateReferrals() {
1127
1342
  draft = false,
1128
1343
  latestResponses
1129
1344
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1130
- let response = {
1131
- referralsToConsent: []
1132
- };
1133
- response = await createReferrals({
1345
+ const response = await createReferrals({
1134
1346
  referrals,
1135
1347
  person,
1136
1348
  draft