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 org.apache.commons.lang3.builder.ToStringBuilder; 037import org.apache.commons.lang3.builder.ToStringStyle; 038import org.hibernate.Length; 039 040import java.io.Serializable; 041import java.util.Objects; 042 043import static org.apache.commons.lang3.StringUtils.left; 044import static org.apache.commons.lang3.StringUtils.length; 045 046@Entity 047@Table( 048 name = "TRM_CONCEPT_DESIG", 049 uniqueConstraints = {}, 050 indexes = { 051 // must have same name that indexed FK or SchemaMigrationTest complains because H2 sets this index 052 // automatically 053 @Index(name = "FK_CONCEPTDESIG_CONCEPT", columnList = "CONCEPT_PID", unique = false), 054 @Index(name = "FK_CONCEPTDESIG_CSV", columnList = "CS_VER_PID") 055 }) 056public class TermConceptDesignation implements Serializable { 057 private static final long serialVersionUID = 1L; 058 059 public static final int MAX_LENGTH = 500; 060 public static final int MAX_VAL_LENGTH = 2000; 061 062 @ManyToOne(fetch = FetchType.LAZY) 063 @JoinColumn( 064 name = "CONCEPT_PID", 065 referencedColumnName = "PID", 066 foreignKey = @ForeignKey(name = "FK_CONCEPTDESIG_CONCEPT")) 067 private TermConcept myConcept; 068 069 @Id() 070 @SequenceGenerator(name = "SEQ_CONCEPT_DESIG_PID", sequenceName = "SEQ_CONCEPT_DESIG_PID") 071 @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CONCEPT_DESIG_PID") 072 @Column(name = "PID") 073 private Long myId; 074 075 @Column(name = "LANG", nullable = true, length = MAX_LENGTH) 076 private String myLanguage; 077 078 @Column(name = "USE_SYSTEM", nullable = true, length = MAX_LENGTH) 079 private String myUseSystem; 080 081 @Column(name = "USE_CODE", nullable = true, length = MAX_LENGTH) 082 private String myUseCode; 083 084 @Column(name = "USE_DISPLAY", nullable = true, length = MAX_LENGTH) 085 private String myUseDisplay; 086 087 @Column(name = "VAL", nullable = true, length = MAX_VAL_LENGTH) 088 private String myValue; 089 090 @Column(name = "VAL_VC", nullable = true, length = Length.LONG32) 091 private String myValueVc; 092 /** 093 * TODO: Make this non-null 094 * 095 * @since 3.5.0 096 */ 097 @ManyToOne(fetch = FetchType.LAZY) 098 @JoinColumn( 099 name = "CS_VER_PID", 100 nullable = true, 101 referencedColumnName = "PID", 102 foreignKey = @ForeignKey(name = "FK_CONCEPTDESIG_CSV")) 103 private TermCodeSystemVersion myCodeSystemVersion; 104 105 public String getLanguage() { 106 return myLanguage; 107 } 108 109 public TermConceptDesignation setLanguage(String theLanguage) { 110 ValidateUtil.isNotTooLongOrThrowIllegalArgument( 111 theLanguage, 112 MAX_LENGTH, 113 "Language exceeds maximum length (" + MAX_LENGTH + "): " + length(theLanguage)); 114 myLanguage = theLanguage; 115 return this; 116 } 117 118 public String getUseCode() { 119 return myUseCode; 120 } 121 122 public TermConceptDesignation setUseCode(String theUseCode) { 123 ValidateUtil.isNotTooLongOrThrowIllegalArgument( 124 theUseCode, MAX_LENGTH, "Use code exceeds maximum length (" + MAX_LENGTH + "): " + length(theUseCode)); 125 myUseCode = theUseCode; 126 return this; 127 } 128 129 public String getUseDisplay() { 130 return myUseDisplay; 131 } 132 133 public TermConceptDesignation setUseDisplay(String theUseDisplay) { 134 myUseDisplay = left(theUseDisplay, MAX_LENGTH); 135 return this; 136 } 137 138 public String getUseSystem() { 139 return myUseSystem; 140 } 141 142 public TermConceptDesignation setUseSystem(String theUseSystem) { 143 ValidateUtil.isNotTooLongOrThrowIllegalArgument( 144 theUseSystem, 145 MAX_LENGTH, 146 "Use system exceeds maximum length (" + MAX_LENGTH + "): " + length(theUseSystem)); 147 myUseSystem = theUseSystem; 148 return this; 149 } 150 151 public String getValue() { 152 return Objects.nonNull(myValueVc) ? myValueVc : myValue; 153 } 154 155 public TermConceptDesignation setValue(@Nonnull String theValueVc) { 156 myValueVc = theValueVc; 157 return this; 158 } 159 160 public TermConceptDesignation setCodeSystemVersion(TermCodeSystemVersion theCodeSystemVersion) { 161 myCodeSystemVersion = theCodeSystemVersion; 162 return this; 163 } 164 165 public TermConceptDesignation setConcept(TermConcept theConcept) { 166 myConcept = theConcept; 167 return this; 168 } 169 170 public Long getPid() { 171 return myId; 172 } 173 174 @Override 175 public String toString() { 176 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 177 .append("conceptPid", myConcept.getId()) 178 .append("pid", myId) 179 .append("language", myLanguage) 180 .append("useSystem", myUseSystem) 181 .append("useCode", myUseCode) 182 .append("useDisplay", myUseDisplay) 183 .append("value", myValue) 184 .toString(); 185 } 186}