gayanw
(Gayan W.)
August 8, 2017, 10:09am
1
I tried to delete and void visits of a patient from the legacy admin ui. But it results in errors:
When I try to end a visit, I get:
'Visit #3' failed to validate with reason: patient: Patient Id is required, visitType: Visit Type is required, startDatetime: Start date is required`
* @return the url to forward/redirect to
*/
@RequestMapping(method = RequestMethod.POST, value = "/admin/visits/endVisit")
public String endVisit(@ModelAttribute(value = "visit") Visit visit,
@RequestParam(value = "stopDate", required = false) String stopDate, HttpServletRequest request) {
if (!StringUtils.hasLength(stopDate)) {
Context.getVisitService().endVisit(visit, null);
} else {
try {
Context.getVisitService().endVisit(visit, Context.getDateTimeFormat().parse(stopDate));
request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Visit.saved");
return "redirect:" + "/patientDashboard.form?patientId=" + visit.getPatient().getPatientId();
}
catch (ParseException pe) {
request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.date");
}
catch (APIException e) {
request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, e.getMessage());
}
}
When trying to delete it throws the API exception:
SEVERE: org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value : org.openmrs.Visit.startDatetime; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value : org.openmrs.Visit.startDatetime] with root cause
org.hibernate.PropertyValueException: not-null property references a null or transient value : org.openmrs.Visit.startDatetime
* @return the url to forward to
*/
@RequestMapping(method = RequestMethod.POST, value = "/admin/visits/voidVisit")
public String voidVisit(WebRequest request, @ModelAttribute(value = "visit") Visit visit,
@RequestParam(required = false, value = "voidReason") String voidReason, SessionStatus status, ModelMap model) {
if (!StringUtils.hasText(voidReason)) {
voidReason = Context.getMessageSourceService().getMessage("general.default.voidReason");
}
try {
Context.getVisitService().voidVisit(visit, voidReason);
if (log.isDebugEnabled()) {
log.debug("Voided visit with id: " + visit.getId());
}
request.setAttribute(WebConstants.OPENMRS_MSG_ATTR,
Context.getMessageSourceService().getMessage("Visit.voided"), WebRequest.SCOPE_SESSION);
return "redirect:" + VISIT_FORM_URL + ".form?visitId=" + visit.getVisitId() + "&patientId="
+ visit.getPatient().getPatientId();
}
catch (APIException e) {
log.warn("Error occurred while attempting to void visit", e);
dkayiwa
(Daniel Kayiwa)
August 10, 2017, 7:41pm
2
Are you able to reproduce this at? qa-refapp.openmrs.org
abiieez
(mustafa abdat)
October 2, 2017, 11:46am
3
I am curious about this issue as well. Have you found out any solution for this ?
dkayiwa
(Daniel Kayiwa)
October 2, 2017, 2:26pm
4
Did you reproduce it on qa-refapp?
abiieez
(mustafa abdat)
October 2, 2017, 2:34pm
5
I couldnt reprodoce it there. But I managed to fix it by
Updating the visitForm.jsp. Change the hidden field name from patientId to patient.patientId
Updating the VisitFormController.java. Both voidVisit and purgeVisit I updated with
visit = Context.getVisitService().getVisit(visit.getId());
Context.getVisitService().voidVisit(visit, voidReason);
visit = Context.getVisitService().getVisit(visit.getId());
Context.getVisitService().purgeVisit(visit);