use of org.openmrs.api.LocationService in project openmrs-core by openmrs.
the class LocationAttributeTypeValidator method validate.
/**
* @see org.springframework.validation.Validator#validate(java.lang.Object,
* org.springframework.validation.Errors)
* @should fail validation if name is null
* @should fail validation if name already in use
* @should pass validation if the location attribute type description is null or empty or whitespace
* @should pass validation if all fields are correct
* @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) {
super.validate(obj, errors);
LocationAttributeType locationObj = (LocationAttributeType) obj;
LocationService ls = Context.getLocationService();
if (locationObj.getName() != null && !locationObj.getName().isEmpty()) {
LocationAttributeType loc = ls.getLocationAttributeTypeByName(locationObj.getName());
if (loc != null && !loc.getUuid().equals(locationObj.getUuid())) {
errors.rejectValue("name", "LocationAttributeType.error.nameAlreadyInUse");
}
} else {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "LocationAttributeType.error.nameEmpty");
}
ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "description", "datatypeClassname", "preferredHandlerClassname", "retireReason");
}
use of org.openmrs.api.LocationService in project openmrs-module-coreapps by openmrs.
the class ParserEncounterIntoSimpleObjectsTest method setUp.
@Before
public void setUp() throws Exception {
emrApiProperties = mock(EmrApiProperties.class);
conceptService = mock(ConceptService.class);
locationService = mock(LocationService.class);
dispositionService = mock(DispositionService.class);
MockMetadataTestUtil.setupMockConceptService(conceptService, emrApiProperties);
emrConceptService = mock(EmrConceptService.class);
diagnosisMetadata = MockMetadataTestUtil.setupDiagnosisMetadata(emrApiProperties, conceptService);
dispositionDescriptor = MockMetadataTestUtil.setupDispositionDescriptor(conceptService);
when(dispositionService.getDispositionDescriptor()).thenReturn(dispositionDescriptor);
TestUiUtils testUiUtils = new TestUiUtils();
testUiUtils.setMockFormattingConcepts(true);
uiUtils = testUiUtils;
encounter = new Encounter();
parser = new ParserEncounterIntoSimpleObjects(encounter, uiUtils, emrApiProperties, locationService, dispositionService);
}
use of org.openmrs.api.LocationService in project openmrs-module-mirebalais by PIH.
the class MirebalaisHospitalActivatorIT method testThatActivatorDoesAllSetup.
@Test
@DirtiesContext
public void testThatActivatorDoesAllSetup() throws Exception {
MirebalaisHospitalService service = Context.getService(MirebalaisHospitalService.class);
IdentifierSourceService identifierSourceService = Context.getService(IdentifierSourceService.class);
LocationService locationService = Context.getLocationService();
/**
* ConfigureIdGenerators configureIdGenerators = new ConfigureIdGenerators(identifierSourceService, locationService);
*
* IdentifierPool localZlIdentifierPool = service.getLocalZlIdentifierPool();
* RemoteIdentifierSource remoteZlIdentifierSource = service.getRemoteZlIdentifierSource();
* SequentialIdentifierGenerator dossierSequenceGenerator = service.getDossierSequenceGenerator(PihCoreConstants.UHM_DOSSIER_NUMBER_IDENTIFIER_SOURCE_UUID);
*
* PatientIdentifierType zlIdentifierType = Context.getPatientService().getPatientIdentifierTypeByUuid(HaitiPatientIdentifierTypes.ZL_EMR_ID.uuid());
* PatientIdentifierType dossierNumberIdentifierType = Context.getPatientService().getPatientIdentifierTypeByUuid(HaitiPatientIdentifierTypes.DOSSIER_NUMBER.uuid());
*
* AutoGenerationOption autoGenerationOption = Context.getService(IdentifierSourceService.class).getAutoGenerationOption(zlIdentifierType);
*
* assertEquals(HaitiPatientIdentifierTypes.ZL_EMR_ID.uuid(), zlIdentifierType.getUuid());
* assertEquals(zlIdentifierType, autoGenerationOption.getIdentifierType());
* assertEquals(localZlIdentifierPool, autoGenerationOption.getSource());
*
* assertEquals(PihCoreConstants.LOCAL_ZL_IDENTIFIER_POOL_UUID, localZlIdentifierPool.getUuid());
* assertEquals(PihCoreConstants.LOCAL_ZL_IDENTIFIER_POOL_BATCH_SIZE, localZlIdentifierPool.getBatchSize());
* assertEquals(PihCoreConstants.LOCAL_ZL_IDENTIFIER_POOL_MIN_POOL_SIZE, localZlIdentifierPool.getMinPoolSize());
*
* assertEquals(PihCoreConstants.REMOTE_ZL_IDENTIFIER_SOURCE_UUID, remoteZlIdentifierSource.getUuid());
* assertEquals(configureIdGenerators.getRemoteZlIdentifierSourceUrl(), remoteZlIdentifierSource.getUrl());
* assertEquals(configureIdGenerators.getRemoteZlIdentifierSourceUsername(), remoteZlIdentifierSource.getUser());
* assertEquals(configureIdGenerators.getRemoteZlIdentifierSourcePassword(), remoteZlIdentifierSource.getPassword());
*
* assertEquals("A", dossierSequenceGenerator.getPrefix());
* assertEquals(new Integer(7), dossierSequenceGenerator.getMaxLength());
* assertEquals(new Integer(7), dossierSequenceGenerator.getMinLength());
* assertEquals("0123456789", dossierSequenceGenerator.getBaseCharacterSet());
* assertEquals("000001", dossierSequenceGenerator.getFirstIdentifierBase());
* assertEquals(PihCoreConstants.UHM_DOSSIER_NUMBER_IDENTIFIER_SOURCE_UUID, dossierSequenceGenerator.getUuid());
* assertEquals(dossierNumberIdentifierType, dossierSequenceGenerator.getIdentifierType());
* assertEquals(2, Context.getService(IdentifierSourceService.class).getAutoGenerationOptions(dossierNumberIdentifierType).size());
*/
assertNotNull(Context.getService(ImportPatientFromWebService.class).getRemoteServers().get("lacolline"));
}
use of org.openmrs.api.LocationService in project openmrs-module-pihcore by PIH.
the class PihCloseStaleVisitsTask method execute.
public void execute() {
AdtService adtService = Context.getService(AdtService.class);
VisitService visitService = Context.getVisitService();
LocationService locationService = Context.getLocationService();
LocationTag visitLocationTag = locationService.getLocationTagByName(EmrApiConstants.LOCATION_TAG_SUPPORTS_VISITS);
List<Location> locations = locationService.getLocationsByTag(visitLocationTag);
List<Visit> openVisits = visitService.getVisits(null, null, locations, null, null, null, null, null, null, false, false);
for (Visit visit : openVisits) {
if ((isOldEDVisit(adtService.wrap(visit), ED_VISIT_EXPIRE_VERY_OLD_TIME_IN_HOURS)) || (adtService.shouldBeClosed(visit) && !isActiveEDVisit(adtService.wrap(visit), ED_VISIT_EXPIRE_TIME_IN_HOURS)) || wasDischargedAndNotAdmitted(adtService.wrap(visit), HUM_VISIT_EXPIRE_TIME_IN_HOURS)) {
try {
adtService.closeAndSaveVisit(visit);
} catch (Exception ex) {
log.warn("Failed to close inactive visit " + visit, ex);
}
}
}
}
use of org.openmrs.api.LocationService in project openmrs-module-pihcore by PIH.
the class PihCoreActivator method started.
// TODO test
@Override
public void started() {
try {
MetadataMappingService metadataMappingService = Context.getService(MetadataMappingService.class);
PatientService patientService = Context.getPatientService();
FormService formService = Context.getFormService();
LocationService locationService = Context.getLocationService();
EncounterService encounterService = Context.getEncounterService();
VisitService visitService = Context.getVisitService();
IdentifierSourceService identifierSourceService = Context.getService(IdentifierSourceService.class);
ConceptService conceptService = Context.getService(ConceptService.class);
if (config == null) {
// hack to allow injecting a mock config for testing
// currently only one of these
config = Context.getRegisteredComponents(Config.class).get(0);
}
setDispositionConfig(config);
installMetadataBundles(config);
setGlobalProperties(config);
setExtraIdentifierTypes(metadataMappingService, patientService, config);
MergeActionsSetup.registerMergeActions();
LocationTagSetup.setupLocationTags(locationService, config);
HtmlFormSetup.setupHtmlFormEntryTagHandlers();
MetadataMappingsSetup.setupGlobalMetadataMappings(metadataMappingService, locationService, encounterService, visitService);
MetadataMappingsSetup.setupPrimaryIdentifierTypeBasedOnCountry(metadataMappingService, patientService, config);
MetadataMappingsSetup.setupFormMetadataMappings(metadataMappingService);
PatientIdentifierSetup.setupIdentifierGeneratorsIfNecessary(identifierSourceService, locationService, config);
PacIntegrationSetup.setup(config);
AttachmentsSetup.migrateAttachmentsConceptsIfNecessary(conceptService);
// RetireProvidersSetup.setupRetireProvidersTask();
} catch (Exception e) {
Module mod = ModuleFactory.getModuleById("pihcore");
ModuleFactory.stopModule(mod);
throw new RuntimeException("failed to setup the required modules", e);
}
}
Aggregations