Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

This document describes the steps to add customized tokens for label printing. This guide is intended for developers or technical IT staff. Following are the high level steps:

  1. One should have done the plugin setup. For steps please refer how to write a plugin for OpenSpecimen?
  2. To customize the Print token implementation, write a 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();
    	}
    
    }
  3. The next step will be to register this new token with the com.krishagni.catissueplus.core.common.domain.DefaultLabelTmplTokenRegistrar, so that OpenSpecimen can use this for printing. To register the new token, one needs to write a java class in the plugin like below:

    Code Block
    public class PluginInitializer implements InitializingBean {
    	
    	private LabelTmplTokenRegistrar specimenPrintLabelTokensRegistrar;
    	
    	public void setSpecimenPrintLabelTokensRegistrar(LabelTmplTokenRegistrar specimenPrintLabelTokensRegistrar) {
    		this.specimenPrintLabelTokensRegistrar = specimenPrintLabelTokensRegistrar;
    	}
    
    	@Override
    	public void afterPropertiesSet() throws Exception {
    		specimenPrintLabelTokensRegistrar.register(new SpecimenCollectionContainerPrintToken());
    	}
    }