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

Fix issue #380: cascading delete for patient records; delete related records first and then patient record #457

Merged
merged 7 commits into from
Aug 29, 2016

Conversation

aboma
Copy link
Contributor

@aboma aboma commented May 12, 2016

Fixes #380 Cascading Delete for patient records.

Changes proposed in this pull request:

  • Delete visits, invoices, and most associated records when deleting patient. Delete these records before deleting patient record to avoid missing records errors.
  • Add view to return invoices for patient.

cc @HospitalRun/core-maintainers

@jglovier
Copy link
Member

@aboma thanks for the PR. 🎉

Add view to return invoices for patient.

Can you please add a screenshots to the view you added?

@jkleinsc
Copy link
Member

@jglovier the view is a database view, not a screen, so I don't think we need a screenshot here.

@aboma
Copy link
Contributor Author

aboma commented May 13, 2016

There is no change to the UI in these commits; the view referenced is a Pouch DB view.

@aboma
Copy link
Contributor Author

aboma commented May 13, 2016

To test this, find or setup a patient record with invoices, visits and labs associated to him/her. Delete the patient using the delete button. Go to the labs view and verify labs are deleted for selected patient and no error occurs on labs list page. Go to invoices list page and verify invoices are deleted for selected patient and no error occurs on invoices list page.

@jkleinsc
Copy link
Member

@aboma good work here. I did notice that there are some orphan records that get left behind because they are children records that don't get directly deleted. Specifically:

  1. appointments
  2. billing-line-item (child of invoice)
  3. line-item-detail (child of billing-line-item)
  4. payment (child of patient and invoice)
  5. proc-charge (child of imaging, lab, procedure, and visit)

A couple of other observations:

  1. It appears if there are no invoices for a patient, the patient doesn't delete properly.
  2. The deletion process takes a little while, so I am wondering if we should leave the modal up until deletion is complete or display a progress modal until the deletion is complete. The progress modal is in the progress-dialog mixin (app/mixins/progress-dialog). To use the progress dialog, you would do the following:
  3. Include the mixin in your controller
  4. define an attribute called progressMessage in your controller which has the message to display while the progress dialog is displayed.
  5. define an attribute called progressTitle in your controller which has the title to display while the progress dialog is displayed.
  6. call showProgressModal to display the progress modal
  7. call closeProgressModal to close the progress modal once processing is complete.

@aboma
Copy link
Contributor Author

aboma commented May 13, 2016

I will add the progress modal (definitely need this) and delete the additional records.

…take some time to delete all associated records
@jkleinsc jkleinsc added the in progress indicates that issue/pull request is currently being worked on label May 23, 2016
@jkleinsc
Copy link
Member

Marking as in progress until this PR is complete.

@aboma
Copy link
Contributor Author

aboma commented Jun 12, 2016

I have made the suggested changes. It is now deleting patient appointments, billing line items, payments and proc charges. I have also added a progress modal.

This pull request should be complete.

@tangollama
Copy link
Member

@aboma thanks for all the good work on this. It appears that there's one test failing on this branch related to the patient-appointments mixin. See below.

If you'd prefer that I or someone else address this fix, I'm happy to do that. If you want to make this change, we should be able to officially "pass" the build.

requireSemicolons: Missing semicolon after statement at mixins/patient-appointments.js : 12 | }, 13 | mapReduce: 'appointments_by_patient' 14 | }) --------------^ 15 | } 16 |});

cc: @jkleinsc for any further feedback / review.

@aboma
Copy link
Contributor Author

aboma commented Jun 13, 2016

I fixed this and also added some changes I mistakenly forgot to check-in. Tests are passing now.

@jkleinsc
Copy link
Member

Thanks @aboma ! Looks good, but I want to test it locally before merging, so I hope to do that tomorrow.

@jkleinsc
Copy link
Member

@aboma in testing this locally, it appears that if I have a payment on a invoice, the delete errors out with: "ember.debug.js:32110 Error: Attempted to handle event didSetProperty on <hospitalrun@model:invoice::ember2049:inv00001> while in state root.deleted.inFlight. Called with {name: paidTotal, oldValue: 12, originalValue: 12, value: 0}."

Also when I don't have a payment the following child records don't appear to delete:

  1. billing-line-item (child of invoice)
  2. line-item-detail (child of billing-line-item)
  3. payment (child of patient and invoice)
  4. proc-charge (child of imaging, lab, procedure, and visit)

@aboma
Copy link
Contributor Author

aboma commented Jul 8, 2016

Ok, I will review again and fix.

Also, you may want to consider creating a service that wraps the store and enforces data integrity. If all model saving/update/deletes are made through the service then it will prevent data corruption.

@jkleinsc
Copy link
Member

@aboma I am going to merge in your changes and adapt them to work with changes I made for #381. Thanks for your work on this PR!

@jkleinsc jkleinsc merged commit a00af29 into HospitalRun:master Aug 29, 2016
jkleinsc pushed a commit that referenced this pull request Aug 29, 2016
jkleinsc added a commit that referenced this pull request Aug 29, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in progress indicates that issue/pull request is currently being worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants