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