Search in sources :

Example 1 with LocationService

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");
}
Also used : LocationService(org.openmrs.api.LocationService) LocationAttributeType(org.openmrs.LocationAttributeType)

Example 2 with LocationService

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);
}
Also used : DispositionService(org.openmrs.module.emrapi.disposition.DispositionService) LocationService(org.openmrs.api.LocationService) TestUiUtils(org.openmrs.module.appui.TestUiUtils) EmrApiProperties(org.openmrs.module.emrapi.EmrApiProperties) Encounter(org.openmrs.Encounter) EmrConceptService(org.openmrs.module.emrapi.concept.EmrConceptService) ConceptService(org.openmrs.api.ConceptService) EmrConceptService(org.openmrs.module.emrapi.concept.EmrConceptService) Before(org.junit.Before)

Example 3 with LocationService

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"));
}
Also used : LocationService(org.openmrs.api.LocationService) IdentifierSourceService(org.openmrs.module.idgen.service.IdentifierSourceService) MirebalaisHospitalService(org.openmrs.module.mirebalais.api.MirebalaisHospitalService) ImportPatientFromWebService(org.openmrs.module.importpatientfromws.api.ImportPatientFromWebService) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 4 with LocationService

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);
            }
        }
    }
}
Also used : LocationTag(org.openmrs.LocationTag) AdtService(org.openmrs.module.emrapi.adt.AdtService) LocationService(org.openmrs.api.LocationService) VisitService(org.openmrs.api.VisitService) Visit(org.openmrs.Visit) Location(org.openmrs.Location)

Example 5 with LocationService

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);
    }
}
Also used : LocationService(org.openmrs.api.LocationService) VisitService(org.openmrs.api.VisitService) PatientService(org.openmrs.api.PatientService) FormService(org.openmrs.api.FormService) IdentifierSourceService(org.openmrs.module.idgen.service.IdentifierSourceService) Module(org.openmrs.module.Module) ConceptService(org.openmrs.api.ConceptService) EncounterService(org.openmrs.api.EncounterService) MetadataMappingService(org.openmrs.module.metadatamapping.api.MetadataMappingService)

Aggregations

LocationService (org.openmrs.api.LocationService)6 Location (org.openmrs.Location)2 ConceptService (org.openmrs.api.ConceptService)2 VisitService (org.openmrs.api.VisitService)2 IdentifierSourceService (org.openmrs.module.idgen.service.IdentifierSourceService)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Encounter (org.openmrs.Encounter)1 LocationAttributeType (org.openmrs.LocationAttributeType)1 LocationTag (org.openmrs.LocationTag)1 Visit (org.openmrs.Visit)1 EncounterService (org.openmrs.api.EncounterService)1 FormService (org.openmrs.api.FormService)1 PatientService (org.openmrs.api.PatientService)1 Module (org.openmrs.module.Module)1 TestUiUtils (org.openmrs.module.appui.TestUiUtils)1 EmrApiProperties (org.openmrs.module.emrapi.EmrApiProperties)1 AdtService (org.openmrs.module.emrapi.adt.AdtService)1 EmrConceptService (org.openmrs.module.emrapi.concept.EmrConceptService)1