001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.model.dataformat; 018 019import java.util.List; 020import java.util.Set; 021 022import javax.xml.bind.annotation.XmlAttribute; 023import javax.xml.bind.annotation.XmlTransient; 024 025import org.apache.camel.model.DataFormatDefinition; 026import org.apache.camel.spi.Metadata; 027 028public abstract class FhirDataformat extends DataFormatDefinition { 029 @XmlTransient 030 @Metadata(label = "advanced") 031 private Object fhirContext; 032 033 @XmlAttribute 034 @Metadata(enums = "DSTU2,DSTU2_HL7ORG,DSTU2_1,DSTU3,R4", defaultValue = "DSTU3") 035 private String fhirVersion; 036 037 @XmlAttribute 038 private Boolean prettyPrint; 039 040 @XmlTransient 041 @Metadata(label = "advanced") 042 private Object parserErrorHandler; 043 044 @XmlTransient 045 @Metadata(label = "advanced") 046 private Object parserOptions; 047 048 @XmlTransient 049 @Metadata(label = "advanced") 050 private Object preferTypes; 051 052 @XmlTransient 053 @Metadata(label = "advanced") 054 private Object forceResourceId; 055 056 @XmlAttribute 057 @Metadata(label = "advanced") 058 private String serverBaseUrl; 059 060 @XmlAttribute 061 @Metadata(label = "advanced") 062 private Boolean omitResourceId; 063 064 @XmlAttribute 065 @Metadata(label = "advanced") 066 private Boolean encodeElementsAppliesToChildResourcesOnly; 067 068 @XmlAttribute 069 @Metadata(label = "advanced") 070 private Set<String> encodeElements; 071 072 @XmlAttribute 073 @Metadata(label = "advanced") 074 private Set<String> dontEncodeElements; 075 076 @XmlAttribute 077 @Metadata(label = "advanced") 078 private Boolean stripVersionsFromReferences; 079 080 @XmlAttribute 081 @Metadata(label = "advanced") 082 private Boolean overrideResourceIdWithBundleEntryFullUrl; 083 084 @XmlAttribute 085 @Metadata(label = "advanced") 086 private Boolean summaryMode; 087 088 @XmlAttribute 089 @Metadata(label = "advanced") 090 private Boolean suppressNarratives; 091 092 @XmlAttribute 093 @Metadata(label = "advanced") 094 private List<String> dontStripVersionsFromReferencesAtPaths; 095 096 protected FhirDataformat(String dataFormatName) { 097 super(dataFormatName); 098 } 099 100 protected FhirDataformat() { 101 // This constructor is needed by jaxb for schema generation 102 } 103 104 public Object getFhirContext() { 105 return fhirContext; 106 } 107 108 public void setFhirContext(Object fhirContext) { 109 this.fhirContext = fhirContext; 110 } 111 112 public String getFhirVersion() { 113 return fhirVersion; 114 } 115 116 /** 117 * The version of FHIR to use. Possible values are: 118 * DSTU2,DSTU2_HL7ORG,DSTU2_1,DSTU3,R4 119 */ 120 public void setFhirVersion(String fhirVersion) { 121 this.fhirVersion = fhirVersion; 122 } 123 124 public Boolean isPrettyPrint() { 125 return prettyPrint; 126 } 127 128 /** 129 * Sets the "pretty print" flag, meaning that the parser will encode 130 * resources with human-readable spacing and newlines between elements 131 * instead of condensing output as much as possible. 132 * 133 * @param prettyPrint The flag 134 */ 135 public void setPrettyPrint(Boolean prettyPrint) { 136 this.prettyPrint = prettyPrint; 137 } 138 139 public Object getParserErrorHandler() { 140 return parserErrorHandler; 141 } 142 143 /** 144 * Registers an error handler which will be invoked when any parse errors 145 * are found 146 * 147 * @param parserErrorHandler The error handler to set. Must not be null. 148 */ 149 public void setParserErrorHandler(Object parserErrorHandler) { 150 this.parserErrorHandler = parserErrorHandler; 151 } 152 153 public Object getParserOptions() { 154 return parserOptions; 155 } 156 157 /** 158 * Sets the parser options object which will be used to supply default 159 * options to newly created parsers. 160 * 161 * @param parserOptions The parser options object 162 */ 163 public void setParserOptions(Object parserOptions) { 164 this.parserOptions = parserOptions; 165 } 166 167 public Object getPreferTypes() { 168 return preferTypes; 169 } 170 171 /** 172 * If set, when parsing resources the parser will try to use the given types 173 * when possible, in the order that they are provided (from highest to 174 * lowest priority). For example, if a custom type which declares to 175 * implement the Patient resource is passed in here, and the parser is 176 * parsing a Bundle containing a Patient resource, the parser will use the 177 * given custom type. 178 * 179 * @param preferTypes The preferred types, or <code>null</code> 180 */ 181 public void setPreferTypes(Object preferTypes) { 182 this.preferTypes = preferTypes; 183 } 184 185 public Object getForceResourceId() { 186 return forceResourceId; 187 } 188 189 /** 190 * When encoding, force this resource ID to be encoded as the resource ID 191 */ 192 public void setForceResourceId(Object forceResourceId) { 193 this.forceResourceId = forceResourceId; 194 } 195 196 public String getServerBaseUrl() { 197 return serverBaseUrl; 198 } 199 200 /** 201 * Sets the server's base URL used by this parser. If a value is set, 202 * resource references will be turned into relative references if they are 203 * provided as absolute URLs but have a base matching the given base. 204 * 205 * @param serverBaseUrl The base URL, e.g. "http://example.com/base" 206 */ 207 public void setServerBaseUrl(String serverBaseUrl) { 208 this.serverBaseUrl = serverBaseUrl; 209 } 210 211 public Boolean isOmitResourceId() { 212 return omitResourceId; 213 } 214 215 /** 216 * If set to <code>true</code> (default is <code>false</code>) the ID of any 217 * resources being encoded will not be included in the output. Note that 218 * this does not apply to contained resources, only to root resources. In 219 * other words, if this is set to <code>true</code>, contained resources 220 * will still have local IDs but the outer/containing ID will not have an 221 * ID. 222 * 223 * @param omitResourceId Should resource IDs be omitted 224 */ 225 public void setOmitResourceId(Boolean omitResourceId) { 226 this.omitResourceId = omitResourceId; 227 } 228 229 public Boolean isEncodeElementsAppliesToChildResourcesOnly() { 230 return encodeElementsAppliesToChildResourcesOnly; 231 } 232 233 /** 234 * If set to <code>true</code> (default is false), the values supplied to 235 * {@link #setEncodeElements(Set)} will not be applied to the root resource 236 * (typically a Bundle), but will be applied to any sub-resources contained 237 * within it (i.e. search result resources in that bundle) 238 */ 239 public void setEncodeElementsAppliesToChildResourcesOnly(Boolean encodeElementsAppliesToChildResourcesOnly) { 240 this.encodeElementsAppliesToChildResourcesOnly = encodeElementsAppliesToChildResourcesOnly; 241 } 242 243 public Set<String> getEncodeElements() { 244 return encodeElements; 245 } 246 247 /** 248 * If provided, specifies the elements which should be encoded, to the 249 * exclusion of all others. Valid values for this field would include: 250 * <ul> 251 * <li><b>Patient</b> - Encode patient and all its children</li> 252 * <li><b>Patient.name</b> - Encode only the patient's name</li> 253 * <li><b>Patient.name.family</b> - Encode only the patient's family 254 * name</li> 255 * <li><b>*.text</b> - Encode the text element on any resource (only the 256 * very first position may contain a wildcard)</li> 257 * <li><b>*.(mandatory)</b> - This is a special case which causes any 258 * mandatory fields (min > 0) to be encoded</li> 259 * </ul> 260 * 261 * @param encodeElements The elements to encode 262 * @see #setDontEncodeElements(Set) 263 */ 264 public void setEncodeElements(Set<String> encodeElements) { 265 this.encodeElements = encodeElements; 266 } 267 268 public Set<String> getDontEncodeElements() { 269 return dontEncodeElements; 270 } 271 272 /** 273 * If provided, specifies the elements which should NOT be encoded. Valid 274 * values for this field would include: 275 * <ul> 276 * <li><b>Patient</b> - Don't encode patient and all its children</li> 277 * <li><b>Patient.name</b> - Don't encode the patient's name</li> 278 * <li><b>Patient.name.family</b> - Don't encode the patient's family 279 * name</li> 280 * <li><b>*.text</b> - Don't encode the text element on any resource (only 281 * the very first position may contain a wildcard)</li> 282 * </ul> 283 * <p> 284 * DSTU2 note: Note that values including meta, such as 285 * <code>Patient.meta</code> will work for DSTU2 parsers, but values with 286 * subelements on meta such as <code>Patient.meta.lastUpdated</code> will 287 * only work in DSTU3+ mode. 288 * </p> 289 * 290 * @param dontEncodeElements The elements to encode 291 * @see #setEncodeElements(Set) 292 */ 293 public void setDontEncodeElements(Set<String> dontEncodeElements) { 294 this.dontEncodeElements = dontEncodeElements; 295 } 296 297 public Boolean getStripVersionsFromReferences() { 298 return stripVersionsFromReferences; 299 } 300 301 /** 302 * If set to 303 * <code>true<code> (which is the default), resource references containing a version 304 * will have the version removed when the resource is encoded. This is generally good behaviour because 305 * in most situations, references from one resource to another should be to the resource by ID, not 306 * by ID and version. In some cases though, it may be desirable to preserve the version in resource 307 * links. In that case, this value should be set to <code>false</code>. 308 * <p> 309 * This method provides the ability to globally disable reference encoding. 310 * If finer-grained control is needed, use 311 * {@link #setDontStripVersionsFromReferencesAtPaths(List)} 312 * </p> 313 * 314 * @param stripVersionsFromReferences Set this to 315 * <code>false<code> to prevent the parser from removing resource versions 316 * from references (or <code>null</code> 317 * to apply the default setting from the 318 * {@link #setParserOptions(Object)} 319 * @see #setDontStripVersionsFromReferencesAtPaths(List) 320 */ 321 public void setStripVersionsFromReferences(Boolean stripVersionsFromReferences) { 322 this.stripVersionsFromReferences = stripVersionsFromReferences; 323 } 324 325 public Boolean getOverrideResourceIdWithBundleEntryFullUrl() { 326 return overrideResourceIdWithBundleEntryFullUrl; 327 } 328 329 /** 330 * If set to <code>true</code> (which is the default), the 331 * Bundle.entry.fullUrl will override the Bundle.entry.resource's resource 332 * id if the fullUrl is defined. This behavior happens when parsing the 333 * source data into a Bundle object. Set this to <code>false</code> if this 334 * is not the desired behavior (e.g. the client code wishes to perform 335 * additional validation checks between the fullUrl and the resource id). 336 * 337 * @param overrideResourceIdWithBundleEntryFullUrl Set this to 338 * <code>false</code> to prevent the parser from overriding 339 * resource ids with the Bundle.entry.fullUrl (or 340 * <code>null</code> to apply the default setting from the 341 * {@link #setParserOptions(Object)}) 342 */ 343 public void setOverrideResourceIdWithBundleEntryFullUrl(Boolean overrideResourceIdWithBundleEntryFullUrl) { 344 this.overrideResourceIdWithBundleEntryFullUrl = overrideResourceIdWithBundleEntryFullUrl; 345 } 346 347 public Boolean isSummaryMode() { 348 return summaryMode; 349 } 350 351 /** 352 * If set to <code>true</code> (default is <code>false</code>) only elements 353 * marked by the FHIR specification as being "summary elements" will be 354 * included. 355 */ 356 public void setSummaryMode(Boolean summaryMode) { 357 this.summaryMode = summaryMode; 358 } 359 360 public Boolean isSuppressNarratives() { 361 return suppressNarratives; 362 } 363 364 /** 365 * If set to <code>true</code> (default is <code>false</code>), narratives 366 * will not be included in the encoded values. 367 */ 368 public void setSuppressNarratives(Boolean suppressNarratives) { 369 this.suppressNarratives = suppressNarratives; 370 } 371 372 public List<String> getDontStripVersionsFromReferencesAtPaths() { 373 return dontStripVersionsFromReferencesAtPaths; 374 } 375 376 /** 377 * If supplied value(s), any resource references at the specified paths will 378 * have their resource versions encoded instead of being automatically 379 * stripped during the encoding process. This setting has no effect on the 380 * parsing process. 381 * <p> 382 * This method provides a finer-grained level of control than 383 * {@link #setStripVersionsFromReferences(Boolean)} and any paths specified 384 * by this method will be encoded even if 385 * {@link #setStripVersionsFromReferences(Boolean)} has been set to 386 * <code>true</code> (which is the default) 387 * </p> 388 * 389 * @param dontStripVersionsFromReferencesAtPaths A collection of paths for 390 * which the resource versions will not be removed automatically 391 * when serializing, e.g. "Patient.managingOrganization" or 392 * "AuditEvent.object.reference". Note that only resource name 393 * and field names with dots separating is allowed here (no 394 * repetition indicators, FluentPath expressions, etc.). Set to 395 * <code>null</code> to use the value set in the 396 * {@link #setParserOptions(Object)} 397 * @see #setStripVersionsFromReferences(Boolean) 398 */ 399 public void setDontStripVersionsFromReferencesAtPaths(List<String> dontStripVersionsFromReferencesAtPaths) { 400 this.dontStripVersionsFromReferencesAtPaths = dontStripVersionsFromReferencesAtPaths; 401 } 402 403}