/** * @see PersonValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfDeathDateIsAFutureDate() { Patient pa = new Patient(1); Calendar death = Calendar.getInstance(); death.setTime(new Date()); death.add(Calendar.YEAR, 20); pa.setDeathDate(death.getTime()); Errors errors = new BindException(pa, "patient"); validator.validate(pa, errors); Assert.assertTrue(errors.hasFieldErrors("deathDate")); }
/** * @see org.openmrs.validator.PersonValidator#validate(Object,Errors) */ @Test public void shouldNotSetDeathBeforeBirth() { Patient pa = new Patient(1); Calendar birth = Calendar.getInstance(); birth.setTime(new Date()); birth.add(Calendar.YEAR, +5); pa.setBirthdate(birth.getTime()); Calendar death = Calendar.getInstance(); death.setTime(new Date()); pa.setDeathDate(death.getTime()); Errors errors = new BindException(pa, "patient"); validator.validate(pa, errors); Assert.assertTrue(errors.hasFieldErrors("deathDate")); }
@Test public void validate_shouldPassValidationIfVisitDateOnEstimatedBirthDatesGracePeriod() { Visit visit = new Visit(); Patient patient = new Patient(); calendar.set(2000, 7, 25); patient.setBirthdate(calendar.getTime()); patient.setBirthdateEstimated(true); calendar.set(2010, 7, 25); patient.setDeathDate(calendar.getTime()); visit.setPatient(patient); calendar.set(1995, 7, 25); visit.setStartDatetime(calendar.getTime()); Errors errors = new BindException(visit, "visit"); new VisitValidator().validate(visit, errors); assertThat(errors, not(hasFieldErrors("startDatetime"))); }
@Test public void validate_shouldPassValidationIfVisitDateOnEstimatedBirthDatesMinimumOneYearGracePeriod() { Visit visit = new Visit(); Patient patient = new Patient(); calendar.set(2000, 7, 25); patient.setBirthdate(calendar.getTime()); patient.setBirthdateEstimated(true); calendar.set(2000, 8, 25); patient.setDeathDate(calendar.getTime()); visit.setPatient(patient); calendar.set(1999, 7, 25); visit.setStartDatetime(calendar.getTime()); Errors errors = new BindException(visit, "visit"); new VisitValidator().validate(visit, errors); assertThat(errors, not(hasFieldErrors("startDatetime"))); }
@Test public void validate_shouldFailValidationIfVisitDateBeforeEstimatedBirthDatesMinimumOneYearGracePeriod() { Visit visit = new Visit(); Patient patient = new Patient(); calendar.set(2000, 7, 25); patient.setBirthdate(calendar.getTime()); patient.setBirthdateEstimated(true); calendar.set(2000, 8, 25); patient.setDeathDate(calendar.getTime()); visit.setPatient(patient); calendar.set(1999, 7, 24); visit.setStartDatetime(calendar.getTime()); Errors errors = new BindException(visit, "visit"); new VisitValidator().validate(visit, errors); assertThat(errors, hasFieldErrors("startDatetime", "Visit.startDateCannotFallBeforeTheBirthDateOfTheSamePatient")); } }
@Test public void validate_shouldFailValidationIfVisitDateBeforeEstimatedBirthDatesGracePeriod() { Visit visit = new Visit(); Patient patient = new Patient(); calendar.set(2000, 7, 25); patient.setBirthdate(calendar.getTime()); patient.setBirthdateEstimated(true); calendar.set(2010, 7, 25); patient.setDeathDate(calendar.getTime()); visit.setPatient(patient); calendar.set(1995, 7, 24); visit.setStartDatetime(calendar.getTime()); Errors errors = new BindException(visit, "visit"); new VisitValidator().validate(visit, errors); assertThat(errors, hasFieldErrors("startDatetime", "Visit.startDateCannotFallBeforeTheBirthDateOfTheSamePatient")); }
patient.setDeathDate(deathDate); patient.setCauseOfDeath(cause);
private void mergeDateOfDeath(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) { mergedData.setPriorDateOfDeath(preferred.getDeathDate()); if (preferred.getDeathDate() == null) { preferred.setDeathDate(notPreferred.getDeathDate()); } if (preferred.getCauseOfDeath() != null) { mergedData.setPriorCauseOfDeath(preferred.getCauseOfDeath().getUuid()); } if (preferred.getCauseOfDeath() == null) { preferred.setCauseOfDeath(notPreferred.getCauseOfDeath()); } }
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldAuditPriorDateOfDeath() throws Exception { //retrieve preferred patient and set a date of birth GregorianCalendar cDate = new GregorianCalendar(); cDate.setTime(new Date()); //milliseconds are not serialized into the database. they will be ignored in the test cDate.set(Calendar.MILLISECOND, 0); Patient preferred = patientService.getPatient(999); preferred.setDeathDate(cDate.getTime()); preferred.setDead(true); preferred.setCauseOfDeath(Context.getConceptService().getConcept(3)); preferred.addName(new PersonName("givenName", "middleName", "familyName")); patientService.savePatient(preferred); Patient notPreferred = patientService.getPatient(7); voidOrders(Collections.singleton(notPreferred)); PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred); Assert.assertEquals("prior date of death was not audited", cDate.getTime(), audit.getPersonMergeLogData() .getPriorDateOfDeath()); }
patient.setDeathDate(dateDied); patient.setCauseOfDeath(causeOfDeath); this.savePatient(patient);
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldAuditPriorDateOfDeathEstimated() throws Exception { //retrieve preferred patient and set a date of death GregorianCalendar cDate = new GregorianCalendar(); cDate.setTime(new Date()); Patient preferred = patientService.getPatient(999); preferred.setDeathDate(cDate.getTime()); preferred.setDeathdateEstimated(true); preferred.setCauseOfDeath(Context.getConceptService().getConcept(3)); preferred.addName(new PersonName("givenName", "middleName", "familyName")); patientService.savePatient(preferred); Patient notPreferred = patientService.getPatient(7); voidOrders(Collections.singleton(notPreferred)); PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred); Assert.assertTrue("prior estimated date of death was not audited", audit.getPersonMergeLogData() .getPriorDateOfDeathEstimated()); }
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldAuditPriorCauseOfDeath() throws Exception { //retrieve preferred patient and set a cause of death Patient preferred = patientService.getPatient(999); preferred.setCauseOfDeath(Context.getConceptService().getConcept(3)); preferred.setDeathDate(new Date()); preferred.setDead(true); preferred.addName(new PersonName("givenName", "middleName", "familyName")); patientService.savePatient(preferred); //merge with not preferred Patient notPreferred = patientService.getPatient(7); voidOrders(Collections.singleton(notPreferred)); PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred); Assert.assertEquals("prior cause of death was not audited", Context.getConceptService().getConcept(3).getUuid(), audit.getPersonMergeLogData().getPriorCauseOfDeath()); }
patient.setBirthdate(new Date()); patient.setBirthdateEstimated(true); patient.setDeathDate(new Date()); patient.setCauseOfDeath(new Concept(1)); patient.setGender("male");
patient.setDeathDate(new Date()); patient.setCauseOfDeath(new Concept()); patient.setGender("male");
preferred.setDeathDate(notPreferred.getDeathDate());
patient.setBirthdate(new Date()); patient.setBirthdateEstimated(true); patient.setDeathDate(new Date()); patient.setCauseOfDeath(new Concept()); patient.setGender("male");
@Test public void testOverridingDateFromEncounter() throws Exception { Date newDeathDate = new Date(); Date oldDeathDate = new Date(newDeathDate.getTime() - 1000000); patient.setDeathDate(oldDeathDate); encounter.setEncounterDatetime(newDeathDate); MarkPatientDeadTagHandler.Action action = tagHandler.newAction(); action.setDeathDateFromEncounter(true); action.applyAction(formEntrySession); assertThat(patient.isDead(), is(true)); assertThat(patient.getDeathDate(), is(newDeathDate)); verify(patientService).savePatient(patient); }
@Test public void testNotOverridingDateFromEncounter() throws Exception { Date newDeathDate = new Date(); Date oldDeathDate = new Date(newDeathDate.getTime() - 1000000); patient.setDeathDate(oldDeathDate); encounter.setEncounterDatetime(newDeathDate); MarkPatientDeadTagHandler.Action action = tagHandler.newAction(); action.setDeathDateFromEncounter(true); action.setPreserveExistingDeathDate(true); action.applyAction(formEntrySession); assertThat(patient.isDead(), is(true)); assertThat(patient.getDeathDate(), is(oldDeathDate)); verify(patientService).savePatient(patient); }
public Patient buildOpenMrsPatient(MRSPatient patient, PatientIdentifierType patientIdentifierType, Location location, List<PersonAttributeType> allPersonAttributeTypes) { final Patient openMRSPatient = new Patient(createPersonWithNames(patient)); openMRSPatient.addIdentifier(new PatientIdentifier(patient.getMotechId(), patientIdentifierType, location)); openMRSPatient.setGender(patient.getPerson().getGender()); openMRSPatient.setBirthdate(patient.getPerson().getDateOfBirth().toDate()); openMRSPatient.setBirthdateEstimated(patient.getPerson().getBirthDateEstimated()); openMRSPatient.setDead(patient.getPerson().isDead()); if (patient.getPerson().getDeathDate() != null) { openMRSPatient.setDeathDate(patient.getPerson().getDeathDate().toDate()); } setPatientAddress(openMRSPatient, patient.getPerson().getAddress()); setPersonAttributes(patient, openMRSPatient, allPersonAttributeTypes); return openMRSPatient; }
/** * Marks a patient as dead with the given date of death and comment * * @param motechId Deceased patient's MOTECH id * @param conceptName Concept name for tracking deceased patients * @param dateOfDeath Patient's date of death * @param comment Additional information for the cause of death * @throws PatientNotFoundException Throws this exception if patient with the given MOTECH id does not exists */ @Override public void deceasePatient(String motechId, String conceptName, Date dateOfDeath, String comment) throws PatientNotFoundException { org.openmrs.Patient patient = getOpenmrsPatientByMotechId(motechId); if (patient == null) { throw new PatientNotFoundException("Patient for the MOTECH ID: " + motechId + " is not found"); } patient.setDeathDate(dateOfDeath); patient.setDead(true); Concept concept = openMrsConceptAdapter.getConceptByName(conceptName); patient.setCauseOfDeath(concept); patientService.savePatient(patient); patientService.saveCauseOfDeathObs(patient, dateOfDeath, concept, comment); eventRelay.sendEventMessage(new MotechEvent(EventKeys.PATIENT_DECEASED_SUBJECT, EventHelper.patientParameters(getMrsPatient(patient)))); }