View Javadoc
1   package ca.uhn.fhir.jpa.term;
2   
3   /*
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import org.apache.commons.lang3.Validate;
24  import org.hl7.fhir.r4.model.BooleanType;
25  import org.hl7.fhir.r4.model.CodeableConcept;
26  import org.hl7.fhir.r4.model.Coding;
27  import org.hl7.fhir.r4.model.UriType;
28  
29  import java.util.ArrayList;
30  import java.util.List;
31  
32  public class TranslationRequest {
33  	private CodeableConcept myCodeableConcept;
34  	private Long myResourceId;
35  	private BooleanType myReverse;
36  	private UriType mySource;
37  	private UriType myTarget;
38  	private UriType myTargetSystem;
39  
40  	public TranslationRequest() {
41  		super();
42  
43  		myCodeableConcept = new CodeableConcept();
44  	}
45  
46  	/**
47  	 * This is just a convenience method that creates a codeableconcept if one
48  	 * doesn't already exist, and adds a coding to it
49  	 */
50  	public TranslationRequest addCode(String theSystem, String theCode) {
51  		Validate.notBlank(theSystem, "theSystem must not be null");
52  		Validate.notBlank(theCode, "theCode must not be null");
53  		if (getCodeableConcept() == null) {
54  			setCodeableConcept(new CodeableConcept());
55  		}
56  		getCodeableConcept().addCoding(new Coding().setSystem(theSystem).setCode(theCode));
57  		return this;
58  	}
59  
60  	public CodeableConcept getCodeableConcept() {
61  		return myCodeableConcept;
62  	}
63  
64  	public TranslationRequest setCodeableConcept(CodeableConcept theCodeableConcept) {
65  		myCodeableConcept = theCodeableConcept;
66  		return this;
67  	}
68  
69  	public Long getResourceId() {
70  		return myResourceId;
71  	}
72  
73  	public void setResourceId(Long theResourceId) {
74  		myResourceId = theResourceId;
75  	}
76  
77  	public BooleanType getReverse() {
78  		return myReverse;
79  	}
80  
81  	public void setReverse(BooleanType theReverse) {
82  		myReverse = theReverse;
83  	}
84  
85  	public boolean getReverseAsBoolean() {
86  		if (hasReverse()) {
87  			return myReverse.booleanValue();
88  		}
89  
90  		return false;
91  	}
92  
93  	public UriType getSource() {
94  		return mySource;
95  	}
96  
97  	public TranslationRequest setSource(UriType theSource) {
98  		mySource = theSource;
99  		return this;
100 	}
101 
102 	public UriType getTarget() {
103 		return myTarget;
104 	}
105 
106 	public TranslationRequest setTarget(UriType theTarget) {
107 		myTarget = theTarget;
108 		return this;
109 	}
110 
111 	public UriType getTargetSystem() {
112 		return myTargetSystem;
113 	}
114 
115 	public TranslationRequest setTargetSystem(UriType theTargetSystem) {
116 		myTargetSystem = theTargetSystem;
117 		return this;
118 	}
119 
120 	public List<TranslationQuery> getTranslationQueries() {
121 		List<TranslationQuery> retVal = new ArrayList<>();
122 
123 		TranslationQuery translationQuery;
124 		for (Coding coding : getCodeableConcept().getCoding()) {
125 			translationQuery = new TranslationQuery();
126 
127 			translationQuery.setCoding(coding);
128 
129 			if (this.hasResourceId()) {
130 				translationQuery.setResourceId(this.getResourceId());
131 			}
132 
133 			if (this.hasSource()) {
134 				translationQuery.setSource(this.getSource());
135 			}
136 
137 			if (this.hasTarget()) {
138 				translationQuery.setTarget(this.getTarget());
139 			}
140 
141 			if (this.hasTargetSystem()) {
142 				translationQuery.setTargetSystem(this.getTargetSystem());
143 			}
144 
145 			retVal.add(translationQuery);
146 		}
147 
148 		return retVal;
149 	}
150 
151 	public boolean hasResourceId() {
152 		return myResourceId != null;
153 	}
154 
155 	public boolean hasReverse() {
156 		return myReverse != null;
157 	}
158 
159 	public boolean hasSource() {
160 		return mySource != null && mySource.hasValue();
161 	}
162 
163 	public boolean hasTarget() {
164 		return myTarget != null && myTarget.hasValue();
165 	}
166 
167 	public boolean hasTargetSystem() {
168 		return myTargetSystem != null && myTargetSystem.hasValue();
169 	}
170 
171 	public void setReverse(boolean theReverse) {
172 		myReverse = new BooleanType(theReverse);
173 	}
174 }