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