Table of Contents |
---|
Introduction
This document describes the steps to add customised tokens used for various label types in OpenSpecimen. For example specimen print tokens, specimen label tokens, visit label tokens, ppid PPID label tokens, etc. This guide is intended for developers or technical IT staff.
Prerequisites
...
- Know how to create plugins in OpenSpecimen - how to write a plugin for OpenSpecimen?
- Know Java programming language
Steps
...
Below is the detailed example of specimen print label token to add collection container name. At the bottom of each step, specified the changes required to implement other type of tokens.
- Write a Java class that extends AbstractLabelTmplToken and implements LabelTmplToken. The following example describes how to implement LabelTmplToken:
Code Block |
---|
public class SpecimenCollectionContainerPrintToken extends AbstractLabelTmplToken implements LabelTmplToken { @Override public String getName() { return "specimen_collection_container"; } @Override public String getReplacement(Object object) { Specimen specimen = (Specimen)object; while (specimen.getParentSpecimen() != null) { specimen = specimen.getParentSpecimen(); } return specimen.getCollectionEvent().getContainer(); } } |
Please refer below for other types of label tokens
i) For specimen label token extend AbstractSpecimenLabelToken. Refer attached example of PPID label token PpidLabelToken.java.
ii) For visit label token extend AbstractVisitLabelToken class. Refer attached example of event label token EventLabelToken.java.
iii) For participant ppid label token extend AbstractPpidToken class. Refer attached example of cp code label token CpCodePpidToken.java.
2. The next step will be to register this new token with the com.krishagni.catissueplus.core.common.domain.LabelTmplTokenRegistrar, to make OpenSpecimen aware of this new token. To register the new token, one needs to write a java class in the plugin like below:
...
3. After adding this plugin initializer class you also need to define this bean in the spring context file located at PLUGIN_HOME/src/main/resources/pluginContext.xml. Following example describes how to define this bean:
...
Code Block |
---|
<bean id="pluginInitializer" class="com.krishagni.openspecimen.plugin.init.PluginInitializer">
<property name="labelTokensRegistrar" ref="specimenPrintLabelTokensRegistrar"/>
</bean>
|
4. Add message property for label token, which is used to show token's display name in generated print file as shown below. The format of the key is print_<token_name_in_lowercase>
Code Block | ||
---|---|---|
| ||
print_specimen_collection_container=Collection Procedure |
In above bean specimenPrintLabelTokensRegistrar is to register specimen print label token. Replace registrar bean name according to your label token type by referring below list
Label Type | Registrar Bean |
---|---|
PPID Label Token | ppidTokensRegistrar |
Specimen Label Token | specimenTokenRegistrar |
Visit Label Token | visitTokenRegistrar |
You can download the complete working example from here:
View file | ||||||
---|---|---|---|---|---|---|
|