001/* 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2024 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.jpa.entity; 021 022import ca.uhn.fhir.util.ValidateUtil; 023import jakarta.annotation.Nonnull; 024import jakarta.persistence.Column; 025import jakarta.persistence.Entity; 026import jakarta.persistence.FetchType; 027import jakarta.persistence.ForeignKey; 028import jakarta.persistence.GeneratedValue; 029import jakarta.persistence.GenerationType; 030import jakarta.persistence.Id; 031import jakarta.persistence.Index; 032import jakarta.persistence.JoinColumn; 033import jakarta.persistence.ManyToOne; 034import jakarta.persistence.SequenceGenerator; 035import jakarta.persistence.Table; 036import jakarta.persistence.Transient; 037import org.apache.commons.lang3.builder.EqualsBuilder; 038import org.apache.commons.lang3.builder.HashCodeBuilder; 039import org.apache.commons.lang3.builder.ToStringBuilder; 040import org.apache.commons.lang3.builder.ToStringStyle; 041 042import java.io.Serializable; 043 044import static org.apache.commons.lang3.StringUtils.left; 045import static org.apache.commons.lang3.StringUtils.length; 046 047@Table( 048 name = "TRM_VALUESET_C_DESIGNATION", 049 indexes = { 050 // must have same name that indexed FK or SchemaMigrationTest complains because H2 sets this index 051 // automatically 052 @Index(name = "FK_TRM_VALUESET_CONCEPT_PID", columnList = "VALUESET_CONCEPT_PID", unique = false), 053 @Index(name = "FK_TRM_VSCD_VS_PID", columnList = "VALUESET_PID") 054 }) 055@Entity() 056public class TermValueSetConceptDesignation implements Serializable { 057 private static final long serialVersionUID = 1L; 058 059 @Id() 060 @SequenceGenerator(name = "SEQ_VALUESET_C_DSGNTN_PID", sequenceName = "SEQ_VALUESET_C_DSGNTN_PID") 061 @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_VALUESET_C_DSGNTN_PID") 062 @Column(name = "PID") 063 private Long myId; 064 065 @ManyToOne(fetch = FetchType.LAZY) 066 @JoinColumn( 067 name = "VALUESET_CONCEPT_PID", 068 referencedColumnName = "PID", 069 nullable = false, 070 foreignKey = @ForeignKey(name = "FK_TRM_VALUESET_CONCEPT_PID")) 071 private TermValueSetConcept myConcept; 072 073 @Column(name = "VALUESET_CONCEPT_PID", insertable = false, updatable = false, nullable = false) 074 private Long myConceptPid; 075 076 @ManyToOne(fetch = FetchType.LAZY) 077 @JoinColumn( 078 name = "VALUESET_PID", 079 referencedColumnName = "PID", 080 nullable = false, 081 foreignKey = @ForeignKey(name = "FK_TRM_VSCD_VS_PID")) 082 private TermValueSet myValueSet; 083 084 @Column(name = "VALUESET_PID", insertable = false, updatable = false, nullable = false) 085 private Long myValueSetPid; 086 087 @Transient 088 private String myValueSetUrl; 089 090 @Transient 091 private String myValueSetName; 092 093 @Column(name = "LANG", nullable = true, length = TermConceptDesignation.MAX_LENGTH) 094 private String myLanguage; 095 096 @Column(name = "USE_SYSTEM", nullable = true, length = TermConceptDesignation.MAX_LENGTH) 097 private String myUseSystem; 098 099 @Column(name = "USE_CODE", nullable = true, length = TermConceptDesignation.MAX_LENGTH) 100 private String myUseCode; 101 102 @Column(name = "USE_DISPLAY", nullable = true, length = TermConceptDesignation.MAX_LENGTH) 103 private String myUseDisplay; 104 105 @Column(name = "VAL", nullable = false, length = TermConceptDesignation.MAX_VAL_LENGTH) 106 private String myValue; 107 108 @Transient 109 private transient Integer myHashCode; 110 111 public Long getId() { 112 return myId; 113 } 114 115 public TermValueSetConcept getConcept() { 116 return myConcept; 117 } 118 119 public TermValueSetConceptDesignation setConcept(TermValueSetConcept theConcept) { 120 myConcept = theConcept; 121 return this; 122 } 123 124 public TermValueSet getValueSet() { 125 return myValueSet; 126 } 127 128 public TermValueSetConceptDesignation setValueSet(TermValueSet theValueSet) { 129 myValueSet = theValueSet; 130 return this; 131 } 132 133 public String getValueSetUrl() { 134 if (myValueSetUrl == null) { 135 myValueSetUrl = getValueSet().getUrl(); 136 } 137 138 return myValueSetUrl; 139 } 140 141 public String getValueSetName() { 142 if (myValueSetName == null) { 143 myValueSetName = getValueSet().getName(); 144 } 145 146 return myValueSetName; 147 } 148 149 public String getLanguage() { 150 return myLanguage; 151 } 152 153 public TermValueSetConceptDesignation setLanguage(String theLanguage) { 154 ValidateUtil.isNotTooLongOrThrowIllegalArgument( 155 theLanguage, 156 TermConceptDesignation.MAX_LENGTH, 157 "Language exceeds maximum length (" + TermConceptDesignation.MAX_LENGTH + "): " + length(theLanguage)); 158 myLanguage = theLanguage; 159 return this; 160 } 161 162 public String getUseSystem() { 163 return myUseSystem; 164 } 165 166 public TermValueSetConceptDesignation setUseSystem(String theUseSystem) { 167 ValidateUtil.isNotTooLongOrThrowIllegalArgument( 168 theUseSystem, 169 TermConceptDesignation.MAX_LENGTH, 170 "Use system exceeds maximum length (" + TermConceptDesignation.MAX_LENGTH + "): " 171 + length(theUseSystem)); 172 myUseSystem = theUseSystem; 173 return this; 174 } 175 176 public String getUseCode() { 177 return myUseCode; 178 } 179 180 public TermValueSetConceptDesignation setUseCode(String theUseCode) { 181 ValidateUtil.isNotTooLongOrThrowIllegalArgument( 182 theUseCode, 183 TermConceptDesignation.MAX_LENGTH, 184 "Use code exceeds maximum length (" + TermConceptDesignation.MAX_LENGTH + "): " + length(theUseCode)); 185 myUseCode = theUseCode; 186 return this; 187 } 188 189 public String getUseDisplay() { 190 return myUseDisplay; 191 } 192 193 public TermValueSetConceptDesignation setUseDisplay(String theUseDisplay) { 194 myUseDisplay = left(theUseDisplay, TermConceptDesignation.MAX_LENGTH); 195 return this; 196 } 197 198 public String getValue() { 199 return myValue; 200 } 201 202 public TermValueSetConceptDesignation setValue(@Nonnull String theValue) { 203 ValidateUtil.isNotBlankOrThrowIllegalArgument(theValue, "theValue must not be null or empty"); 204 ValidateUtil.isNotTooLongOrThrowIllegalArgument( 205 theValue, 206 TermConceptDesignation.MAX_VAL_LENGTH, 207 "Value exceeds maximum length (" + TermConceptDesignation.MAX_VAL_LENGTH + "): " + length(theValue)); 208 myValue = theValue; 209 return this; 210 } 211 212 @Override 213 public boolean equals(Object theO) { 214 if (this == theO) return true; 215 216 if (!(theO instanceof TermValueSetConceptDesignation)) return false; 217 218 TermValueSetConceptDesignation that = (TermValueSetConceptDesignation) theO; 219 220 return new EqualsBuilder() 221 .append(getLanguage(), that.getLanguage()) 222 .append(getUseSystem(), that.getUseSystem()) 223 .append(getUseCode(), that.getUseCode()) 224 .append(getUseDisplay(), that.getUseDisplay()) 225 .append(getValue(), that.getValue()) 226 .isEquals(); 227 } 228 229 @Override 230 public int hashCode() { 231 if (myHashCode == null) { 232 myHashCode = new HashCodeBuilder(17, 37) 233 .append(getLanguage()) 234 .append(getUseSystem()) 235 .append(getUseCode()) 236 .append(getUseDisplay()) 237 .append(getValue()) 238 .toHashCode(); 239 } 240 return myHashCode; 241 } 242 243 @Override 244 public String toString() { 245 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 246 .append("myId", myId) 247 .append(myConcept != null ? ("myConcept - id=" + myConcept.getId()) : ("myConcept=(null)")) 248 .append("myConceptPid", myConceptPid) 249 .append(myValueSet != null ? ("myValueSet - id=" + myValueSet.getId()) : ("myValueSet=(null)")) 250 .append("myValueSetPid", myValueSetPid) 251 .append("myValueSetUrl", this.getValueSetUrl()) 252 .append("myValueSetName", this.getValueSetName()) 253 .append("myLanguage", myLanguage) 254 .append("myUseSystem", myUseSystem) 255 .append("myUseCode", myUseCode) 256 .append("myUseDisplay", myUseDisplay) 257 .append("myValue", myValue) 258 .toString(); 259 } 260}