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.EqualsBuilder; 026import org.apache.commons.lang3.builder.HashCodeBuilder; 027import org.apache.commons.lang3.builder.ToStringBuilder; 028import org.apache.commons.lang3.builder.ToStringStyle; 029 030import java.io.Serializable; 031import java.util.ArrayList; 032import java.util.List; 033 034import static org.apache.commons.lang3.StringUtils.left; 035import static org.apache.commons.lang3.StringUtils.length; 036 037@Entity 038@Table( 039 name = "TRM_CONCEPT_MAP_GRP_ELEMENT", 040 indexes = { 041 @Index(name = "IDX_CNCPT_MAP_GRP_CD", columnList = "SOURCE_CODE"), 042 @Index(name = "FK_TCMGELEMENT_GROUP", columnList = "CONCEPT_MAP_GROUP_PID") 043 }) 044public class TermConceptMapGroupElement implements Serializable { 045 private static final long serialVersionUID = 1L; 046 047 @Id() 048 @SequenceGenerator(name = "SEQ_CONCEPT_MAP_GRP_ELM_PID", sequenceName = "SEQ_CONCEPT_MAP_GRP_ELM_PID") 049 @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CONCEPT_MAP_GRP_ELM_PID") 050 @Column(name = "PID") 051 private Long myId; 052 053 @ManyToOne() 054 @JoinColumn( 055 name = "CONCEPT_MAP_GROUP_PID", 056 nullable = false, 057 referencedColumnName = "PID", 058 foreignKey = @ForeignKey(name = "FK_TCMGELEMENT_GROUP")) 059 private TermConceptMapGroup myConceptMapGroup; 060 061 @Column(name = "SOURCE_CODE", nullable = false, length = TermConcept.MAX_CODE_LENGTH) 062 private String myCode; 063 064 @Column(name = "SOURCE_DISPLAY", length = TermConcept.MAX_DISP_LENGTH) 065 private String myDisplay; 066 067 @OneToMany(mappedBy = "myConceptMapGroupElement") 068 private List<TermConceptMapGroupElementTarget> myConceptMapGroupElementTargets; 069 070 @Column(name = "CONCEPT_MAP_URL", nullable = true, length = TermConceptMap.MAX_URL_LENGTH) 071 private String myConceptMapUrl; 072 073 @Column(name = "SYSTEM_URL", nullable = true, length = TermCodeSystem.MAX_URL_LENGTH) 074 private String mySystem; 075 076 @Column(name = "SYSTEM_VERSION", nullable = true, length = TermCodeSystemVersion.MAX_VERSION_LENGTH) 077 private String mySystemVersion; 078 079 @Column(name = "VALUESET_URL", nullable = true, length = TermValueSet.MAX_URL_LENGTH) 080 private String myValueSet; 081 082 public String getCode() { 083 return myCode; 084 } 085 086 public TermConceptMapGroupElement setCode(@Nonnull String theCode) { 087 ValidateUtil.isNotBlankOrThrowIllegalArgument(theCode, "theCode must not be null or empty"); 088 ValidateUtil.isNotTooLongOrThrowIllegalArgument( 089 theCode, 090 TermConcept.MAX_CODE_LENGTH, 091 "Code exceeds maximum length (" + TermConcept.MAX_CODE_LENGTH + "): " + length(theCode)); 092 myCode = theCode; 093 return this; 094 } 095 096 public TermConceptMapGroup getConceptMapGroup() { 097 return myConceptMapGroup; 098 } 099 100 public TermConceptMapGroupElement setConceptMapGroup(TermConceptMapGroup theTermConceptMapGroup) { 101 myConceptMapGroup = theTermConceptMapGroup; 102 return this; 103 } 104 105 public List<TermConceptMapGroupElementTarget> getConceptMapGroupElementTargets() { 106 if (myConceptMapGroupElementTargets == null) { 107 myConceptMapGroupElementTargets = new ArrayList<>(); 108 } 109 110 return myConceptMapGroupElementTargets; 111 } 112 113 public String getConceptMapUrl() { 114 if (myConceptMapUrl == null) { 115 myConceptMapUrl = getConceptMapGroup().getConceptMap().getUrl(); 116 } 117 return myConceptMapUrl; 118 } 119 120 public String getDisplay() { 121 return myDisplay; 122 } 123 124 public TermConceptMapGroupElement setDisplay(String theDisplay) { 125 myDisplay = left(theDisplay, TermConcept.MAX_DISP_LENGTH); 126 return this; 127 } 128 129 public Long getId() { 130 return myId; 131 } 132 133 public String getSystem() { 134 if (mySystem == null) { 135 mySystem = getConceptMapGroup().getSource(); 136 } 137 return mySystem; 138 } 139 140 public String getSystemVersion() { 141 if (mySystemVersion == null) { 142 mySystemVersion = getConceptMapGroup().getSourceVersion(); 143 } 144 return mySystemVersion; 145 } 146 147 public String getValueSet() { 148 if (myValueSet == null) { 149 myValueSet = getConceptMapGroup().getSourceValueSet(); 150 } 151 return myValueSet; 152 } 153 154 @Override 155 public boolean equals(Object o) { 156 if (this == o) return true; 157 158 if (!(o instanceof TermConceptMapGroupElement)) return false; 159 160 TermConceptMapGroupElement that = (TermConceptMapGroupElement) o; 161 162 return new EqualsBuilder() 163 .append(getCode(), that.getCode()) 164 .append(getSystem(), that.getSystem()) 165 .append(getSystemVersion(), that.getSystemVersion()) 166 .isEquals(); 167 } 168 169 @Override 170 public int hashCode() { 171 return new HashCodeBuilder(17, 37) 172 .append(getCode()) 173 .append(getSystem()) 174 .append(getSystemVersion()) 175 .toHashCode(); 176 } 177 178 @Override 179 public String toString() { 180 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 181 .append("myId", myId) 182 .append( 183 myConceptMapGroup != null 184 ? ("myConceptMapGroup - id=" + myConceptMapGroup.getId()) 185 : ("myConceptMapGroup=(null)")) 186 .append("myCode", myCode) 187 .append("myDisplay", myDisplay) 188 .append( 189 myConceptMapGroupElementTargets != null 190 ? ("myConceptMapGroupElementTargets - size=" + myConceptMapGroupElementTargets.size()) 191 : ("myConceptMapGroupElementTargets=(null)")) 192 .append("myConceptMapUrl", this.getConceptMapUrl()) 193 .append("mySystem", this.getSystem()) 194 .append("mySystemVersion", this.getSystemVersion()) 195 .append("myValueSet", this.getValueSet()) 196 .toString(); 197 } 198}