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.commons.lang3.builder.EqualsBuilder;
24  import org.apache.commons.lang3.builder.HashCodeBuilder;
25  import org.apache.commons.lang3.builder.ToStringBuilder;
26  import org.apache.commons.lang3.builder.ToStringStyle;
27  
28  import javax.persistence.*;
29  import java.io.Serializable;
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  @Entity
34  @Table(name = "TRM_CONCEPT_MAP_GRP_ELEMENT", indexes = {
35  	@Index(name = "IDX_CNCPT_MAP_GRP_CD", columnList = "SOURCE_CODE")
36  })
37  public class TermConceptMapGroupElement implements Serializable {
38  	@Id()
39  	@SequenceGenerator(name = "SEQ_CONCEPT_MAP_GRP_ELM_PID", sequenceName = "SEQ_CONCEPT_MAP_GRP_ELM_PID")
40  	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CONCEPT_MAP_GRP_ELM_PID")
41  	@Column(name = "PID")
42  	private Long myId;
43  
44  	@ManyToOne()
45  	@JoinColumn(name = "CONCEPT_MAP_GROUP_PID", nullable = false, referencedColumnName = "PID", foreignKey=@ForeignKey(name="FK_TCMGELEMENT_GROUP"))
46  	private TermConceptMapGroup myConceptMapGroup;
47  
48  	@Column(name = "SOURCE_CODE", nullable = false, length = 100)
49  	private String myCode;
50  
51  	@Column(name = "SOURCE_DISPLAY", length = TermConcept.MAX_DESC_LENGTH)
52  	private String myDisplay;
53  
54  	@OneToMany(mappedBy = "myConceptMapGroupElement")
55  	private List<TermConceptMapGroupElementTarget> myConceptMapGroupElementTargets;
56  
57  	private String myConceptMapUrl;
58  	private String mySystem;
59  	private String mySystemVersion;
60  	private String myValueSet;
61  
62  	public String getCode() {
63  		return myCode;
64  	}
65  
66  	public void setCode(String theCode) {
67  		myCode = theCode;
68  	}
69  
70  	public TermConceptMapGroup getConceptMapGroup() {
71  		return myConceptMapGroup;
72  	}
73  
74  	public void setConceptMapGroup(TermConceptMapGroup theTermConceptMapGroup) {
75  		myConceptMapGroup = theTermConceptMapGroup;
76  	}
77  
78  	public List<TermConceptMapGroupElementTarget> getConceptMapGroupElementTargets() {
79  		if (myConceptMapGroupElementTargets == null) {
80  			myConceptMapGroupElementTargets = new ArrayList<>();
81  		}
82  
83  		return myConceptMapGroupElementTargets;
84  	}
85  
86  	public String getConceptMapUrl() {
87  		if (myConceptMapUrl == null) {
88  			myConceptMapUrl = getConceptMapGroup().getConceptMap().getUrl();
89  		}
90  		return myConceptMapUrl;
91  	}
92  
93  	public String getDisplay() {
94  		return myDisplay;
95  	}
96  
97  	public void setDisplay(String theDisplay) {
98  		myDisplay = theDisplay;
99  	}
100 
101 	public Long getId() {
102 		return myId;
103 	}
104 
105 	public String getSystem() {
106 		if (mySystem == null) {
107 			mySystem = getConceptMapGroup().getSource();
108 		}
109 		return mySystem;
110 	}
111 
112 	public String getSystemVersion() {
113 		if (mySystemVersion == null) {
114 			mySystemVersion = getConceptMapGroup().getSourceVersion();
115 		}
116 		return mySystemVersion;
117 	}
118 
119 	public String getValueSet() {
120 		if (myValueSet == null) {
121 			myValueSet = getConceptMapGroup().getSourceValueSet();
122 		}
123 		return myValueSet;
124 	}
125 
126 	@Override
127 	public boolean equals(Object o) {
128 		if (this == o) return true;
129 
130 		if (!(o instanceof TermConceptMapGroupElement)) return false;
131 
132 		TermConceptMapGroupElement that = (TermConceptMapGroupElement) o;
133 
134 		return new EqualsBuilder()
135 			.append(getCode(), that.getCode())
136 			.append(getSystem(), that.getSystem())
137 			.append(getSystemVersion(), that.getSystemVersion())
138 			.isEquals();
139 	}
140 
141 	@Override
142 	public int hashCode() {
143 		return new HashCodeBuilder(17, 37)
144 			.append(getCode())
145 			.append(getSystem())
146 			.append(getSystemVersion())
147 			.toHashCode();
148 	}
149 
150 	@Override
151 	public String toString() {
152 		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
153 			.append("myId", myId)
154 			.append("myConceptMapGroup - id", myConceptMapGroup.getId())
155 			.append("myCode", myCode)
156 			.append("myDisplay", myDisplay)
157 			.append("myConceptMapGroupElementTargets - size", myConceptMapGroupElementTargets.size())
158 			.append("myConceptMapUrl", this.getConceptMapUrl())
159 			.append("mySystem", this.getSystem())
160 			.append("mySystemVersion", this.getSystemVersion())
161 			.append("myValueSet", this.getValueSet())
162 			.toString();
163 	}
164 }