use of org.openmrs.VisitType in project openmrs-core by openmrs.
the class VisitServiceTest method saveVisit_shouldAddANewVisitToTheDatabase.
/**
* @see VisitService#saveVisit(Visit)
*/
@Test
public void saveVisit_shouldAddANewVisitToTheDatabase() {
Integer originalSize = visitService.getAllVisits().size();
Visit visit = new Visit(new Patient(2), new VisitType(1), new Date());
visit = visitService.saveVisit(visit);
assertNotNull(visit.getId());
assertNotNull(visit.getUuid());
assertNotNull(visit.getCreator());
assertNotNull(visit.getDateCreated());
assertEquals(originalSize + 1, visitService.getAllVisits().size());
}
use of org.openmrs.VisitType in project openmrs-core by openmrs.
the class VisitTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see VisitTypeValidator#validate(Object, org.springframework.validation.Errors)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
VisitType visitType = new VisitType();
visitType.setName("name");
visitType.setDescription("some text");
visitType.setRetireReason("some text");
Errors errors = new BindException(visitType, "visitType");
new VisitTypeValidator().validate(visitType, errors);
Assert.assertFalse(errors.hasErrors());
}
use of org.openmrs.VisitType in project openmrs-core by openmrs.
the class VisitTypeValidator method validate.
/**
* Checks the form object for any inconsistencies/errors
*
* @see org.springframework.validation.Validator#validate(java.lang.Object,
* org.springframework.validation.Errors)
* @should fail validation if name is null or empty or whitespace
* @should fail validation if description is null or empty or whitespace
* @should pass validation if all required fields have proper values
* @should pass validation if field lengths are correct
* @should fail validation if field lengths are not correct
*/
@Override
public void validate(Object obj, Errors errors) {
VisitType visitType = (VisitType) obj;
if (visitType == null) {
errors.rejectValue("visitType", "error.general");
} else {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name");
ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "retireReason");
}
}
use of org.openmrs.VisitType in project openmrs-core by openmrs.
the class ExistingOrNewVisitAssignmentHandler method loadVisitType.
/**
* Get the visit type corresponding to an encounter type by reading valid mappings
* from a global property
* @param encounterType
* @return
* @throws APIException
*/
private static VisitType loadVisitType(EncounterType encounterType) throws APIException {
String value = Context.getAdministrationService().getGlobalPropertyValue(OpenmrsConstants.GP_ENCOUNTER_TYPE_TO_VISIT_TYPE_MAPPING, "");
// or encounterTypeUuid:visitTypeUuid o a mixture of uuids and id
if (!StringUtils.isBlank(value)) {
VisitService visitService = Context.getVisitService();
String targetEncounterTypeId = encounterType.getId().toString();
String[] mappings = value.split(",");
for (String mapping : mappings) {
int index = mapping.indexOf(':');
if (index > 0) {
String encounterTypeIdOrUuid = mapping.substring(0, index).trim();
if (targetEncounterTypeId.equals(encounterTypeIdOrUuid) || encounterType.getUuid().equals(encounterTypeIdOrUuid)) {
String visitTypeIdOrUuid = mapping.substring(index + 1).trim();
VisitType visitType;
if (StringUtils.isNumeric(visitTypeIdOrUuid)) {
visitType = visitService.getVisitType(Integer.parseInt(visitTypeIdOrUuid));
} else {
visitType = visitService.getVisitTypeByUuid(visitTypeIdOrUuid);
}
if (visitType != null) {
return visitType;
}
}
}
}
// Reaching here means this encounter type is not in the user's mapping.
throw new APIException("GlobalProperty.error.loadVisitType", new Object[] { encounterType.getName() });
}
return Context.getVisitService().getAllVisitTypes().get(0);
}
use of org.openmrs.VisitType in project openmrs-module-pihcore by PIH.
the class BaseInpatientReportTest method setup.
@Before
@Override
public void setup() throws Exception {
super.setup();
VisitType atFacility = visitService.getVisitTypeByUuid(PihEmrConfigConstants.VISITTYPE_CLINIC_OR_HOSPITAL_VISIT_UUID);
EncounterType checkIn = getCheckInEncounterType();
EncounterType admission = getAdmissionEncounterType();
EncounterType transfer = getTransferEncounterType();
EncounterType exit = getExitEncounterType();
EncounterType consultation = getConsultationEncounterType();
EncounterType postOpNote = getPostOpNoteEncounterType();
Location visitLocation = locationService.getLocation("Mirebalais");
Location outpatientClinic = locationService.getLocation("Klinik Ekstèn");
Location womensInternalMedicine = locationService.getLocation("Sal Fanm");
Location mensInternalMedicine = locationService.getLocation("Sal Gason");
Location surgicalWard = locationService.getLocation("Sal Aprè Operasyon");
Location emergencyDepartment = locationService.getLocation("Ijans");
Concept dispositionConcept = conceptService.getConceptByUuid("c8b22b09-e2f2-4606-af7d-e52579996de3");
// Already admitted at start of 3 Oct (Women's Internal Medicine)
patient1 = data.randomPatient().save();
String startDateStr = "2013-10-02 09:15:00";
patient1 = this.conditionallySetBirthDateBeforeStartDate(patient1, startDateStr);
Visit visit1 = data.visit().patient(patient1).visitType(atFacility).started(startDateStr).stopped("2013-10-14 04:30:00").location(visitLocation).save();
Encounter enc1a = data.encounter().visit(visit1).encounterType(checkIn).location(outpatientClinic).encounterDatetime("2013-10-02 09:15:00").save();
Encounter enc1b = data.encounter().visit(visit1).encounterType(admission).location(womensInternalMedicine).encounterDatetime("2013-10-02 12:30:00").save();
// Admitted and discharged the days before. Visit extends into 3 Oct, but they've already been discharged at that point. (I.e. not an inpatient on Oct 3.)
patient2 = data.randomPatient().save();
startDateStr = "2013-10-01 17:30:00";
patient2 = this.conditionallySetBirthDateBeforeStartDate(patient2, startDateStr);
Visit visit2 = data.visit().patient(patient2).visitType(atFacility).started(startDateStr).stopped("2013-10-03 12:45:00").location(visitLocation).save();
data.encounter().visit(visit2).encounterType(checkIn).location(outpatientClinic).encounterDatetime(startDateStr).save();
data.encounter().visit(visit2).encounterType(admission).location(womensInternalMedicine).encounterDatetime("2013-10-01 18:30:00").save();
data.encounter().visit(visit2).encounterType(exit).location(womensInternalMedicine).encounterDatetime("2013-10-02 23:45:00").save();
// Admitted during the day of 3 Oct (Men's Internal Medicine)
patient3 = data.randomPatient().save();
startDateStr = "2013-10-03 12:34:00";
patient3 = this.conditionallySetBirthDateBeforeStartDate(patient3, startDateStr);
Visit visit3a = data.visit().patient(patient3).visitType(atFacility).started(startDateStr).stopped("2013-10-07 12:45:00").location(visitLocation).save();
data.encounter().visit(visit3a).encounterType(checkIn).location(outpatientClinic).encounterDatetime(startDateStr).save();
data.encounter().visit(visit3a).encounterType(admission).location(mensInternalMedicine).encounterDatetime("2013-10-03 13:57:00").save();
Encounter encounter3a = data.encounter().visit(visit3a).encounterType(exit).location(mensInternalMedicine).encounterDatetime("2013-10-07 12:45:00").save();
data.obs().encounter(encounter3a).concept(dispositionConcept).value("Transfer out of hospital", "PIH").save();
// This was a possible readmission, because the patient was admitted and left the previous day
startDateStr = "2013-10-02 12:34:00";
Visit visit3b = data.visit().patient(patient3).visitType(atFacility).started(startDateStr).stopped("2013-10-02 16:45:00").location(visitLocation).save();
data.encounter().visit(visit3b).encounterType(admission).location(mensInternalMedicine).encounterDatetime(startDateStr).save();
Encounter encounter3b = data.encounter().visit(visit3b).encounterType(exit).location(mensInternalMedicine).encounterDatetime("2013-10-02 16:45:00").save();
data.obs().encounter(encounter3b).concept(dispositionConcept).value("Departed without medical discharge", "PIH").save();
// Admitted earlier (Men's Internal Medicine), and discharged on 3 Oct
patient4 = data.randomPatient().save();
startDateStr = "2013-10-01 12:34:00";
patient4 = this.conditionallySetBirthDateBeforeStartDate(patient4, startDateStr);
Visit visit4 = data.visit().patient(patient4).visitType(atFacility).started(startDateStr).stopped("2013-10-03 12:45:00").location(visitLocation).save();
data.encounter().visit(visit4).encounterType(checkIn).location(outpatientClinic).encounterDatetime(startDateStr).save();
data.encounter().visit(visit4).encounterType(admission).location(mensInternalMedicine).encounterDatetime("2013-10-01 13:57:00").save();
data.encounter().visit(visit4).encounterType(exit).location(mensInternalMedicine).encounterDatetime("2013-10-03 12:45:00").save();
// consult with discharge
Encounter encounter4a = data.encounter().visit(visit4).encounterType(consultation).location(mensInternalMedicine).encounterDatetime("2013-10-03 12:15:00").save();
data.obs().encounter(encounter4a).concept(dispositionConcept).value("DISCHARGED", "PIH").save();
// Begins the day of 3 Oct at Women's Inpatient (was admitted earlier), and transferred to Surgical Ward during the day
patient5 = data.randomPatient().save();
startDateStr = "2013-10-01 12:34:00";
patient5 = this.conditionallySetBirthDateBeforeStartDate(patient5, startDateStr);
Visit visit5 = data.visit().patient(patient5).visitType(atFacility).started(startDateStr).stopped("2013-10-13 12:45:00").location(visitLocation).save();
data.encounter().visit(visit5).encounterType(checkIn).location(outpatientClinic).encounterDatetime(startDateStr).save();
data.encounter().visit(visit5).encounterType(admission).location(womensInternalMedicine).encounterDatetime("2013-10-01 13:57:00").save();
data.encounter().visit(visit5).encounterType(transfer).location(surgicalWard).encounterDatetime("2013-10-03 12:45:00").save();
// Checks into ED during the day, transferred to surgery (with no admission), and has surgery
patient6 = data.randomPatient().save();
startDateStr = "2013-10-03 10:05:00";
patient6 = this.conditionallySetBirthDateBeforeStartDate(patient6, startDateStr);
Visit visit6 = data.visit().patient(patient6).visitType(atFacility).started(startDateStr).stopped("2013-10-03 18:32:21").location(visitLocation).save();
data.encounter().visit(visit6).encounterType(checkIn).location(emergencyDepartment).encounterDatetime(startDateStr).save();
data.encounter().visit(visit6).encounterType(transfer).location(surgicalWard).encounterDatetime("2013-10-03 12:45:00").save();
data.encounter().visit(visit6).encounterType(postOpNote).location(surgicalWard).encounterDatetime("2013-10-03 14:53:00").save();
}
Aggregations