private void validateStartDatetime(Visit visit, Visit otherVisit, Errors errors) { if (visit.getStartDatetime() != null && otherVisit.getStartDatetime() != null && visit.getStartDatetime().equals(otherVisit.getStartDatetime())) { errors.rejectValue("startDatetime", "Visit.startCannotBeTheSameAsOtherStartDateOfTheSamePatient", "This visit has the same start date and time as another visit of this patient."); } if (visit.getStartDatetime() != null && otherVisit.getStartDatetime() != null && otherVisit.getStopDatetime() != null && visit.getStartDatetime().after(otherVisit.getStartDatetime()) && visit.getStartDatetime().before(otherVisit.getStopDatetime())) { errors.rejectValue("startDatetime", "Visit.startDateCannotFallIntoAnotherVisitOfTheSamePatient", "This visit has a start date that falls into another visit of the same patient."); } }
private void validateStopDatetime(Visit visit, Visit otherVisit, Errors errors) { if (visit.getStopDatetime() != null && otherVisit.getStartDatetime() != null && otherVisit.getStopDatetime() != null && visit.getStopDatetime().after(otherVisit.getStartDatetime()) && visit.getStopDatetime().before(otherVisit.getStopDatetime())) { errors.rejectValue("stopDatetime", "Visit.stopDateCannotFallIntoAnotherVisitOfTheSamePatient", "This visit has a stop date that falls into another visit of the same patient."); } if (visit.getStartDatetime() != null && visit.getStopDatetime() != null && otherVisit.getStartDatetime() != null && otherVisit.getStopDatetime() != null && visit.getStartDatetime().before(otherVisit.getStartDatetime()) && visit.getStopDatetime().after(otherVisit.getStopDatetime())) { String message = "This visit contains another visit of the same patient, " + "i.e. its start date is before the start date of the other visit " + "and its stop date is after the stop date of the other visit."; errors.rejectValue("stopDatetime", "Visit.visitCannotContainAnotherVisitOfTheSamePatient", message); } }
private void validateVisitStartedBeforePatientBirthdate(Visit visit, Errors errors) { if (visit.getPatient() == null || visit.getPatient().getBirthdate() == null || visit.getStartDatetime() == null) { return; } if (visit.getStartDatetime().before(getPatientBirthdateAdjustedIfEstimated(visit.getPatient()))) { errors.rejectValue("startDatetime", "Visit.startDateCannotFallBeforeTheBirthDateOfTheSamePatient", "This visit has a start date that falls before the birthdate of the same patient."); } }
Date o1Date = (o1.getVisit() != null) ? o1.getVisit().getStartDatetime() : o1.getEncounterDatetime(); Date o2Date = (o2.getVisit() != null) ? o2.getVisit().getStartDatetime() : o2.getEncounterDatetime(); return o2Date.compareTo(o1Date); });
/** * @see VisitService#endVisit(Visit,Date) */ @Test(expected = APIException.class) public void endVisit_shouldFailIfValidationErrorsAreFound() { Visit visit = visitService.getVisit(1); Calendar cal = Calendar.getInstance(); cal.setTime(visit.getStartDatetime()); cal.add(Calendar.DAY_OF_MONTH, -1); visitService.endVisit(visit, cal.getTime()); }
private boolean patientHasVoidedVisit(Patient patient, long startInMillis, long stopInMillis) { // To get voided visit from the past, both inactive AND voided visits are queried. // List<Visit> visitList = Context.getVisitService().getVisitsByPatient(patient, true, true); for (Visit visit : visitList) { if (visit.getStartDatetime() != null && visit.getStartDatetime().getTime() == startInMillis && visit.getStopDatetime() != null && visit.getStopDatetime().getTime() == stopInMillis && visit.getVoided()) { return true; } } return false; }
if (visit.getStartDatetime() != null && encounterDateTime.before(visit.getStartDatetime())) { errors.rejectValue("encounterDatetime", "Encounter.datetimeShouldBeInVisitDatesRange", "The encounter datetime should be between the visit start and stop dates.");
if (visit.getStartDatetime().after(encounterDate)) { continue;
ValidationUtils.rejectIfEmpty(errors, "visitType", "Visit.error.visitType.required"); ValidationUtils.rejectIfEmpty(errors, "startDatetime", "Visit.error.startDate.required"); if (visit.getStartDatetime() != null && OpenmrsUtil.compareWithNullAsLatest(visit.getStartDatetime(), visit.getStopDatetime()) > 0) { errors.rejectValue("stopDatetime", "Visit.error.endDateBeforeStartDate"); Date startDateTime = visit.getStartDatetime(); Date stopDateTime = visit.getStopDatetime();
@Override public boolean matches(Object argument) { Visit visit = (Visit) argument; return OpenmrsUtil.nullSafeEquals(visit.getLocation(), expected.getLocation()) && OpenmrsUtil.nullSafeEquals(visit.getVisitType(), expected.getVisitType()) && OpenmrsUtil.nullSafeEquals(visit.getIndication(), expected.getIndication()) && OpenmrsUtil.nullSafeEquals(visit.getStartDatetime(), expected.getStartDatetime()) && OpenmrsUtil.nullSafeEquals(visit.getStopDatetime(), expected.getStopDatetime()) && (visit.getEncounters().size() == expected.getEncounters().size()); } };
/** * @see ExistingVisitAssignmentHandler#beforeCreateEncounter(Encounter) */ @Test public void beforeCreateEncounter_shouldNotAssignVisitWhichStoppedBeforeEncounterDate() { Encounter encounter = Context.getEncounterService().getEncounter(1); Assert.assertNull(encounter.getVisit()); //set the visit stop date to that before the encounter date Visit visit = Context.getVisitService().getVisit(1); Calendar calendar = Calendar.getInstance(); calendar.setTime(visit.getStartDatetime()); calendar.set(Calendar.YEAR, 2004); visit.setStopDatetime(calendar.getTime()); Context.getVisitService().saveVisit(visit); new ExistingVisitAssignmentHandler().beforeCreateEncounter(encounter); Assert.assertNull(encounter.getVisit()); } }
/** * @see EncounterValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfEncounterDateTimeIsBeforeVisitStartDateTime() { Encounter encounter = Context.getEncounterService().getEncounter(3); Visit visit = Context.getVisitService().getVisit(1); visit.setPatient(encounter.getPatient()); encounter.setVisit(visit); //Set encounter dateTime to before the visit startDateTime. Date date = new Date(visit.getStartDatetime().getTime() - 1); encounter.setEncounterDatetime(date); errors = new BindException(encounter, "encounter"); encounterValidator.validate(encounter, errors); Assert.assertEquals(true, errors.hasFieldErrors("encounterDatetime")); }
/** * @see VisitValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfTheStartDatetimeIsAfterAnyEncounter() { Visit visit = Context.getVisitService().getVisit(1); Encounter encounter = Context.getEncounterService().getEncounter(3); visit.setPatient(encounter.getPatient()); encounter.setVisit(visit); encounter.setEncounterDatetime(visit.getStartDatetime()); Context.getEncounterService().saveEncounter(encounter); //Set visit start date to after the encounter date. Date date = new Date(encounter.getEncounterDatetime().getTime() + 1); visit.setStartDatetime(date); Errors errors = new BindException(visit, "visit"); new VisitValidator().validate(visit, errors); assertEquals(true, errors.hasFieldErrors("startDatetime")); }
/** * @see VisitValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfTheStopDatetimeIsBeforeAnyEncounter() { Visit visit = Context.getVisitService().getVisit(1); Encounter encounter = Context.getEncounterService().getEncounter(3); visit.setPatient(encounter.getPatient()); encounter.setVisit(visit); encounter.setEncounterDatetime(visit.getStartDatetime()); Context.getEncounterService().saveEncounter(encounter); //Set visit stop date to before the encounter date. Date date = new Date(encounter.getEncounterDatetime().getTime() - 1); visit.setStopDatetime(date); Errors errors = new BindException(visit, "visit"); new VisitValidator().validate(visit, errors); assertEquals(true, errors.hasFieldErrors("stopDatetime")); }
/** * Returns a display string * * @param visit * @return the display string */ @PropertyGetter("display") public String getDisplayString(Visit visit) { String ret = visit.getVisitType() == null ? "?" : visit.getVisitType().getName(); ret += " "; ret += visit.getLocation() == null ? "?" : "@ " + visit.getLocation().getName(); ret += " - "; ret += visit.getStartDatetime() == null ? "?" : Context.getDateTimeFormat().format(visit.getStartDatetime()); return ret; }
Assert.assertFalse(newLocationUuid.equalsIgnoreCase(visit.getLocation().getUuid())); Assert.assertFalse(newIndicationConceptUuid.equalsIgnoreCase(visit.getIndication().getUuid())); Assert.assertFalse(newStartDatetime.equals(visit.getStartDatetime())); Assert.assertFalse(newStopDatetime.equals(visit.getStopDatetime())); Assert.assertEquals(newLocationUuid, updated.getLocation().getUuid()); Assert.assertEquals(newIndicationConceptUuid, updated.getIndication().getUuid()); Assert.assertEquals(newStartDatetime, updated.getStartDatetime()); Assert.assertEquals(newStopDatetime, updated.getStopDatetime());
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest#validateDefaultRepresentation() */ @Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropPresent("patient"); assertPropPresent("visitType"); assertPropPresent("indication"); assertPropPresent("location"); assertPropPresent("encounters"); assertPropEquals("startDatetime", getObject().getStartDatetime()); assertPropEquals("stopDatetime", getObject().getStopDatetime()); assertPropPresent("attributes"); assertPropEquals("voided", getObject().isVoided()); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest#validateFullRepresentation() */ @Override public void validateFullRepresentation() throws Exception { super.validateFullRepresentation(); assertPropPresent("patient"); assertPropPresent("visitType"); assertPropPresent("indication"); assertPropPresent("location"); assertPropPresent("encounters"); assertPropEquals("startDatetime", getObject().getStartDatetime()); assertPropEquals("stopDatetime", getObject().getStopDatetime()); assertPropPresent("attributes"); assertPropEquals("voided", getObject().isVoided()); assertPropPresent("auditInfo"); }