Search in sources :

Example 11 with ConceptService

use of org.openmrs.api.ConceptService 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 12 with ConceptService

use of org.openmrs.api.ConceptService in project openmrs-module-coreapps by openmrs.

the class CoreAppsActivator method contextRefreshed.

/**
 * @see ModuleActivator#contextRefreshed()
 */
public void contextRefreshed() {
    ConceptService conceptService = Context.getConceptService();
    EmrApiProperties emrApiProperties = Context.getRegisteredComponent("emrApiProperties", EmrApiProperties.class);
    DispositionService dispositionService = Context.getRegisteredComponent("dispositionService", DispositionService.class);
    AdtService adtService = Context.getRegisteredComponent("adtService", AdtService.class);
    UiUtils uiUtils = Context.getRegisteredComponent("uiUtils", BasicUiUtils.class);
    if (ModuleFactory.isModuleStarted("htmlformentry")) {
        HtmlFormEntryService htmlFormEntryService = Context.getService(HtmlFormEntryService.class);
        EncounterDiagnosesTagHandler encounterDiagnosesTagHandler = CoreAppsActivator.setupEncounterDiagnosesTagHandler(conceptService, adtService, emrApiProperties, uiUtils);
        htmlFormEntryService.addHandler(CoreAppsConstants.HTMLFORMENTRY_ENCOUNTER_DIAGNOSES_TAG_NAME, encounterDiagnosesTagHandler);
        EncounterDispositionTagHandler encounterDispositionTagHandler = CoreAppsActivator.setupEncounterDispositionTagHandler(emrApiProperties, dispositionService, adtService);
        htmlFormEntryService.addHandler(CoreAppsConstants.HTMLFORMENTRY_ENCOUNTER_DISPOSITION_TAG_NAME, encounterDispositionTagHandler);
        htmlFormEntryService.addHandler(CoreAppsConstants.HTMLFORMENTRY_CODED_OR_FREE_TEXT_OBS_TAG_NAME, new CodedOrFreeTextObsTagHandler());
    }
    log.info("Core Apps Module refreshed");
}
Also used : DispositionService(org.openmrs.module.emrapi.disposition.DispositionService) AdtService(org.openmrs.module.emrapi.adt.AdtService) HtmlFormEntryService(org.openmrs.module.htmlformentry.HtmlFormEntryService) EmrApiProperties(org.openmrs.module.emrapi.EmrApiProperties) EncounterDiagnosesTagHandler(org.openmrs.module.coreapps.htmlformentry.EncounterDiagnosesTagHandler) ConceptService(org.openmrs.api.ConceptService) EncounterDispositionTagHandler(org.openmrs.module.coreapps.htmlformentry.EncounterDispositionTagHandler) CodedOrFreeTextObsTagHandler(org.openmrs.module.coreapps.htmlformentry.CodedOrFreeTextObsTagHandler) BasicUiUtils(org.openmrs.ui.framework.BasicUiUtils) UiUtils(org.openmrs.ui.framework.UiUtils)

Example 13 with ConceptService

use of org.openmrs.api.ConceptService in project openmrs-module-coreapps by openmrs.

the class CodedOrFreeTextAnswerListWidget method getValue.

@Override
public Object getValue(FormEntryContext context, HttpServletRequest request) {
    String fieldName = context.getFieldName(this);
    String[] submitted = request.getParameterValues(fieldName);
    if (submitted != null && submitted.length > 1) {
        throw new IllegalArgumentException("Expected one submitted parameter value for " + fieldName + " but got " + submitted.length);
    }
    try {
        List<CodedOrFreeTextAnswer> results = new ArrayList<CodedOrFreeTextAnswer>();
        if (submitted != null && StringUtils.isNotEmpty(submitted[0])) {
            ArrayNode array = new ObjectMapper().readValue(submitted[0], ArrayNode.class);
            ConceptService conceptService = Context.getConceptService();
            for (JsonNode node : array) {
                String conceptNameUuid = node.path("ConceptName").getTextValue();
                String conceptUuid = node.path("Concept").getTextValue();
                String nonCodedValue = node.path("NonCodedValue").getTextValue();
                if (conceptNameUuid != null) {
                    results.add(new CodedOrFreeTextAnswer(conceptService.getConceptNameByUuid(conceptNameUuid)));
                } else if (conceptUuid != null) {
                    results.add(new CodedOrFreeTextAnswer(conceptService.getConceptByUuid(conceptUuid)));
                } else {
                    results.add(new CodedOrFreeTextAnswer(nonCodedValue));
                }
            }
        }
        return results;
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) CodedOrFreeTextAnswer(org.openmrs.module.emrapi.diagnosis.CodedOrFreeTextAnswer) ArrayNode(org.codehaus.jackson.node.ArrayNode) IOException(java.io.IOException) ConceptService(org.openmrs.api.ConceptService) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 14 with ConceptService

use of org.openmrs.api.ConceptService 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)

Example 15 with ConceptService

use of org.openmrs.api.ConceptService in project openmrs-core by openmrs.

the class OpenmrsUtil method conceptListHelper.

// TODO: properly handle duplicates
public static List<Concept> conceptListHelper(String descriptor) {
    List<Concept> ret = new ArrayList<>();
    if (descriptor == null || descriptor.length() == 0) {
        return ret;
    }
    ConceptService cs = Context.getConceptService();
    for (StringTokenizer st = new StringTokenizer(descriptor, "|"); st.hasMoreTokens(); ) {
        String s = st.nextToken().trim();
        boolean isSet = s.startsWith("set:");
        if (isSet) {
            s = s.substring(4).trim();
        }
        Concept c = null;
        if (s.startsWith("name:")) {
            String name = s.substring(5).trim();
            c = cs.getConceptByName(name);
        } else {
            try {
                c = cs.getConcept(Integer.valueOf(s.trim()));
            } catch (Exception ex) {
            }
        }
        if (c != null) {
            if (isSet) {
                List<Concept> inSet = cs.getConceptsByConceptSet(c);
                ret.addAll(inSet);
            } else {
                ret.add(c);
            }
        }
    }
    return ret;
}
Also used : Concept(org.openmrs.Concept) StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) ConceptService(org.openmrs.api.ConceptService) ApplicationContextException(org.springframework.context.ApplicationContextException) TransformerException(javax.xml.transform.TransformerException) InvalidCharactersPasswordException(org.openmrs.api.InvalidCharactersPasswordException) IOException(java.io.IOException) NoSuchMessageException(org.springframework.context.NoSuchMessageException) ModuleException(org.openmrs.module.ModuleException) PatternSyntaxException(java.util.regex.PatternSyntaxException) FileNotFoundException(java.io.FileNotFoundException) PasswordException(org.openmrs.api.PasswordException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WeakPasswordException(org.openmrs.api.WeakPasswordException) APIException(org.openmrs.api.APIException) ShortPasswordException(org.openmrs.api.ShortPasswordException) MalformedURLException(java.net.MalformedURLException)

Aggregations

ConceptService (org.openmrs.api.ConceptService)21 Test (org.junit.Test)11 Concept (org.openmrs.Concept)11 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)11 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 ArrayList (java.util.ArrayList)4 ConceptName (org.openmrs.ConceptName)4 Encounter (org.openmrs.Encounter)4 Patient (org.openmrs.Patient)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 CareSetting (org.openmrs.CareSetting)3 ConceptDescription (org.openmrs.ConceptDescription)3 OrderFrequency (org.openmrs.OrderFrequency)3 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 Date (java.util.Date)2 StringTokenizer (java.util.StringTokenizer)2