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