From ccfa481610f356a5d82f813ace4a4db34f8d2129 Mon Sep 17 00:00:00 2001 From: Kevin Zurek Date: Sun, 7 Dec 2014 18:49:01 -0500 Subject: [PATCH 1/2] added pharmacy Confirmation --- app/femr/business/helpers/DomainMapper.java | 5 +- .../business/services/IMedicalService.java | 2 +- .../business/services/IPharmacyService.java | 19 +++++- .../business/services/MedicalService.java | 4 +- .../business/services/PharmacyService.java | 65 +++++++++++++++++- .../data/models/IPatientPrescription.java | 8 +++ app/femr/data/models/PatientPrescription.java | 24 +++++++ .../ui/controllers/MedicalController.java | 8 ++- .../ui/controllers/PharmaciesController.java | 44 +++++++++++-- .../ui/models/pharmacy/EditViewModelPost.java | 9 +++ app/femr/ui/views/pharmacies/edit.scala.html | 22 +++++-- conf/evolutions/default/71.sql | 16 +++++ public/css/pharmacy.css | 66 +++++++++++++++---- 13 files changed, 259 insertions(+), 33 deletions(-) create mode 100644 conf/evolutions/default/71.sql diff --git a/app/femr/business/helpers/DomainMapper.java b/app/femr/business/helpers/DomainMapper.java index 6118e3187..cc0e61b19 100644 --- a/app/femr/business/helpers/DomainMapper.java +++ b/app/femr/business/helpers/DomainMapper.java @@ -576,9 +576,10 @@ public IPatientEncounterTabField createPatientEncounterTabField(ITabField tabFie * @param userId id of the user creating the prescription * @param encounterId encounter id of the prescription * @param replacementId id of the prescription being replaced OR null + * @param isDispensed is the patient prescription dispensed to the patient yet * @return a new IPatientPrescription */ - public IPatientPrescription createPatientPrescription(int amount, IMedication medication, int userId, int encounterId, Integer replacementId) { + public IPatientPrescription createPatientPrescription(int amount, IMedication medication, int userId, int encounterId, Integer replacementId, boolean isDispensed, boolean isCounseled) { if (medication == null || StringUtils.isNullOrWhiteSpace(medication.getName()) || userId < 1 || encounterId < 1) { return null; } @@ -589,6 +590,8 @@ public IPatientPrescription createPatientPrescription(int amount, IMedication me patientPrescription.setMedication(medication); patientPrescription.setReplacementId(replacementId); patientPrescription.setPhysician(Ebean.getReference(userProvider.get().getClass(), userId)); + patientPrescription.setDispensed(isDispensed); + patientPrescription.setCounseled(isCounseled); return patientPrescription; } diff --git a/app/femr/business/services/IMedicalService.java b/app/femr/business/services/IMedicalService.java index 202aaaf02..e1d5b72cb 100644 --- a/app/femr/business/services/IMedicalService.java +++ b/app/femr/business/services/IMedicalService.java @@ -53,7 +53,7 @@ public interface IMedicalService { * @param encounterId id of the current encounter * @return updated prescription list */ - ServiceResponse> createPatientPrescriptions(List prescriptionItems, int userId, int encounterId); + ServiceResponse> createPatientPrescriptions(List prescriptionItems, int userId, int encounterId, boolean isDispensed); /** * Adds tab field items to the PatientEncounterTabField table diff --git a/app/femr/business/services/IPharmacyService.java b/app/femr/business/services/IPharmacyService.java index 98eb6b21e..7dd636e0a 100644 --- a/app/femr/business/services/IPharmacyService.java +++ b/app/femr/business/services/IPharmacyService.java @@ -42,9 +42,10 @@ public interface IPharmacyService { * * @param prescriptionItem new prescription to replace the old one * @param oldScriptId id of the old prescription that is being replaced + * @param isCounseled was the patient counseled on this prescription * @return updated new prescription */ - ServiceResponse createAndReplacePrescription(PrescriptionItem prescriptionItem, int oldScriptId, int userId); + ServiceResponse createAndReplacePrescription(PrescriptionItem prescriptionItem, int oldScriptId, int userId, boolean isCounseled); /** * Find all problems @@ -60,4 +61,20 @@ public interface IPharmacyService { * @return */ ServiceResponse> findAllMedications(); + + /** + * Mark prescriptions as filled + * + * @param prescriptionIds a list of prescription ids to fill + * @return prescription items that were filled + */ + ServiceResponse> markPrescriptionsAsFilled(List prescriptionIds); + + /** + * Mark prescriptions as having the patient counseled + * + * @param prescriptionIds a list of prescription ids to identify as counseled + * @return prescription items that were marked as counseled + */ + ServiceResponse> markPrescriptionsAsCounseled(List prescriptionIds); } diff --git a/app/femr/business/services/MedicalService.java b/app/femr/business/services/MedicalService.java index 1307c94e3..d5c42f8f0 100644 --- a/app/femr/business/services/MedicalService.java +++ b/app/femr/business/services/MedicalService.java @@ -106,7 +106,7 @@ public ServiceResponse getPhysicianThatCheckedInPatient(int encounterI * {@inheritDoc} */ @Override - public ServiceResponse> createPatientPrescriptions(List prescriptionItems, int userId, int encounterId) { + public ServiceResponse> createPatientPrescriptions(List prescriptionItems, int userId, int encounterId, boolean isDispensed) { ServiceResponse> response = new ServiceResponse<>(); if (prescriptionItems == null || userId < 1 || encounterId < 1) { response.addError("", "invalid parameters"); @@ -116,7 +116,7 @@ public ServiceResponse> createPatientPrescriptions(List

patientPrescriptions = new ArrayList<>(); for (PrescriptionItem pi : prescriptionItems) { IMedication medication = domainMapper.createMedication(pi.getName()); - patientPrescriptions.add(domainMapper.createPatientPrescription(0, medication, userId, encounterId, null)); + patientPrescriptions.add(domainMapper.createPatientPrescription(0, medication, userId, encounterId, null, false, false)); } try { diff --git a/app/femr/business/services/PharmacyService.java b/app/femr/business/services/PharmacyService.java index 3b8ff352e..600574732 100644 --- a/app/femr/business/services/PharmacyService.java +++ b/app/femr/business/services/PharmacyService.java @@ -96,7 +96,7 @@ public ServiceResponse checkPatientIn(int encounterId, int us * {@inheritDoc} */ @Override - public ServiceResponse createAndReplacePrescription(PrescriptionItem prescriptionItem, int oldScriptId, int userId) { + public ServiceResponse createAndReplacePrescription(PrescriptionItem prescriptionItem, int oldScriptId, int userId, boolean isCounseled) { ServiceResponse response = new ServiceResponse<>(); if (prescriptionItem == null || StringUtils.isNullOrWhiteSpace(prescriptionItem.getName()) || oldScriptId < 1 || userId < 1) { response.addError("", "bad parameters"); @@ -112,11 +112,12 @@ public ServiceResponse createAndReplacePrescription(Prescripti //create new prescription IMedication medication = domainMapper.createMedication(prescriptionItem.getName()); - IPatientPrescription newPatientPrescription = domainMapper.createPatientPrescription(0, medication, userId, oldPatientPrescription.getPatientEncounter().getId(), null); + IPatientPrescription newPatientPrescription = domainMapper.createPatientPrescription(0, medication, userId, oldPatientPrescription.getPatientEncounter().getId(), null, true, isCounseled); newPatientPrescription = patientPrescriptionRepository.create(newPatientPrescription); //replace the old prescription oldPatientPrescription.setReplacementId(newPatientPrescription.getId()); + oldPatientPrescription.setDispensed(false); patientPrescriptionRepository.update(oldPatientPrescription); PrescriptionItem newPrescriptionItem = domainMapper.createPrescriptionItem(newPatientPrescription); @@ -180,5 +181,65 @@ public ServiceResponse> findAllMedications() { return response; } + + /** + * {@inheritDoc} + */ + @Override + public ServiceResponse> markPrescriptionsAsFilled(List prescriptionIds) { + ServiceResponse> response = new ServiceResponse<>(); + + List updatedPrescriptions = new ArrayList<>(); + try { + + for (Integer i : prescriptionIds) { + if (i != null && i > 0) { + ExpressionList patientPrescriptionExpressionList = QueryProvider.getPatientPrescriptionQuery() + .where() + .eq("id", i); + IPatientPrescription patientPrescription = patientPrescriptionRepository.findOne(patientPrescriptionExpressionList); + patientPrescription.setDispensed(true); + patientPrescription = patientPrescriptionRepository.update(patientPrescription); + updatedPrescriptions.add(domainMapper.createPrescriptionItem(patientPrescription)); + } + } + response.setResponseObject(updatedPrescriptions); + } catch (Exception ex) { + + response.addError("", "prescriptions were not updated"); + } + + return response; + } + + /** + * {@inheritDoc} + */ + @Override + public ServiceResponse> markPrescriptionsAsCounseled(List prescriptionIds){ + ServiceResponse> response = new ServiceResponse<>(); + + List updatedPrescriptions = new ArrayList<>(); + try { + + for (Integer i : prescriptionIds) { + if (i != null && i > 0) { + ExpressionList patientPrescriptionExpressionList = QueryProvider.getPatientPrescriptionQuery() + .where() + .eq("id", i); + IPatientPrescription patientPrescription = patientPrescriptionRepository.findOne(patientPrescriptionExpressionList); + patientPrescription.setCounseled(true); + patientPrescription = patientPrescriptionRepository.update(patientPrescription); + updatedPrescriptions.add(domainMapper.createPrescriptionItem(patientPrescription)); + } + } + response.setResponseObject(updatedPrescriptions); + } catch (Exception ex) { + + response.addError("", "prescriptions were not updated"); + } + + return response; + } } diff --git a/app/femr/data/models/IPatientPrescription.java b/app/femr/data/models/IPatientPrescription.java index 7fcc8b334..3ca712f4b 100644 --- a/app/femr/data/models/IPatientPrescription.java +++ b/app/femr/data/models/IPatientPrescription.java @@ -56,4 +56,12 @@ public interface IPatientPrescription { String getSpecialInstructions(); void setSpecialInstructions(String specialInstructions); + + boolean isCounseled(); + + void setCounseled(boolean isCounseled); + + boolean isDispensed(); + + void setDispensed(boolean isDispensed); } diff --git a/app/femr/data/models/PatientPrescription.java b/app/femr/data/models/PatientPrescription.java index cdc432442..934f472aa 100644 --- a/app/femr/data/models/PatientPrescription.java +++ b/app/femr/data/models/PatientPrescription.java @@ -48,6 +48,10 @@ public class PatientPrescription implements IPatientPrescription { private Integer replacementId; @Column(name = "special_instructions", nullable = true) private String specialInstructions; + @Column(name = "isCounseled", nullable = false) + private boolean isCounseled; + @Column(name = "isDispensed", nullable = false) + private boolean isDispensed; @Override public int getId() { @@ -133,4 +137,24 @@ public String getSpecialInstructions() { public void setSpecialInstructions(String specialInstructions) { this.specialInstructions = specialInstructions; } + + @Override + public boolean isCounseled() { + return isCounseled; + } + + @Override + public void setCounseled(boolean isCounseled) { + this.isCounseled = isCounseled; + } + + @Override + public boolean isDispensed() { + return isDispensed; + } + + @Override + public void setDispensed(boolean isDispensed) { + this.isDispensed = isDispensed; + } } diff --git a/app/femr/ui/controllers/MedicalController.java b/app/femr/ui/controllers/MedicalController.java index 534552bd7..dd1351e75 100644 --- a/app/femr/ui/controllers/MedicalController.java +++ b/app/femr/ui/controllers/MedicalController.java @@ -258,8 +258,12 @@ public Result editPost(int patientId) { if (viewModelPost.getPrescription5() != null && StringUtils.isNotNullOrWhiteSpace(viewModelPost.getPrescription5())) prescriptionItems.add(new PrescriptionItem(viewModelPost.getPrescription5())); if (prescriptionItems.size() > 0) { - ServiceResponse> prescriptionResponse = - medicalService.createPatientPrescriptions(prescriptionItems, currentUserSession.getId(), patientEncounterItem.getId()); + ServiceResponse> prescriptionResponse = medicalService.createPatientPrescriptions( + prescriptionItems, + currentUserSession.getId(), + patientEncounterItem.getId(), + false + ); if (prescriptionResponse.hasErrors()) { throw new RuntimeException(); } diff --git a/app/femr/ui/controllers/PharmaciesController.java b/app/femr/ui/controllers/PharmaciesController.java index 6115c0ab7..44720e040 100644 --- a/app/femr/ui/controllers/PharmaciesController.java +++ b/app/femr/ui/controllers/PharmaciesController.java @@ -18,6 +18,7 @@ import play.mvc.Result; import play.mvc.Security; +import java.util.ArrayList; import java.util.List; @Security.Authenticated(FEMRAuthenticated.class) @@ -150,6 +151,11 @@ public Result editPost(int id) { } PatientItem patientItem = patientItemServiceResponse.getResponseObject(); + //after replacing the prescriptions, this list will contain the non-replaced prescriptions that need + //to be identified as dispensed. The service layer checks for an ID of 0. Also, this is a cluster fuck + //and some of the logic needs to be moved up to the service layer. + List prescriptionToMarkAsDispensedOrCounseled = new ArrayList<>(); + boolean isCounseled = StringUtils.isNotNullOrWhiteSpace(createViewModelPost.getDisclaimer()); //replace prescription 1 PrescriptionItem prescriptionItem = new PrescriptionItem(); if (StringUtils.isNotNullOrWhiteSpace(createViewModelPost.getReplacementMedication1())) { @@ -157,11 +163,14 @@ public Result editPost(int id) { ServiceResponse response = pharmacyService.createAndReplacePrescription( prescriptionItem, createViewModelPost.getId_prescription1(), - currentUserSession.getId() + currentUserSession.getId(), + isCounseled ); if (response.hasErrors()) { throw new RuntimeException(); } + } else { + prescriptionToMarkAsDispensedOrCounseled.add(createViewModelPost.getId_prescription1()); } //replace prescription 2 if (StringUtils.isNotNullOrWhiteSpace(createViewModelPost.getReplacementMedication2())) { @@ -169,11 +178,14 @@ public Result editPost(int id) { ServiceResponse response = pharmacyService.createAndReplacePrescription( prescriptionItem, createViewModelPost.getId_prescription2(), - currentUserSession.getId() + currentUserSession.getId(), + isCounseled ); if (response.hasErrors()) { throw new RuntimeException(); } + } else { + prescriptionToMarkAsDispensedOrCounseled.add(createViewModelPost.getId_prescription2()); } //replace prescription 3 if (StringUtils.isNotNullOrWhiteSpace(createViewModelPost.getReplacementMedication3())) { @@ -181,11 +193,14 @@ public Result editPost(int id) { ServiceResponse response = pharmacyService.createAndReplacePrescription( prescriptionItem, createViewModelPost.getId_prescription3(), - currentUserSession.getId() + currentUserSession.getId(), + isCounseled ); if (response.hasErrors()) { throw new RuntimeException(); } + } else { + prescriptionToMarkAsDispensedOrCounseled.add(createViewModelPost.getId_prescription3()); } //replace prescription 4 if (StringUtils.isNotNullOrWhiteSpace(createViewModelPost.getReplacementMedication4())) { @@ -193,11 +208,14 @@ public Result editPost(int id) { ServiceResponse response = pharmacyService.createAndReplacePrescription( prescriptionItem, createViewModelPost.getId_prescription4(), - currentUserSession.getId() + currentUserSession.getId(), + isCounseled ); if (response.hasErrors()) { throw new RuntimeException(); } + } else { + prescriptionToMarkAsDispensedOrCounseled.add(createViewModelPost.getId_prescription4()); } //replace prescription 5 if (StringUtils.isNotNullOrWhiteSpace(createViewModelPost.getReplacementMedication5())) { @@ -205,11 +223,27 @@ public Result editPost(int id) { ServiceResponse response = pharmacyService.createAndReplacePrescription( prescriptionItem, createViewModelPost.getId_prescription5(), - currentUserSession.getId() + currentUserSession.getId(), + isCounseled ); if (response.hasErrors()) { throw new RuntimeException(); } + } else { + prescriptionToMarkAsDispensedOrCounseled.add(createViewModelPost.getId_prescription5()); + } + + //update non-replaced prescriptions to dispensed + ServiceResponse> prescriptionDispensedResponse = pharmacyService.markPrescriptionsAsFilled(prescriptionToMarkAsDispensedOrCounseled); + if (prescriptionDispensedResponse.hasErrors()) { + throw new RuntimeException(); + } + //update non-replaced prescriptions that the patient was counseled on + if (isCounseled){ + ServiceResponse> prescriptionCounseledResponse = pharmacyService.markPrescriptionsAsCounseled(prescriptionToMarkAsDispensedOrCounseled); + if (prescriptionCounseledResponse.hasErrors()){ + throw new RuntimeException(); + } } //check the patient in! diff --git a/app/femr/ui/models/pharmacy/EditViewModelPost.java b/app/femr/ui/models/pharmacy/EditViewModelPost.java index 7e99fda10..c6eeb4c18 100644 --- a/app/femr/ui/models/pharmacy/EditViewModelPost.java +++ b/app/femr/ui/models/pharmacy/EditViewModelPost.java @@ -29,6 +29,7 @@ public class EditViewModelPost { private String replacementMedication3; private String replacementMedication4; private String replacementMedication5; + private String disclaimer; public String getReplacementMedication1() { return replacementMedication1; @@ -110,4 +111,12 @@ public int getId_prescription5() { public void setId_prescription5(int id_prescription5) { this.id_prescription5 = id_prescription5; } + + public String getDisclaimer() { + return disclaimer; + } + + public void setDisclaimer(String disclaimer) { + this.disclaimer = disclaimer; + } } diff --git a/app/femr/ui/views/pharmacies/edit.scala.html b/app/femr/ui/views/pharmacies/edit.scala.html index 2a039ea73..a8efa1c74 100644 --- a/app/femr/ui/views/pharmacies/edit.scala.html +++ b/app/femr/ui/views/pharmacies/edit.scala.html @@ -30,13 +30,13 @@

List of Diagnoses

    - @if(viewModel.getProblems != null) { - @for(y <- 1 to viewModel.getProblems.size) { - @if(viewModel.getProblems.get(y - 1) != null) { -
  1. @viewModel.getProblems.get(y - 1).getName
  2. - } + @if(viewModel.getProblems != null) { + @for(y <- 1 to viewModel.getProblems.size) { + @if(viewModel.getProblems.get(y - 1) != null) { +
  3. @viewModel.getProblems.get(y - 1).getName
  4. } } + }
@@ -57,7 +57,17 @@

List of Medications

- + + +
+ + +
+
+ +
diff --git a/conf/evolutions/default/71.sql b/conf/evolutions/default/71.sql new file mode 100644 index 000000000..8b37c8aef --- /dev/null +++ b/conf/evolutions/default/71.sql @@ -0,0 +1,16 @@ +# --- !Ups + +ALTER TABLE `patient_prescriptions` +ADD COLUMN `isCounseled` BIT(1) NOT NULL AFTER `special_instructions`; + +ALTER TABLE `patient_prescriptions` +CHANGE COLUMN `isCounseled` `isCounseled` BIT(1) NOT NULL DEFAULT false , +ADD COLUMN `isDispensed` BIT(1) NOT NULL DEFAULT false AFTER `isCounseled`; + +# --- !Downs + +ALTER TABLE `patient_prescriptions` +DROP COLUMN `isCounseled`; + +ALTER TABLE `patient_prescriptions` +DROP COLUMN `isDispensed`; \ No newline at end of file diff --git a/public/css/pharmacy.css b/public/css/pharmacy.css index b27452c46..a61f474d5 100644 --- a/public/css/pharmacy.css +++ b/public/css/pharmacy.css @@ -1,7 +1,8 @@ /* General page styles */ -#mainWrap form{ +#mainWrap form { overflow: hidden; } + #diagnosisWrap { width: 30%; float: left; @@ -16,11 +17,7 @@ border-left: 1px solid #b2b2b0; } -#pharmacySubmitBtn{ - margin-top: 15px; -} - -#medicationList{ +#medicationList { padding-left: 80px; } @@ -28,22 +25,25 @@ padding: 15px; border-bottom: 1px solid #b2b2b0; } -.medication button{ + +.medication button { position: absolute; margin-left: -80px; margin-top: -6px; } -.medication span{ + +.medication span { width: 100%; } -.medication input{ + +.medication input { width: 100%; margin-top: 10px; } /* Override the overflow style so the user can see the full drop down in medication typeahead list*/ -#mainWrap{ +#mainWrap { min-height: 300px; } @@ -53,15 +53,28 @@ } @media (max-width: 620px) { - #diagnosisWrap{ + #diagnosisWrap { width: 100%; } - #medicationWrap{ + #medicationWrap { width: 100%; border-left: none; } } + +@media (max-width: 500px) { + #disclaimerWrap label{ + max-width: 300px; + } +} + +@media (max-width: 400px){ + #disclaimerWrap label{ + max-width: 150px; + } +} + /*typeahead */ input[style] { @@ -138,8 +151,35 @@ input[style] { .tt-suggestion p { margin: 0; } -.replaceBtn{ + +.replaceBtn { width: auto !important; padding: 6px 12px 6px 12px; +} + +#disclaimerWrap { + float: right; + width: 100%; +} + +#disclaimerWrap label { + font-size: 10px; + float: right; + margin-top: 5px; +} + +#disclaimerWrap input { + float: right; + -ms-transform: scale(1.5); /* IE */ + -moz-transform: scale(1.5); /* FF */ + -webkit-transform: scale(1.5); /* Safari and Chrome */ + -o-transform: scale(1.5); /* Opera */ + padding: 10px; + margin: 5px; +} + +#submitWrap { + width: 100%; + float: right; } \ No newline at end of file From e5a56e72ccd6f5b4ab05b83567322d2536a8cebe Mon Sep 17 00:00:00 2001 From: Kevin Zurek Date: Sun, 7 Dec 2014 19:11:45 -0500 Subject: [PATCH 2/2] update email on readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9c2746c43..ef21b27db 100644 --- a/README.md +++ b/README.md @@ -28,5 +28,5 @@ Add play framework to your PATH environment variable if you haven't done so alre ### Questions? -Email: kevinzurek@gmail.com +Email: kevin.zurek@teamfemr.org