001package ca.uhn.fhir.jpa.api.model;
002
003/*-
004 * #%L
005 * HAPI FHIR Storage api
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 org.apache.commons.lang3.Validate;
024import org.hl7.fhir.r4.model.BooleanType;
025import org.hl7.fhir.r4.model.CodeableConcept;
026import org.hl7.fhir.r4.model.Coding;
027import org.hl7.fhir.r4.model.StringType;
028import org.hl7.fhir.r4.model.UriType;
029
030import java.util.ArrayList;
031import java.util.List;
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 void setReverse(boolean theReverse) {
089                myReverse = new BooleanType(theReverse);
090        }
091
092        public boolean getReverseAsBoolean() {
093                if (hasReverse()) {
094                        return myReverse.booleanValue();
095                }
096
097                return false;
098        }
099
100        public UriType getUrl() {
101                return myUrl;
102        }
103
104        public TranslationRequest setUrl(UriType theUrl) {
105                myUrl = theUrl;
106                return this;
107        }
108
109        public StringType getConceptMapVersion() {
110                return myConceptMapVersion;
111        }
112
113        public TranslationRequest setConceptMapVersion(StringType theConceptMapVersion) {
114                myConceptMapVersion = theConceptMapVersion;
115                return this;
116        }
117
118        public UriType getSource() {
119                return mySource;
120        }
121
122        public TranslationRequest setSource(UriType theSource) {
123                mySource = theSource;
124                return this;
125        }
126
127        public UriType getTarget() {
128                return myTarget;
129        }
130
131        public TranslationRequest setTarget(UriType theTarget) {
132                myTarget = theTarget;
133                return this;
134        }
135
136        public UriType getTargetSystem() {
137                return myTargetSystem;
138        }
139
140        public TranslationRequest setTargetSystem(UriType theTargetSystem) {
141                myTargetSystem = theTargetSystem;
142                return this;
143        }
144
145        public List<TranslationQuery> getTranslationQueries() {
146                List<TranslationQuery> retVal = new ArrayList<>();
147
148                TranslationQuery translationQuery;
149                for (Coding coding : getCodeableConcept().getCoding()) {
150                        translationQuery = new TranslationQuery();
151
152                        translationQuery.setCoding(coding);
153
154                        if (this.hasResourceId()) {
155                                translationQuery.setResourceId(this.getResourceId());
156                        }
157
158                        if (this.hasUrl()) {
159                                translationQuery.setUrl(this.getUrl());
160                        }
161
162                        if (this.hasConceptMapVersion()) {
163                                translationQuery.setConceptMapVersion(this.getConceptMapVersion());
164                        }
165
166                        if (this.hasSource()) {
167                                translationQuery.setSource(this.getSource());
168                        }
169
170                        if (this.hasTarget()) {
171                                translationQuery.setTarget(this.getTarget());
172                        }
173
174                        if (this.hasTargetSystem()) {
175                                translationQuery.setTargetSystem(this.getTargetSystem());
176                        }
177
178                        retVal.add(translationQuery);
179                }
180
181                return retVal;
182        }
183
184        public boolean hasResourceId() {
185                return myResourceId != null;
186        }
187
188        public boolean hasReverse() {
189                return myReverse != null;
190        }
191
192        public boolean hasUrl() {
193                return myUrl != null && myUrl.hasValue();
194        }
195
196        public boolean hasConceptMapVersion() {
197                return myConceptMapVersion != null && myConceptMapVersion.hasValue();
198        }
199
200        public boolean hasSource() {
201                return mySource != null && mySource.hasValue();
202        }
203
204        public boolean hasTarget() {
205                return myTarget != null && myTarget.hasValue();
206        }
207
208        public boolean hasTargetSystem() {
209                return myTargetSystem != null && myTargetSystem.hasValue();
210        }
211}