Skip to content

Commit

Permalink
Merge pull request #343 from FEMR/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Kevin Zurek committed Dec 8, 2014
2 parents b3d5189 + 0246bad commit 5bdca78
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ Add play framework to your PATH environment variable if you haven't done so alre

### Questions?

Email: [email protected]
Email: [email protected]

5 changes: 4 additions & 1 deletion app/femr/business/helpers/DomainMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion app/femr/business/services/IMedicalService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public interface IMedicalService {
* @param encounterId id of the current encounter
* @return updated prescription list
*/
ServiceResponse<List<PrescriptionItem>> createPatientPrescriptions(List<PrescriptionItem> prescriptionItems, int userId, int encounterId);
ServiceResponse<List<PrescriptionItem>> createPatientPrescriptions(List<PrescriptionItem> prescriptionItems, int userId, int encounterId, boolean isDispensed);

/**
* Adds tab field items to the PatientEncounterTabField table
Expand Down
19 changes: 18 additions & 1 deletion app/femr/business/services/IPharmacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<PrescriptionItem> createAndReplacePrescription(PrescriptionItem prescriptionItem, int oldScriptId, int userId);
ServiceResponse<PrescriptionItem> createAndReplacePrescription(PrescriptionItem prescriptionItem, int oldScriptId, int userId, boolean isCounseled);

/**
* Find all problems
Expand All @@ -60,4 +61,20 @@ public interface IPharmacyService {
* @return
*/
ServiceResponse<List<String>> findAllMedications();

/**
* Mark prescriptions as filled
*
* @param prescriptionIds a list of prescription ids to fill
* @return prescription items that were filled
*/
ServiceResponse<List<PrescriptionItem>> markPrescriptionsAsFilled(List<Integer> 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<List<PrescriptionItem>> markPrescriptionsAsCounseled(List<Integer> prescriptionIds);
}
4 changes: 2 additions & 2 deletions app/femr/business/services/MedicalService.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public ServiceResponse<UserItem> getPhysicianThatCheckedInPatient(int encounterI
* {@inheritDoc}
*/
@Override
public ServiceResponse<List<PrescriptionItem>> createPatientPrescriptions(List<PrescriptionItem> prescriptionItems, int userId, int encounterId) {
public ServiceResponse<List<PrescriptionItem>> createPatientPrescriptions(List<PrescriptionItem> prescriptionItems, int userId, int encounterId, boolean isDispensed) {
ServiceResponse<List<PrescriptionItem>> response = new ServiceResponse<>();
if (prescriptionItems == null || userId < 1 || encounterId < 1) {
response.addError("", "invalid parameters");
Expand All @@ -116,7 +116,7 @@ public ServiceResponse<List<PrescriptionItem>> createPatientPrescriptions(List<P
List<IPatientPrescription> 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 {
Expand Down
65 changes: 63 additions & 2 deletions app/femr/business/services/PharmacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public ServiceResponse<IPatientEncounter> checkPatientIn(int encounterId, int us
* {@inheritDoc}
*/
@Override
public ServiceResponse<PrescriptionItem> createAndReplacePrescription(PrescriptionItem prescriptionItem, int oldScriptId, int userId) {
public ServiceResponse<PrescriptionItem> createAndReplacePrescription(PrescriptionItem prescriptionItem, int oldScriptId, int userId, boolean isCounseled) {
ServiceResponse<PrescriptionItem> response = new ServiceResponse<>();
if (prescriptionItem == null || StringUtils.isNullOrWhiteSpace(prescriptionItem.getName()) || oldScriptId < 1 || userId < 1) {
response.addError("", "bad parameters");
Expand All @@ -112,11 +112,12 @@ public ServiceResponse<PrescriptionItem> 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);
Expand Down Expand Up @@ -180,5 +181,65 @@ public ServiceResponse<List<String>> findAllMedications() {

return response;
}

/**
* {@inheritDoc}
*/
@Override
public ServiceResponse<List<PrescriptionItem>> markPrescriptionsAsFilled(List<Integer> prescriptionIds) {
ServiceResponse<List<PrescriptionItem>> response = new ServiceResponse<>();

List<PrescriptionItem> updatedPrescriptions = new ArrayList<>();
try {

for (Integer i : prescriptionIds) {
if (i != null && i > 0) {
ExpressionList<PatientPrescription> 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<List<PrescriptionItem>> markPrescriptionsAsCounseled(List<Integer> prescriptionIds){
ServiceResponse<List<PrescriptionItem>> response = new ServiceResponse<>();

List<PrescriptionItem> updatedPrescriptions = new ArrayList<>();
try {

for (Integer i : prescriptionIds) {
if (i != null && i > 0) {
ExpressionList<PatientPrescription> 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;
}
}

8 changes: 8 additions & 0 deletions app/femr/data/models/IPatientPrescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
24 changes: 24 additions & 0 deletions app/femr/data/models/PatientPrescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
8 changes: 6 additions & 2 deletions app/femr/ui/controllers/MedicalController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<PrescriptionItem>> prescriptionResponse =
medicalService.createPatientPrescriptions(prescriptionItems, currentUserSession.getId(), patientEncounterItem.getId());
ServiceResponse<List<PrescriptionItem>> prescriptionResponse = medicalService.createPatientPrescriptions(
prescriptionItems,
currentUserSession.getId(),
patientEncounterItem.getId(),
false
);
if (prescriptionResponse.hasErrors()) {
throw new RuntimeException();
}
Expand Down
44 changes: 39 additions & 5 deletions app/femr/ui/controllers/PharmaciesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import play.mvc.Result;
import play.mvc.Security;

import java.util.ArrayList;
import java.util.List;

@Security.Authenticated(FEMRAuthenticated.class)
Expand Down Expand Up @@ -150,66 +151,99 @@ 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<Integer> prescriptionToMarkAsDispensedOrCounseled = new ArrayList<>();
boolean isCounseled = StringUtils.isNotNullOrWhiteSpace(createViewModelPost.getDisclaimer());
//replace prescription 1
PrescriptionItem prescriptionItem = new PrescriptionItem();
if (StringUtils.isNotNullOrWhiteSpace(createViewModelPost.getReplacementMedication1())) {
prescriptionItem.setName(createViewModelPost.getReplacementMedication1());
ServiceResponse<PrescriptionItem> 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())) {
prescriptionItem.setName(createViewModelPost.getReplacementMedication2());
ServiceResponse<PrescriptionItem> 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())) {
prescriptionItem.setName(createViewModelPost.getReplacementMedication3());
ServiceResponse<PrescriptionItem> 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())) {
prescriptionItem.setName(createViewModelPost.getReplacementMedication4());
ServiceResponse<PrescriptionItem> 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())) {
prescriptionItem.setName(createViewModelPost.getReplacementMedication5());
ServiceResponse<PrescriptionItem> 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<List<PrescriptionItem>> prescriptionDispensedResponse = pharmacyService.markPrescriptionsAsFilled(prescriptionToMarkAsDispensedOrCounseled);
if (prescriptionDispensedResponse.hasErrors()) {
throw new RuntimeException();
}
//update non-replaced prescriptions that the patient was counseled on
if (isCounseled){
ServiceResponse<List<PrescriptionItem>> prescriptionCounseledResponse = pharmacyService.markPrescriptionsAsCounseled(prescriptionToMarkAsDispensedOrCounseled);
if (prescriptionCounseledResponse.hasErrors()){
throw new RuntimeException();
}
}

//check the patient in!
Expand Down
9 changes: 9 additions & 0 deletions app/femr/ui/models/pharmacy/EditViewModelPost.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class EditViewModelPost {
private String replacementMedication3;
private String replacementMedication4;
private String replacementMedication5;
private String disclaimer;

public String getReplacementMedication1() {
return replacementMedication1;
Expand Down Expand Up @@ -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;
}
}
Loading

0 comments on commit 5bdca78

Please sign in to comment.