* @param doc
* @return
*/
public List<ItemInstance> process(AnnotatedDocument doc) throws TerminologyException{
List<ItemInstance> items = new ArrayList<ItemInstance>();
PathHelper paths = getPathHelper();
// first pass
for(Concept c: doc.getConcepts()){
if(paths.hasAncestor(c,getConcept())){
ItemInstance item = new ItemInstance(this,c);
item.process(doc);
addInstance(paths, items, item);
}else if(concept.getCodes() != null && !concept.getCodes().isEmpty() && c.getSources().length > 0){
// what if there is a linkage code
String code = concept.getCode(c.getSources()[0]);
if(code != null){
Concept cc = (code.equals(c.getSources()[0].getName()))?c.getTerminology().getRootConcepts()[0]:c.getTerminology().lookupConcept(code);
if(cc != null){
if(paths.hasAncestor(c,cc)){
ItemInstance item = new ItemInstance(this,c);
item.process(doc);
addInstance(paths, items, item);
}
}
}
}
}
// second pass, if nothing was found and there is a more general feature available
if(items.isEmpty() && feature != null){
for(Concept c: doc.getConcepts()){
if(paths.hasAncestor(c,getFeature().getConcept())){
// process this template with feature concept
ItemInstance item = new ItemInstance(this,c);
item.process(doc);
// process a feature template with feature concept