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