Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Changed to archive records instead of delete
Browse files Browse the repository at this point in the history
Fixes #380
Closes #457
  • Loading branch information
jkleinsc committed Aug 29, 2016
1 parent b22f4d1 commit 1b9022e
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions app/patients/delete/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ function deleteMany(manyArray) {
// empty array: no records to delete
return Ember.RSVP.resolve();
}
return Ember.RSVP.all(manyArray.invoke('destroyRecord', 'async array deletion'));
var archivePromises = manyArray.map((recordToDelete) => {
recordToDelete.set('archived', true);
return recordToDelete.save().then(() => {
return recordToDelete.unloadRecord();
});
});
return Ember.RSVP.all(archivePromises, 'async array deletion');
}

export default AbstractDeleteController.extend(PatientVisitsMixin, PatientInvoicesMixin, PouchDbMixin, ProgressDialog, PatientAppointmentsMixin, {
title: t('patients.titles.delete'),
progressTitle: 'Delete Patient Record',
progressMessage: 'Deleting patient and all associated records',
progressTitle: t('patients.titles.deletePatientRecord'),
progressMessage: t('patients.messages.deletingPatient'),

// Override delete action on controller; we must delete
// all related records before deleting patient record
Expand Down Expand Up @@ -86,11 +92,13 @@ export default AbstractDeleteController.extend(PatientVisitsMixin, PatientInvoic

deleteInvoices: function(patientInvoices) {
return Ember.RSVP.resolve(patientInvoices).then(function(invoices) {
var lineItems = invoices.map(function(i) {
return i.get('lineItems');
let lineItems = Ember.A();
invoices.forEach(function(i) {
lineItems.addObjects(i.get('lineItems'));
});
var lineItemDetails = lineItems.map(function(li) {
return li.get('details');
let lineItemDetails = Ember.A();
lineItems.forEach(function(li) {
lineItemDetails.addObjects(li.get('details'));
});
return Ember.RSVP.all([lineItems, lineItemDetails]).then(function() {
return Ember.RSVP.all([deleteMany(invoices), deleteMany(lineItems), deleteMany(lineItemDetails)]);
Expand Down

0 comments on commit 1b9022e

Please sign in to comment.