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);
}
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");
}
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);
}
}
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);
}
}
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;
}
Aggregations