
001package ca.uhn.fhir.jpa.entity; 002 003/*- 004 * #%L 005 * HAPI FHIR JPA Server 006 * %% 007 * Copyright (C) 2014 - 2022 Smile CDR, Inc. 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import ca.uhn.fhir.util.ValidateUtil; 024import org.apache.commons.lang3.builder.EqualsBuilder; 025import org.apache.commons.lang3.builder.HashCodeBuilder; 026import org.apache.commons.lang3.builder.ToStringBuilder; 027import org.apache.commons.lang3.builder.ToStringStyle; 028import org.hl7.fhir.r4.model.Enumerations.ConceptMapEquivalence; 029 030import javax.annotation.Nonnull; 031import javax.persistence.*; 032import java.io.Serializable; 033 034import static org.apache.commons.lang3.StringUtils.length; 035 036@Entity 037@Table(name = "TRM_CONCEPT_MAP_GRP_ELM_TGT", indexes = { 038 @Index(name = "IDX_CNCPT_MP_GRP_ELM_TGT_CD", columnList = "TARGET_CODE") 039}) 040public class TermConceptMapGroupElementTarget implements Serializable { 041 private static final long serialVersionUID = 1L; 042 043 static final int MAX_EQUIVALENCE_LENGTH = 50; 044 045 @Id() 046 @SequenceGenerator(name = "SEQ_CNCPT_MAP_GRP_ELM_TGT_PID", sequenceName = "SEQ_CNCPT_MAP_GRP_ELM_TGT_PID") 047 @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CNCPT_MAP_GRP_ELM_TGT_PID") 048 @Column(name = "PID") 049 private Long myId; 050 051 @ManyToOne() 052 @JoinColumn(name = "CONCEPT_MAP_GRP_ELM_PID", nullable = false, referencedColumnName = "PID", foreignKey = @ForeignKey(name = "FK_TCMGETARGET_ELEMENT")) 053 private TermConceptMapGroupElement myConceptMapGroupElement; 054 055 @Column(name = "TARGET_CODE", nullable = false, length = TermConcept.MAX_CODE_LENGTH) 056 private String myCode; 057 058 @Column(name = "TARGET_DISPLAY", nullable = true, length = TermConcept.MAX_DISP_LENGTH) 059 private String myDisplay; 060 061 @Enumerated(EnumType.STRING) 062 @Column(name = "TARGET_EQUIVALENCE", nullable = true, length = MAX_EQUIVALENCE_LENGTH) 063 private ConceptMapEquivalence myEquivalence; 064 065 @Column(name = "CONCEPT_MAP_URL", nullable = true, length = TermConceptMap.MAX_URL_LENGTH) 066 private String myConceptMapUrl; 067 068 @Column(name = "SYSTEM_URL", nullable = true, length = TermCodeSystem.MAX_URL_LENGTH) 069 private String mySystem; 070 071 @Column(name = "SYSTEM_VERSION", nullable = true, length = TermCodeSystemVersion.MAX_VERSION_LENGTH) 072 private String mySystemVersion; 073 074 @Column(name = "VALUESET_URL", nullable = true, length = TermValueSet.MAX_URL_LENGTH) 075 private String myValueSet; 076 077 public String getCode() { 078 return myCode; 079 } 080 081 public TermConceptMapGroupElementTarget setCode(@Nonnull String theCode) { 082 ValidateUtil.isNotBlankOrThrowIllegalArgument(theCode, "theCode must not be null or empty"); 083 ValidateUtil.isNotTooLongOrThrowIllegalArgument(theCode, TermConcept.MAX_CODE_LENGTH, 084 "Code exceeds maximum length (" + TermConcept.MAX_CODE_LENGTH + "): " + length(theCode)); 085 myCode = theCode; 086 return this; 087 } 088 089 public TermConceptMapGroupElement getConceptMapGroupElement() { 090 return myConceptMapGroupElement; 091 } 092 093 public void setConceptMapGroupElement(TermConceptMapGroupElement theTermConceptMapGroupElement) { 094 myConceptMapGroupElement = theTermConceptMapGroupElement; 095 } 096 097 public String getConceptMapUrl() { 098 if (myConceptMapUrl == null) { 099 myConceptMapUrl = getConceptMapGroupElement().getConceptMapGroup().getConceptMap().getUrl(); 100 } 101 return myConceptMapUrl; 102 } 103 104 public String getDisplay() { 105 return myDisplay; 106 } 107 108 public TermConceptMapGroupElementTarget setDisplay(String theDisplay) { 109 myDisplay = theDisplay; 110 return this; 111 } 112 113 public ConceptMapEquivalence getEquivalence() { 114 return myEquivalence; 115 } 116 117 public TermConceptMapGroupElementTarget setEquivalence(ConceptMapEquivalence theEquivalence) { 118 myEquivalence = theEquivalence; 119 return this; 120 } 121 122 public Long getId() { 123 return myId; 124 } 125 126 public String getSystem() { 127 if (mySystem == null) { 128 mySystem = getConceptMapGroupElement().getConceptMapGroup().getTarget(); 129 } 130 return mySystem; 131 } 132 133 public String getSystemVersion() { 134 if (mySystemVersion == null) { 135 mySystemVersion = getConceptMapGroupElement().getConceptMapGroup().getTargetVersion(); 136 } 137 return mySystemVersion; 138 } 139 140 public String getValueSet() { 141 if (myValueSet == null) { 142 myValueSet = getConceptMapGroupElement().getConceptMapGroup().getTargetValueSet(); 143 } 144 return myValueSet; 145 } 146 147 @Override 148 public boolean equals(Object o) { 149 if (this == o) return true; 150 151 if (!(o instanceof TermConceptMapGroupElementTarget)) return false; 152 153 TermConceptMapGroupElementTarget that = (TermConceptMapGroupElementTarget) o; 154 155 return new EqualsBuilder() 156 .append(getCode(), that.getCode()) 157 .append(getEquivalence(), that.getEquivalence()) 158 .append(getSystem(), that.getSystem()) 159 .append(getSystemVersion(), that.getSystemVersion()) 160 .isEquals(); 161 } 162 163 @Override 164 public int hashCode() { 165 return new HashCodeBuilder(17, 37) 166 .append(getCode()) 167 .append(getEquivalence()) 168 .append(getSystem()) 169 .append(getSystemVersion()) 170 .toHashCode(); 171 } 172 173 @Override 174 public String toString() { 175 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) 176 .append("myId", myId) 177 .append(myConceptMapGroupElement != null ? ("myConceptMapGroupElement - id=" + myConceptMapGroupElement.getId()) : ("myConceptMapGroupElement=(null)")) 178 .append("myCode", myCode) 179 .append("myDisplay", myDisplay) 180 .append("myEquivalence", myEquivalence.toCode()) 181 .append("myConceptMapUrl", this.getConceptMapUrl()) 182 .append("mySystem", this.getSystem()) 183 .append("mySystemVersion", this.getSystemVersion()) 184 .append("myValueSet", this.getValueSet()) 185 .toString(); 186 } 187}