View Javadoc
1   package ca.uhn.fhir.jpa.entity;
2   
3   /*-
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import org.apache.lucene.document.Document;
24  import org.apache.lucene.document.Field;
25  import org.apache.lucene.document.StringField;
26  import org.hibernate.search.bridge.FieldBridge;
27  import org.hibernate.search.bridge.LuceneOptions;
28  import org.hibernate.search.bridge.StringBridge;
29  
30  import java.util.Collection;
31  
32  import static org.apache.commons.lang3.StringUtils.isNotBlank;
33  
34  /**
35   * Allows hibernate search to index individual concepts' properties
36   */
37  public class TermConceptPropertyFieldBridge implements FieldBridge, StringBridge {
38  
39  	public static final String CONCEPT_FIELD_PROPERTY_PREFIX = "PROP";
40  
41  	/**
42  	 * Constructor
43  	 */
44  	public TermConceptPropertyFieldBridge() {
45  		super();
46  	}
47  
48  	@Override
49  	public String objectToString(Object theObject) {
50  		return theObject.toString();
51  	}
52  
53  	@Override
54  	public void set(String theName, Object theValue, Document theDocument, LuceneOptions theLuceneOptions) {
55  		@SuppressWarnings("unchecked")
56  		Collection<TermConceptProperty> properties = (Collection<TermConceptProperty>) theValue;
57  
58  		if (properties != null) {
59  			for (TermConceptProperty next : properties) {
60  				theDocument.add(new StringField(CONCEPT_FIELD_PROPERTY_PREFIX + next.getKey(), next.getValue(), Field.Store.YES));
61  
62  				if (next.getType() == TermConceptPropertyTypeEnum.CODING) {
63  					if (isNotBlank(next.getDisplay())) {
64  						theDocument.add(new StringField(CONCEPT_FIELD_PROPERTY_PREFIX + next.getKey(), next.getDisplay(), Field.Store.YES));
65  					}
66  				}
67  			}
68  		}
69  	}
70  }