View Javadoc
1   package ca.uhn.fhir.jpa.entity;
2   
3   /*-
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2019 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 ca.uhn.fhir.util.ValidateUtil;
24  import org.apache.commons.lang3.builder.ToStringBuilder;
25  import org.apache.commons.lang3.builder.ToStringStyle;
26  
27  import javax.annotation.Nonnull;
28  import javax.persistence.*;
29  import java.io.Serializable;
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  import static org.apache.commons.lang3.StringUtils.length;
34  
35  @Entity
36  @Table(name = "TRM_CONCEPT_MAP_GROUP")
37  public class TermConceptMapGroup implements Serializable {
38  	private static final long serialVersionUID = 1L;
39  
40  	@Id()
41  	@SequenceGenerator(name = "SEQ_CONCEPT_MAP_GROUP_PID", sequenceName = "SEQ_CONCEPT_MAP_GROUP_PID")
42  	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CONCEPT_MAP_GROUP_PID")
43  	@Column(name = "PID")
44  	private Long myId;
45  
46  	@ManyToOne()
47  	@JoinColumn(name = "CONCEPT_MAP_PID", nullable = false, referencedColumnName = "PID", foreignKey = @ForeignKey(name = "FK_TCMGROUP_CONCEPTMAP"))
48  	private TermConceptMap myConceptMap;
49  
50  	@Column(name = "SOURCE_URL", nullable = false, length = TermCodeSystem.MAX_URL_LENGTH)
51  	private String mySource;
52  
53  	@Column(name = "SOURCE_VERSION", nullable = true, length = TermCodeSystemVersion.MAX_VERSION_LENGTH)
54  	private String mySourceVersion;
55  
56  	@Column(name = "TARGET_URL", nullable = false, length = TermCodeSystem.MAX_URL_LENGTH)
57  	private String myTarget;
58  
59  	@Column(name = "TARGET_VERSION", nullable = true, length = TermCodeSystemVersion.MAX_VERSION_LENGTH)
60  	private String myTargetVersion;
61  
62  	@OneToMany(mappedBy = "myConceptMapGroup")
63  	private List<TermConceptMapGroupElement> myConceptMapGroupElements;
64  
65  	@Column(name= "CONCEPT_MAP_URL", nullable = true, length = TermConceptMap.MAX_URL_LENGTH)
66  	private String myConceptMapUrl;
67  
68  	@Column(name= "SOURCE_VS", nullable = true, length = TermValueSet.MAX_URL_LENGTH)
69  	private String mySourceValueSet;
70  
71  	@Column(name= "TARGET_VS", nullable = true, length = TermValueSet.MAX_URL_LENGTH)
72  	private String myTargetValueSet;
73  
74  	public TermConceptMap getConceptMap() {
75  		return myConceptMap;
76  	}
77  
78  	public TermConceptMapGroup setConceptMap(TermConceptMap theTermConceptMap) {
79  		myConceptMap = theTermConceptMap;
80  		return this;
81  	}
82  
83  	public List<TermConceptMapGroupElement> getConceptMapGroupElements() {
84  		if (myConceptMapGroupElements == null) {
85  			myConceptMapGroupElements = new ArrayList<>();
86  		}
87  
88  		return myConceptMapGroupElements;
89  	}
90  
91  	public String getConceptMapUrl() {
92  		if (myConceptMapUrl == null) {
93  			myConceptMapUrl = getConceptMap().getUrl();
94  		}
95  		return myConceptMapUrl;
96  	}
97  
98  	public Long getId() {
99  		return myId;
100 	}
101 
102 	public String getSource() {
103 		return mySource;
104 	}
105 
106 	public TermConceptMapGroup setSource(@Nonnull String theSource) {
107 		ValidateUtil.isNotBlankOrThrowIllegalArgument(theSource, "theSource must not be null or empty");
108 		ValidateUtil.isNotTooLongOrThrowIllegalArgument(theSource, TermCodeSystem.MAX_URL_LENGTH,
109 			"Source exceeds maximum length (" + TermCodeSystem.MAX_URL_LENGTH + "): " + length(theSource));
110 		this.mySource = theSource;
111 		return this;
112 	}
113 
114 	public String getSourceValueSet() {
115 		if (mySourceValueSet == null) {
116 			mySourceValueSet = getConceptMap().getSource();
117 		}
118 		return mySourceValueSet;
119 	}
120 
121 	public String getSourceVersion() {
122 		return mySourceVersion;
123 	}
124 
125 	public TermConceptMapGroup setSourceVersion(String theSourceVersion) {
126 		ValidateUtil.isNotTooLongOrThrowIllegalArgument(theSourceVersion, TermCodeSystemVersion.MAX_VERSION_LENGTH,
127 			"Source version ID exceeds maximum length (" + TermCodeSystemVersion.MAX_VERSION_LENGTH + "): " + length(theSourceVersion));
128 		mySourceVersion = theSourceVersion;
129 		return this;
130 	}
131 
132 	public String getTarget() {
133 		return myTarget;
134 	}
135 
136 	public TermConceptMapGroup setTarget(@Nonnull String theTarget) {
137 		ValidateUtil.isNotBlankOrThrowIllegalArgument(theTarget, "theTarget must not be null or empty");
138 		ValidateUtil.isNotTooLongOrThrowIllegalArgument(theTarget, TermCodeSystem.MAX_URL_LENGTH,
139 			"Target exceeds maximum length (" + TermCodeSystem.MAX_URL_LENGTH + "): " + length(theTarget));
140 		this.myTarget = theTarget;
141 		return this;
142 	}
143 
144 	public String getTargetValueSet() {
145 		if (myTargetValueSet == null) {
146 			myTargetValueSet = getConceptMap().getTarget();
147 		}
148 		return myTargetValueSet;
149 	}
150 
151 	public String getTargetVersion() {
152 		return myTargetVersion;
153 	}
154 
155 	public TermConceptMapGroup setTargetVersion(String theTargetVersion) {
156 		ValidateUtil.isNotTooLongOrThrowIllegalArgument(theTargetVersion, TermCodeSystemVersion.MAX_VERSION_LENGTH,
157 			"Target version ID exceeds maximum length (" + TermCodeSystemVersion.MAX_VERSION_LENGTH + "): " + length(theTargetVersion));
158 		myTargetVersion = theTargetVersion;
159 		return this;
160 	}
161 
162 	@Override
163 	public String toString() {
164 		return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
165 			.append("myId", myId)
166 			.append(myConceptMap != null ? ("myConceptMap - id=" + myConceptMap.getId()) : ("myConceptMap=(null)"))
167 			.append("mySource", mySource)
168 			.append("mySourceVersion", mySourceVersion)
169 			.append("myTarget", myTarget)
170 			.append("myTargetVersion", myTargetVersion)
171 			.append(myConceptMapGroupElements != null ? ("myConceptMapGroupElements - size=" + myConceptMapGroupElements.size()) : ("myConceptMapGroupElements=(null)"))
172 			.append("myConceptMapUrl", this.getConceptMapUrl())
173 			.append("mySourceValueSet", this.getSourceValueSet())
174 			.append("myTargetValueSet", this.getTargetValueSet())
175 			.toString();
176 	}
177 }