001/*- 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2025 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.jpa.model.entity.BasePartitionable; 023import ca.uhn.fhir.jpa.model.entity.IdAndPartitionId; 024import ca.uhn.fhir.util.ValidateUtil; 025import jakarta.annotation.Nonnull; 026import jakarta.persistence.Column; 027import jakarta.persistence.Entity; 028import jakarta.persistence.ForeignKey; 029import jakarta.persistence.GeneratedValue; 030import jakarta.persistence.GenerationType; 031import jakarta.persistence.Id; 032import jakarta.persistence.IdClass; 033import jakarta.persistence.Index; 034import jakarta.persistence.JoinColumn; 035import jakarta.persistence.JoinColumns; 036import jakarta.persistence.ManyToOne; 037import jakarta.persistence.OneToMany; 038import jakarta.persistence.SequenceGenerator; 039import jakarta.persistence.Table; 040import org.apache.commons.lang3.builder.ToStringBuilder; 041import org.apache.commons.lang3.builder.ToStringStyle; 042 043import java.io.Serializable; 044import java.util.ArrayList; 045import java.util.List; 046 047import static org.apache.commons.lang3.StringUtils.length; 048 049@Entity 050@Table( 051 name = "TRM_CONCEPT_MAP_GROUP", 052 indexes = {@Index(name = "FK_TCMGROUP_CONCEPTMAP", columnList = "CONCEPT_MAP_PID")}) 053@IdClass(IdAndPartitionId.class) 054public class TermConceptMapGroup extends BasePartitionable implements Serializable { 055 private static final long serialVersionUID = 1L; 056 057 @Id() 058 @SequenceGenerator(name = "SEQ_CONCEPT_MAP_GROUP_PID", sequenceName = "SEQ_CONCEPT_MAP_GROUP_PID") 059 @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CONCEPT_MAP_GROUP_PID") 060 @Column(name = "PID") 061 private Long myId; 062 063 @ManyToOne() 064 @JoinColumns( 065 value = { 066 @JoinColumn( 067 name = "CONCEPT_MAP_PID", 068 insertable = true, 069 updatable = false, 070 nullable = false, 071 referencedColumnName = "PID"), 072 @JoinColumn( 073 name = "PARTITION_ID", 074 referencedColumnName = "PARTITION_ID", 075 insertable = true, 076 updatable = false, 077 nullable = false) 078 }, 079 foreignKey = @ForeignKey(name = "FK_TCMGROUP_CONCEPTMAP")) 080 private TermConceptMap myConceptMap; 081 082 @Column(name = "SOURCE_URL", nullable = false, length = TermCodeSystem.MAX_URL_LENGTH) 083 private String mySource; 084 085 @Column(name = "SOURCE_VERSION", nullable = true, length = TermCodeSystemVersion.MAX_VERSION_LENGTH) 086 private String mySourceVersion; 087 088 @Column(name = "TARGET_URL", nullable = false, length = TermCodeSystem.MAX_URL_LENGTH) 089 private String myTarget; 090 091 @Column(name = "TARGET_VERSION", nullable = true, length = TermCodeSystemVersion.MAX_VERSION_LENGTH) 092 private String myTargetVersion; 093 094 @OneToMany(mappedBy = "myConceptMapGroup") 095 private List<TermConceptMapGroupElement> myConceptMapGroupElements; 096 097 @Column(name = "CONCEPT_MAP_URL", nullable = true, length = TermConceptMap.MAX_URL_LENGTH) 098 private String myConceptMapUrl; 099 100 @Column(name = "SOURCE_VS", nullable = true, length = TermValueSet.MAX_URL_LENGTH) 101 private String mySourceValueSet; 102 103 @Column(name = "TARGET_VS", nullable = true, length = TermValueSet.MAX_URL_LENGTH) 104 private String myTargetValueSet; 105 106 public TermConceptMap getConceptMap() { 107 return myConceptMap; 108 } 109 110 public TermConceptMapGroup setConceptMap(TermConceptMap theTermConceptMap) { 111 myConceptMap = theTermConceptMap; 112 setPartitionId(theTermConceptMap.getPartitionId()); 113 return this; 114 } 115 116 public List<TermConceptMapGroupElement> getConceptMapGroupElements() { 117 if (myConceptMapGroupElements == null) { 118 myConceptMapGroupElements = new ArrayList<>(); 119 } 120 121 return myConceptMapGroupElements; 122 } 123 124 public String getConceptMapUrl() { 125 if (myConceptMapUrl == null) { 126 myConceptMapUrl = getConceptMap().getUrl(); 127 } 128 return myConceptMapUrl; 129 } 130 131 public Long getId() { 132 return myId; 133 } 134 135 public String getSource() { 136 return mySource; 137 } 138 139 public TermConceptMapGroup setSource(@Nonnull String theSource) { 140 ValidateUtil.isNotBlankOrThrowIllegalArgument(theSource, "theSource must not be null or empty"); 141 ValidateUtil.isNotTooLongOrThrowIllegalArgument( 142 theSource, 143 TermCodeSystem.MAX_URL_LENGTH, 144 "Source exceeds maximum length (" + TermCodeSystem.MAX_URL_LENGTH + "): " + length(theSource)); 145 this.mySource = theSource; 146 return this; 147 } 148 149 public String getSourceValueSet() { 150 if (mySourceValueSet == null) { 151 mySourceValueSet = getConceptMap().getSource(); 152 } 153 return mySourceValueSet; 154 } 155 156 public String getSourceVersion() { 157 return mySourceVersion; 158 } 159 160 public TermConceptMapGroup setSourceVersion(String theSourceVersion) { 161 ValidateUtil.isNotTooLongOrThrowIllegalArgument( 162 theSourceVersion, 163 TermCodeSystemVersion.MAX_VERSION_LENGTH, 164 "Source version ID exceeds maximum length (" + TermCodeSystemVersion.MAX_VERSION_LENGTH + "): " 165 + length(theSourceVersion)); 166 mySourceVersion = theSourceVersion; 167 return this; 168 } 169 170 public String getTarget() { 171 return myTarget; 172 } 173 174 public TermConceptMapGroup setTarget(@Nonnull String theTarget) { 175 ValidateUtil.isNotBlankOrThrowIllegalArgument(theTarget, "theTarget must not be null or empty"); 176 ValidateUtil.isNotTooLongOrThrowIllegalArgument( 177 theTarget, 178 TermCodeSystem.MAX_URL_LENGTH, 179 "Target exceeds maximum length (" + TermCodeSystem.MAX_URL_LENGTH + "): " + length(theTarget)); 180 this.myTarget = theTarget; 181 return this; 182 } 183 184 public String getTargetValueSet() { 185 if (myTargetValueSet == null) { 186 myTargetValueSet = getConceptMap().getTarget(); 187 } 188 return myTargetValueSet; 189 } 190 191 public String getTargetVersion() { 192 return myTargetVersion; 193 } 194 195 public TermConceptMapGroup setTargetVersion(String theTargetVersion) { 196 ValidateUtil.isNotTooLongOrThrowIllegalArgument( 197 theTargetVersion, 198 TermCodeSystemVersion.MAX_VERSION_LENGTH, 199 "Target version ID exceeds maximum length (" + TermCodeSystemVersion.MAX_VERSION_LENGTH + "): " 200 + length(theTargetVersion)); 201 myTargetVersion = theTargetVersion; 202 return this; 203 } 204 205 @Override 206 public String toString() { 207 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 208 .append("myId", myId) 209 .append(myConceptMap != null ? ("myConceptMap - id=" + myConceptMap.getId()) : ("myConceptMap=(null)")) 210 .append("mySource", mySource) 211 .append("mySourceVersion", mySourceVersion) 212 .append("myTarget", myTarget) 213 .append("myTargetVersion", myTargetVersion) 214 .append( 215 myConceptMapGroupElements != null 216 ? ("myConceptMapGroupElements - size=" + myConceptMapGroupElements.size()) 217 : ("myConceptMapGroupElements=(null)")) 218 .append("myConceptMapUrl", this.getConceptMapUrl()) 219 .append("mySourceValueSet", this.getSourceValueSet()) 220 .append("myTargetValueSet", this.getTargetValueSet()) 221 .toString(); 222 } 223}