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 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 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.getStopDatetime() != null && visit.getStopDatetime().before(encounterDate)) { continue;
/** * @see VisitService#endVisit(Visit,Date) */ @Test public void endVisit_shouldSetStopDateTimeAsCurrentDateIfStopDateIsNull() { Visit visit = visitService.getVisit(1); assertNull(visit.getStopDatetime()); visitService.endVisit(visit, null); assertNotNull(visit.getStopDatetime()); }
if (visit.getStopDatetime() != null && encounterDateTime.after(visit.getStopDatetime())) { errors.rejectValue("encounterDatetime", "Encounter.datetimeShouldBeInVisitDatesRange", "The encounter datetime should be between the visit start and stop dates.");
@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()); } };
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 stopDateTime = visit.getStopDatetime();
/** * @see EncounterValidator#validate(Object,Errors) */ @Test public void validate_shouldFailIfEncounterDateTimeIsAfterVisitStopDateTime() { Encounter encounter = Context.getEncounterService().getEncounter(3); Visit visit = Context.getVisitService().getVisit(1); visit.setPatient(encounter.getPatient()); encounter.setVisit(visit); //Set encounter dateTime to after the visit stopDateTime. visit.setStopDatetime(new Date()); Date date = new Date(visit.getStopDatetime().getTime() + 1); encounter.setEncounterDatetime(date); errors = new BindException(encounter, "encounter"); encounterValidator.validate(encounter, errors); Assert.assertEquals(true, errors.hasFieldErrors("encounterDatetime")); }
Assert.assertFalse(newIndicationConceptUuid.equalsIgnoreCase(visit.getIndication().getUuid())); Assert.assertFalse(newStartDatetime.equals(visit.getStartDatetime())); Assert.assertFalse(newStopDatetime.equals(visit.getStopDatetime())); 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"); }