/** @see FormSubmissionControllerAction#handleSubmission(FormEntrySession, HttpServletRequest) */ @Override public void handleSubmission(FormEntrySession session, HttpServletRequest submission) { if (dateWidget != null) { Date date = (Date) dateWidget.getValue(session.getContext(), submission); if (session.getSubmissionActions().getCurrentEncounter().getEncounterDatetime() != null && !session .getSubmissionActions() .getCurrentEncounter() .getEncounterDatetime() .equals(date)) { session .getContext() .setPreviousEncounterDate( new Date( session .getSubmissionActions() .getCurrentEncounter() .getEncounterDatetime() .getTime())); } session.getSubmissionActions().getCurrentEncounter().setEncounterDatetime(date); } if (timeWidget != null) { Date time = (Date) timeWidget.getValue(session.getContext(), submission); Encounter e = session.getSubmissionActions().getCurrentEncounter(); Date dateAndTime = HtmlFormEntryUtil.combineDateAndTime(e.getEncounterDatetime(), time); e.setEncounterDatetime(dateAndTime); } if (providerWidget != null) { Object value = providerWidget.getValue(session.getContext(), submission); Person person = (Person) convertValueToProvider(value); session.getSubmissionActions().getCurrentEncounter().setProvider(person); } if (locationWidget != null) { Object value = locationWidget.getValue(session.getContext(), submission); Location location = (Location) HtmlFormEntryUtil.convertToType(value.toString().trim(), Location.class); session.getSubmissionActions().getCurrentEncounter().setLocation(location); } if (encounterTypeWidget != null) { EncounterType encounterType = (EncounterType) encounterTypeWidget.getValue(session.getContext(), submission); session.getSubmissionActions().getCurrentEncounter().setEncounterType(encounterType); } if (voidWidget != null) { if ("true".equals(voidWidget.getValue(session.getContext(), submission))) { session.setVoidEncounter(true); } else if ("false".equals(voidWidget.getValue(session.getContext(), submission))) { // nothing.. the session.voidEncounter property will be false, and the encounter will be // un-voided if already voided // otherwise, nothing will happen. 99% of the time the encounter won't be voided to begin // with. } } }
/** * @see FormSubmissionControllerAction#validateSubmission(FormEntryContext, HttpServletRequest) */ @Override public Collection<FormSubmissionError> validateSubmission( FormEntryContext context, HttpServletRequest submission) { List<FormSubmissionError> ret = new ArrayList<FormSubmissionError>(); try { if (dateWidget != null) { Date date = (Date) dateWidget.getValue(context, submission); if (timeWidget != null) { Date time = (Date) timeWidget.getValue(context, submission); date = HtmlFormEntryUtil.combineDateAndTime(date, time); } if (date == null) throw new Exception("htmlformentry.error.required"); if (OpenmrsUtil.compare((Date) date, new Date()) > 0) throw new Exception("htmlformentry.error.cannotBeInFuture"); } } catch (Exception ex) { ret.add( new FormSubmissionError( context.getFieldName(dateErrorWidget), Context.getMessageSourceService().getMessage(ex.getMessage()))); } try { if (providerWidget != null) { Object value = providerWidget.getValue(context, submission); Person provider = (Person) convertValueToProvider(value); if (provider == null) throw new Exception("required"); } } catch (Exception ex) { ret.add( new FormSubmissionError( context.getFieldName(providerErrorWidget), Context.getMessageSourceService().getMessage(ex.getMessage()))); } try { if (locationWidget != null) { Object value = locationWidget.getValue(context, submission); Location location = (Location) HtmlFormEntryUtil.convertToType(value.toString().trim(), Location.class); if (location == null) throw new Exception("required"); } } catch (Exception ex) { ret.add( new FormSubmissionError( context.getFieldName(locationErrorWidget), Context.getMessageSourceService().getMessage(ex.getMessage()))); } try { if (encounterTypeWidget != null) { Object encounterType = encounterTypeWidget.getValue(context, submission); if (encounterType == null) throw new Exception("required"); } } catch (Exception ex) { ret.add( new FormSubmissionError( context.getFieldName(encounterTypeErrorWidget), Context.getMessageSourceService().getMessage(ex.getMessage()))); } return ret; }