001package ca.uhn.fhir.jpa.api.model;
002
003import java.util.ArrayList;
004import java.util.List;
005
006/*
007 * #%L
008 * HAPI FHIR JPA API
009 * %%
010 * Copyright (C) 2014 - 2021 Smile CDR, Inc.
011 * %%
012 * Licensed under the Apache License, Version 2.0 (the "License");
013 * you may not use this file except in compliance with the License.
014 * You may obtain a copy of the License at
015 *
016 *      http://www.apache.org/licenses/LICENSE-2.0
017 *
018 * Unless required by applicable law or agreed to in writing, software
019 * distributed under the License is distributed on an "AS IS" BASIS,
020 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
021 * See the License for the specific language governing permissions and
022 * limitations under the License.
023 * #L%
024 */
025
026import org.apache.commons.lang3.Validate;
027import org.hl7.fhir.r4.model.BooleanType;
028import org.hl7.fhir.r4.model.CodeableConcept;
029import org.hl7.fhir.r4.model.Coding;
030import org.hl7.fhir.r4.model.StringType;
031import org.hl7.fhir.r4.model.UriType;
032
033public class TranslationRequest {
034        private CodeableConcept myCodeableConcept;
035        private Long myResourceId;
036        private BooleanType myReverse;
037        private UriType myUrl;
038        private StringType myConceptMapVersion;
039        private UriType mySource;
040        private UriType myTarget;
041        private UriType myTargetSystem;
042
043        public TranslationRequest() {
044                super();
045
046                myCodeableConcept = new CodeableConcept();
047        }
048
049        /**
050         * This is just a convenience method that creates a codeableconcept if one
051         * doesn't already exist, and adds a coding to it
052         */
053        public TranslationRequest addCode(String theSystem, String theCode) {
054                Validate.notBlank(theSystem, "theSystem must not be null");
055                Validate.notBlank(theCode, "theCode must not be null");
056                if (getCodeableConcept() == null) {
057                        setCodeableConcept(new CodeableConcept());
058                }
059                getCodeableConcept().addCoding(new Coding().setSystem(theSystem).setCode(theCode));
060                return this;
061        }
062
063        public CodeableConcept getCodeableConcept() {
064                return myCodeableConcept;
065        }
066
067        public TranslationRequest setCodeableConcept(CodeableConcept theCodeableConcept) {
068                myCodeableConcept = theCodeableConcept;
069                return this;
070        }
071
072        public Long getResourceId() {
073                return myResourceId;
074        }
075
076        public void setResourceId(Long theResourceId) {
077                myResourceId = theResourceId;
078        }
079
080        public BooleanType getReverse() {
081                return myReverse;
082        }
083
084        public void setReverse(BooleanType theReverse) {
085                myReverse = theReverse;
086        }
087
088        public boolean getReverseAsBoolean() {
089                if (hasReverse()) {
090                        return myReverse.booleanValue();
091                }
092
093                return false;
094        }
095
096        public UriType getUrl() {
097                return myUrl;
098        }
099
100        public TranslationRequest setUrl(UriType theUrl) {
101                myUrl = theUrl;
102                return this;
103        }
104        
105        public StringType getConceptMapVersion() {
106                return myConceptMapVersion;
107        }
108
109        public TranslationRequest setConceptMapVersion(StringType theConceptMapVersion) {
110                myConceptMapVersion = theConceptMapVersion;
111                return this;
112        }
113        
114        public UriType getSource() {
115                return mySource;
116        }
117
118        public TranslationRequest setSource(UriType theSource) {
119                mySource = theSource;
120                return this;
121        }
122
123        public UriType getTarget() {
124                return myTarget;
125        }
126
127        public TranslationRequest setTarget(UriType theTarget) {
128                myTarget = theTarget;
129                return this;
130        }
131
132        public UriType getTargetSystem() {
133                return myTargetSystem;
134        }
135
136        public TranslationRequest setTargetSystem(UriType theTargetSystem) {
137                myTargetSystem = theTargetSystem;
138                return this;
139        }
140
141        public List<TranslationQuery> getTranslationQueries() {
142                List<TranslationQuery> retVal = new ArrayList<>();
143
144                TranslationQuery translationQuery;
145                for (Coding coding : getCodeableConcept().getCoding()) {
146                        translationQuery = new TranslationQuery();
147
148                        translationQuery.setCoding(coding);
149
150                        if (this.hasResourceId()) {
151                                translationQuery.setResourceId(this.getResourceId());
152                        }
153
154                        if (this.hasUrl()) {
155                                translationQuery.setUrl(this.getUrl());
156                        }
157                        
158                        if (this.hasConceptMapVersion()) {
159                                translationQuery.setConceptMapVersion(this.getConceptMapVersion());
160                        }
161                        
162                        if (this.hasSource()) {
163                                translationQuery.setSource(this.getSource());
164                        }
165
166                        if (this.hasTarget()) {
167                                translationQuery.setTarget(this.getTarget());
168                        }
169
170                        if (this.hasTargetSystem()) {
171                                translationQuery.setTargetSystem(this.getTargetSystem());
172                        }
173
174                        retVal.add(translationQuery);
175                }
176
177                return retVal;
178        }
179
180        public boolean hasResourceId() {
181                return myResourceId != null;
182        }
183
184        public boolean hasReverse() {
185                return myReverse != null;
186        }
187
188        public boolean hasUrl() {
189                return myUrl != null && myUrl.hasValue();
190        }
191
192        public boolean hasConceptMapVersion() {
193                return myConceptMapVersion != null && myConceptMapVersion.hasValue();
194        }
195
196        public boolean hasSource() {
197                return mySource != null && mySource.hasValue();
198        }
199
200        public boolean hasTarget() {
201                return myTarget != null && myTarget.hasValue();
202        }
203
204        public boolean hasTargetSystem() {
205                return myTargetSystem != null && myTargetSystem.hasValue();
206        }
207
208        public void setReverse(boolean theReverse) {
209                myReverse = new BooleanType(theReverse);
210        }
211}