Skip to content

Commit

Permalink
fix specialties needed to create specialties for new patients and ret…
Browse files Browse the repository at this point in the history
…urning patients
  • Loading branch information
Barry Levine authored and Barry Levine committed Jun 9, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 47e4f2a commit 9892b56
Showing 3 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -14,8 +14,12 @@
import org.openmrs.User;
import org.openmrs.api.context.Context;
import org.openmrs.module.patientlist.PatientListItem;
import org.openmrs.module.patientlist.PatientSpecialtyNeededItem;
import org.openmrs.module.patientlist.SpecialtyTypeItem;
import org.springframework.aop.AfterReturningAdvice;
import org.openmrs.module.patientlist.api.PatientListItemService;
import org.openmrs.module.patientlist.api.PatientSpecialtyNeededItemService;
import org.openmrs.module.patientlist.api.SpecialtyTypeItemService;

public class PatientAfterSaveAdvice implements AfterReturningAdvice {

@@ -35,7 +39,7 @@ public void afterReturning(Object returnValue, Method method, Object[] args, Obj
System.out.println("Updating patient demographic data - not added to patient list");
return;
}
*/
*/
if (isPatientInPatientList(patient.getPatientId())) {
System.out.println("Updating patient demographic data - not added to patient list");
return;
@@ -55,6 +59,23 @@ public void afterReturning(Object returnValue, Method method, Object[] args, Obj
patientListItem.setPatientId(patient.getPatientId());
PatientListItem item = Context.getService(PatientListItemService.class).savePatientListItem(patientListItem);

PatientSpecialtyNeededItem specialtyItemNeeded = new PatientSpecialtyNeededItem();
specialtyItemNeeded.setDateCreated(new Date());
specialtyItemNeeded.setPatientId(patient.getPatientId());

List<SpecialtyTypeItem> specItems;
int medicineSpecItemId = 1;
specItems = Context.getService(SpecialtyTypeItemService.class).getAllSpecialtyTypeItem();
for (SpecialtyTypeItem specItem : specItems) {
if (specItem.getName().equalsIgnoreCase("Medicine")) {
medicineSpecItemId = specItem.getId();
}
}
specialtyItemNeeded.setSpecialtyTypeId(medicineSpecItemId);
System.out.println("New patient with specialty: " + specialtyItemNeeded);

Context.getService(PatientSpecialtyNeededItemService.class).savePatientSpecialtyNeededItem(specialtyItemNeeded);

}

private boolean isPatientInPatientList(Integer patientId) {
Original file line number Diff line number Diff line change
@@ -275,8 +275,8 @@ public String getPatientName() {
}

public PatientListItemLocal(org.openmrs.module.patientlist.PatientListItem item, int specId, User doctorRequested) {
System.out.println("**********************Patient id: " + item.getPatientId() + " Spec id: " + specId
+ " Dr Requested: " + doctorRequested);
//System.out.println("**********************Patient id: " + item.getPatientId() + " Spec id: " + specId
// + " Dr Requested: " + doctorRequested);
if (specId == 0) {
specItem = null;
} else {
Original file line number Diff line number Diff line change
@@ -17,8 +17,12 @@
import org.openmrs.api.PatientService;
import org.openmrs.api.context.Context;
import org.openmrs.module.patientlist.PatientListItem;
import org.openmrs.module.patientlist.PatientSpecialtyNeededItem;
import org.openmrs.module.patientlist.SpecialtyTypeItem;
import org.openmrs.ui.framework.page.PageModel;
import org.openmrs.module.patientlist.api.PatientListItemService;
import org.openmrs.module.patientlist.api.PatientSpecialtyNeededItemService;
import org.openmrs.module.patientlist.api.SpecialtyTypeItemService;
import org.openmrs.module.uicommons.util.InfoErrorMessageUtil;
import org.springframework.web.bind.annotation.RequestParam;

@@ -65,6 +69,25 @@ public String post(HttpSession session, HttpServletRequest request,
patientListItem.setPatientId(patientId);
patientListItem.setClerkPersonId(user.getPerson().getPersonId());
patientListItem.setDrPersonId(user.getPerson().getPersonId()); //needs a person id so default to clerk

PatientSpecialtyNeededItem specialtyItemNeeded = new PatientSpecialtyNeededItem();
specialtyItemNeeded.setDateCreated(new Date());
specialtyItemNeeded.setPatientId(patientId);

PatientSpecialtyNeededItem mostCurrentSpecialtyNeeded = null;
List<PatientSpecialtyNeededItem> specialtiesNeeded = Context.getService(PatientSpecialtyNeededItemService.class)
.getPatientSpecialtyNeededItemForPatient(patientId);
mostCurrentSpecialtyNeeded = specialtiesNeeded.get(0);
for (PatientSpecialtyNeededItem item : specialtiesNeeded) {
if (item.getDateCreated().after(mostCurrentSpecialtyNeeded.getDateCreated())) {
mostCurrentSpecialtyNeeded = item;
}
}
specialtyItemNeeded.setSpecialtyTypeId(mostCurrentSpecialtyNeeded.getSpecialtyTypeId());
System.out.println("*****Old patient with specialty added to list, specialty: "
+ specialtyItemNeeded.getSpecialtyTypeId());

Context.getService(PatientSpecialtyNeededItemService.class).savePatientSpecialtyNeededItem(specialtyItemNeeded);
} else {
System.out.println("Unsuccessful attempt to call patient, item id: " + itemId);
patientListItem = Context.getService(PatientListItemService.class).getPatientListItem(itemId);

0 comments on commit 9892b56

Please sign in to comment.