public abstract class BaseParser extends Object implements IParser
| Modifier and Type | Class and Description |
|---|---|
protected class |
BaseParser.CompositeChildElement |
| Constructor and Description |
|---|
BaseParser(FhirContext theContext,
IParserErrorHandler theParserErrorHandler)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
protected Iterable<BaseParser.CompositeChildElement> |
compositeChildIterator(IBase theCompositeElement,
boolean theContainedResource,
boolean theSubResource,
BaseParser.CompositeChildElement theParent) |
protected void |
containResourcesForEncoding(IBaseResource theResource) |
protected abstract void |
doEncodeResourceToWriter(IBaseResource theResource,
Writer theWriter) |
protected abstract <T extends IBaseResource> |
doParseResource(Class<T> theResourceType,
Reader theReader) |
String |
encodeResourceToString(IBaseResource theResource) |
void |
encodeResourceToWriter(IBaseResource theResource,
Writer theWriter) |
protected static <T> List<T> |
extractMetadataListNotNull(IResource resource,
ResourceMetadataKeyEnum<List<T>> key) |
protected IIdType |
fixContainedResourceId(String theValue) |
protected String |
getCompositeElementId(IBase theElement) |
Set<String> |
getDontStripVersionsFromReferencesAtPaths()
Returns the value supplied to
IParser.setDontStripVersionsFromReferencesAtPaths(String...)
or null if no value has been set for this parser (in which case the default from
the ParserOptions will be used} |
Set<String> |
getEncodeElements()
|
Set<String> |
getEncodeElementsAppliesToResourceTypes()
|
IIdType |
getEncodeForceResourceId()
If not set to null (as is the default) this ID will be used as the ID in any
resources encoded by this parser
|
protected IParserErrorHandler |
getErrorHandler() |
protected String |
getExtensionUrl(String extensionUrl) |
protected TagList |
getMetaTagsForEncoding(IResource theIResource) |
Boolean |
getOverrideResourceIdWithBundleEntryFullUrl()
If set to
true (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource's
resource id if the fullUrl is defined. |
List<Class<? extends IBaseResource>> |
getPreferTypes()
Gets the preferred types, as set using
IParser.setPreferTypes(List) |
protected <T extends IPrimitiveType<String>> |
getProfileTagsForEncoding(IBaseResource theResource,
List<T> theProfiles) |
protected String |
getServerBaseUrl() |
Boolean |
getStripVersionsFromReferences()
If set to
true |
boolean |
getSuppressNarratives()
Deprecated.
|
protected boolean |
isChildContained(BaseRuntimeElementDefinition<?> childDef,
boolean theIncludedResource) |
boolean |
isOmitResourceId()
Returns true if resource IDs should be omitted
|
boolean |
isSummaryMode()
Is the parser in "summary mode"? See
IParser.setSummaryMode(boolean) for information |
boolean |
isSuppressNarratives()
If set to
true (default is false), narratives will not be included in the encoded
values. |
<T extends IBaseResource> |
parseResource(Class<T> theResourceType,
Reader theReader)
Parses a resource
|
<T extends IBaseResource> |
parseResource(Class<T> theResourceType,
String theMessageString)
Parses a resource
|
IBaseResource |
parseResource(Reader theReader)
Parses a resource
|
IBaseResource |
parseResource(String theMessageString)
Parses a resource
|
protected List<? extends IBase> |
preProcessValues(BaseRuntimeChildDefinition theMetaChildUncast,
IBaseResource theResource,
List<? extends IBase> theValues,
BaseParser.CompositeChildElement theCompositeChildElement) |
void |
setDontEncodeElements(Set<String> theDontEncodeElements)
If provided, specifies the elements which should NOT be encoded.
|
IParser |
setDontStripVersionsFromReferencesAtPaths(Collection<String> thePaths)
If supplied value(s), any resource references at the specified paths will have their
resource versions encoded instead of being automatically stripped during the encoding
process.
|
IParser |
setDontStripVersionsFromReferencesAtPaths(String... thePaths)
If supplied value(s), any resource references at the specified paths will have their
resource versions encoded instead of being automatically stripped during the encoding
process.
|
void |
setEncodeElements(Set<String> theEncodeElements)
If provided, specifies the elements which should be encoded, to the exclusion of all others.
|
void |
setEncodeElementsAppliesToResourceTypes(Set<String> theEncodeElementsAppliesToResourceTypes)
If provided, tells the parse which resource types to apply
encode elements to. |
BaseParser |
setEncodeForceResourceId(IIdType theEncodeForceResourceId)
When encoding, force this resource ID to be encoded as the resource ID
|
IParser |
setOmitResourceId(boolean theOmitResourceId)
If set to
true (default is false) the ID of any resources being encoded will not be
included in the output. |
IParser |
setOverrideResourceIdWithBundleEntryFullUrl(Boolean theOverrideResourceIdWithBundleEntryFullUrl)
If set to
true (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource's
resource id if the fullUrl is defined. |
IParser |
setParserErrorHandler(IParserErrorHandler theErrorHandler)
Registers an error handler which will be invoked when any parse errors are found
|
void |
setPreferTypes(List<Class<? extends IBaseResource>> thePreferTypes)
If set, when parsing resources the parser will try to use the given types when possible, in
the order that they are provided (from highest to lowest priority).
|
IParser |
setServerBaseUrl(String theUrl)
Sets the server's base URL used by this parser.
|
IParser |
setStripVersionsFromReferences(Boolean theStripVersionsFromReferences)
If set to
true |
IParser |
setSummaryMode(boolean theSummaryMode)
If set to
true (default is false) only elements marked by the FHIR specification as
being "summary elements" will be included. |
IParser |
setSuppressNarratives(boolean theSuppressNarratives)
If set to
true (default is false), narratives will not be included in the encoded
values. |
protected boolean |
shouldAddSubsettedTag() |
protected boolean |
shouldEncodeResourceId(IBaseResource theResource,
boolean theSubResource) |
protected boolean |
shouldEncodeResourceMeta(IResource theResource)
Used for DSTU2 only
|
protected void |
throwExceptionForUnknownChildType(BaseRuntimeChildDefinition nextChild,
Class<? extends IBase> theType) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetEncoding, setPrettyPrintpublic BaseParser(FhirContext theContext, IParserErrorHandler theParserErrorHandler)
theParserErrorHandler - protected Iterable<BaseParser.CompositeChildElement> compositeChildIterator(IBase theCompositeElement, boolean theContainedResource, boolean theSubResource, BaseParser.CompositeChildElement theParent)
protected void containResourcesForEncoding(IBaseResource theResource)
protected abstract void doEncodeResourceToWriter(IBaseResource theResource, Writer theWriter) throws IOException, DataFormatException
IOExceptionDataFormatExceptionprotected abstract <T extends IBaseResource> T doParseResource(Class<T> theResourceType, Reader theReader) throws DataFormatException
DataFormatExceptionpublic String encodeResourceToString(IBaseResource theResource) throws DataFormatException
encodeResourceToString in interface IParserDataFormatExceptionpublic final void encodeResourceToWriter(IBaseResource theResource, Writer theWriter) throws IOException, DataFormatException
encodeResourceToWriter in interface IParserIOExceptionDataFormatExceptionprotected IIdType fixContainedResourceId(String theValue)
protected String getCompositeElementId(IBase theElement)
public Set<String> getDontStripVersionsFromReferencesAtPaths()
IParserIParser.setDontStripVersionsFromReferencesAtPaths(String...)
or null if no value has been set for this parser (in which case the default from
the ParserOptions will be used}getDontStripVersionsFromReferencesAtPaths in interface IParserIParser.setDontStripVersionsFromReferencesAtPaths(String...),
IParser.setStripVersionsFromReferences(Boolean),
ParserOptionspublic Set<String> getEncodeElements()
getEncodeElements in interface IParserpublic void setEncodeElements(Set<String> theEncodeElements)
IParsersetEncodeElements in interface IParsertheEncodeElements - The elements to encodeIParser.setDontEncodeElements(Set)public Set<String> getEncodeElementsAppliesToResourceTypes()
getEncodeElementsAppliesToResourceTypes in interface IParserpublic void setEncodeElementsAppliesToResourceTypes(Set<String> theEncodeElementsAppliesToResourceTypes)
IParserencode elements to. Any
resource types not specified here will be encoded completely, with no elements excluded.setEncodeElementsAppliesToResourceTypes in interface IParserpublic IIdType getEncodeForceResourceId()
IParsergetEncodeForceResourceId in interface IParserpublic BaseParser setEncodeForceResourceId(IIdType theEncodeForceResourceId)
IParsersetEncodeForceResourceId in interface IParserprotected IParserErrorHandler getErrorHandler()
protected String getExtensionUrl(String extensionUrl)
protected TagList getMetaTagsForEncoding(IResource theIResource)
public Boolean getOverrideResourceIdWithBundleEntryFullUrl()
IParsertrue (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource's
resource id if the fullUrl is defined. This behavior happens when parsing the source data into a Bundle object. Set this
to false if this is not the desired behavior (e.g. the client code wishes to perform additional
validation checks between the fullUrl and the resource id).getOverrideResourceIdWithBundleEntryFullUrl in interface IParsernull if no value is set, in
which case the value from the ParserOptions will be used (default is true)ParserOptionspublic List<Class<? extends IBaseResource>> getPreferTypes()
IParserIParser.setPreferTypes(List)getPreferTypes in interface IParsernullIParser.setPreferTypes(List)public void setPreferTypes(List<Class<? extends IBaseResource>> thePreferTypes)
IParser
This feature is related to, but not the same as the
FhirContext.setDefaultTypeForProfile(String, Class) feature.
setDefaultTypeForProfile is used to specify a type to be used
when a resource explicitly declares support for a given profile. This
feature specifies a type to be used irrespective of the profile declaration
in the metadata statement.
setPreferTypes in interface IParserthePreferTypes - The preferred types, or nullprotected <T extends IPrimitiveType<String>> List<T> getProfileTagsForEncoding(IBaseResource theResource, List<T> theProfiles)
protected String getServerBaseUrl()
public Boolean getStripVersionsFromReferences()
IParsertrue (which is the default), resource references containing a version
will have the version removed when the resource is encoded. This is generally good behaviour because
in most situations, references from one resource to another should be to the resource by ID, not
by ID and version. In some cases though, it may be desirable to preserve the version in resource
links. In that case, this value should be set to false.getStripVersionsFromReferences in interface IParsernull if no value is set, in which case
the value from the ParserOptions will be used (default is true)ParserOptions@Deprecated public boolean getSuppressNarratives()
isSuppressNarratives()true (default is false), narratives will not be included in the encoded
values.protected boolean isChildContained(BaseRuntimeElementDefinition<?> childDef, boolean theIncludedResource)
public boolean isOmitResourceId()
IParserisOmitResourceId in interface IParserIParser.setOmitResourceId(boolean)public boolean isSummaryMode()
IParserIParser.setSummaryMode(boolean) for informationisSummaryMode in interface IParser#setSummaryMode(boolean)} for informationpublic boolean isSuppressNarratives()
true (default is false), narratives will not be included in the encoded
values.public <T extends IBaseResource> T parseResource(Class<T> theResourceType, Reader theReader) throws DataFormatException
IParserparseResource in interface IParsertheResourceType - The resource type to use. This can be used to explicitly specify a class which extends a built-in type
(e.g. a custom type extending the default Patient class)theReader - The reader to parse input from. Note that the Reader will not be closed by the parser upon completion.DataFormatException - If the resource can not be parsed because the data is not recognized or invalid for any reasonpublic <T extends IBaseResource> T parseResource(Class<T> theResourceType, String theMessageString)
IParserparseResource in interface IParsertheResourceType - The resource type to use. This can be used to explicitly specify a class which extends a built-in type
(e.g. a custom type extending the default Patient class)theMessageString - The string to parsepublic IBaseResource parseResource(Reader theReader) throws ConfigurationException, DataFormatException
IParserparseResource in interface IParsertheReader - The reader to parse input from. Note that the Reader will not be closed by the parser upon completion.IResource or
IAnyResource depending on the specific FhirContext which created this parser.DataFormatException - If the resource can not be parsed because the data is not recognized or invalid for any reasonConfigurationExceptionpublic IBaseResource parseResource(String theMessageString) throws ConfigurationException, DataFormatException
IParserparseResource in interface IParsertheMessageString - The string to parseIResource or
IAnyResource depending on the specific FhirContext which created this parser.DataFormatException - If the resource can not be parsed because the data is not recognized or invalid for any reasonConfigurationExceptionprotected List<? extends IBase> preProcessValues(BaseRuntimeChildDefinition theMetaChildUncast, IBaseResource theResource, List<? extends IBase> theValues, BaseParser.CompositeChildElement theCompositeChildElement)
public void setDontEncodeElements(Set<String> theDontEncodeElements)
IParser
DSTU2 note: Note that values including meta, such as Patient.meta
will work for DSTU2 parsers, but values with subelements on meta such
as Patient.meta.lastUpdated will only work in
DSTU3+ mode.
setDontEncodeElements in interface IParsertheDontEncodeElements - The elements to encodeIParser.setEncodeElements(Set)public IParser setDontStripVersionsFromReferencesAtPaths(String... thePaths)
IParser
This method provides a finer-grained level of control than IParser.setStripVersionsFromReferences(Boolean)
and any paths specified by this method will be encoded even if IParser.setStripVersionsFromReferences(Boolean)
has been set to true (which is the default)
setDontStripVersionsFromReferencesAtPaths in interface IParserthePaths - A collection of paths for which the resource versions will not be removed automatically
when serializing, e.g. "Patient.managingOrganization" or "AuditEvent.object.reference". Note that
only resource name and field names with dots separating is allowed here (no repetition
indicators, FluentPath expressions, etc.). Set to null to use the value
set in the ParserOptionsthis parser so that method calls can be chained togetherIParser.setStripVersionsFromReferences(Boolean),
ParserOptionspublic IParser setDontStripVersionsFromReferencesAtPaths(Collection<String> thePaths)
IParser
This method provides a finer-grained level of control than IParser.setStripVersionsFromReferences(Boolean)
and any paths specified by this method will be encoded even if IParser.setStripVersionsFromReferences(Boolean)
has been set to true (which is the default)
setDontStripVersionsFromReferencesAtPaths in interface IParserthePaths - A collection of paths for which the resource versions will not be removed automatically
when serializing, e.g. "Patient.managingOrganization" or "AuditEvent.object.reference". Note that
only resource name and field names with dots separating is allowed here (no repetition
indicators, FluentPath expressions, etc.). Set to null to use the value
set in the ParserOptionsthis parser so that method calls can be chained togetherIParser.setStripVersionsFromReferences(Boolean),
ParserOptionspublic IParser setOmitResourceId(boolean theOmitResourceId)
IParsertrue (default is false) the ID of any resources being encoded will not be
included in the output. Note that this does not apply to contained resources, only to root resources. In other
words, if this is set to true, contained resources will still have local IDs but the outer/containing
ID will not have an ID.setOmitResourceId in interface IParsertheOmitResourceId - Should resource IDs be omittedthis parser so that method calls can be chained togetherpublic IParser setOverrideResourceIdWithBundleEntryFullUrl(Boolean theOverrideResourceIdWithBundleEntryFullUrl)
IParsertrue (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource's
resource id if the fullUrl is defined. This behavior happens when parsing the source data into a Bundle object. Set this
to false if this is not the desired behavior (e.g. the client code wishes to perform additional
validation checks between the fullUrl and the resource id).setOverrideResourceIdWithBundleEntryFullUrl in interface IParsertheOverrideResourceIdWithBundleEntryFullUrl - Set this to false to prevent the parser from overriding resource ids with the
Bundle.entry.fullUrl (or null to apply the default setting from the ParserOptions)this parser so that method calls can be chained togetherParserOptionspublic IParser setParserErrorHandler(IParserErrorHandler theErrorHandler)
IParsersetParserErrorHandler in interface IParsertheErrorHandler - The error handler to set. Must not be null.public IParser setServerBaseUrl(String theUrl)
IParsersetServerBaseUrl in interface IParsertheUrl - The base URL, e.g. "http://example.com/base"this parser so that method calls can be chained togetherpublic IParser setStripVersionsFromReferences(Boolean theStripVersionsFromReferences)
IParsertrue (which is the default), resource references containing a version
will have the version removed when the resource is encoded. This is generally good behaviour because
in most situations, references from one resource to another should be to the resource by ID, not
by ID and version. In some cases though, it may be desirable to preserve the version in resource
links. In that case, this value should be set to false.
This method provides the ability to globally disable reference encoding. If finer-grained
control is needed, use IParser.setDontStripVersionsFromReferencesAtPaths(String...)
setStripVersionsFromReferences in interface IParsertheStripVersionsFromReferences - Set this to false to prevent the parser from removing resource versions from references (or null to apply the default setting from the ParserOptionsthis parser so that method calls can be chained togetherIParser.setDontStripVersionsFromReferencesAtPaths(String...),
ParserOptionspublic IParser setSummaryMode(boolean theSummaryMode)
IParsertrue (default is false) only elements marked by the FHIR specification as
being "summary elements" will be included.setSummaryMode in interface IParserthis parser so that method calls can be chained togetherpublic IParser setSuppressNarratives(boolean theSuppressNarratives)
IParsertrue (default is false), narratives will not be included in the encoded
values.setSuppressNarratives in interface IParserprotected boolean shouldAddSubsettedTag()
protected boolean shouldEncodeResourceId(IBaseResource theResource, boolean theSubResource)
protected boolean shouldEncodeResourceMeta(IResource theResource)
protected void throwExceptionForUnknownChildType(BaseRuntimeChildDefinition nextChild, Class<? extends IBase> theType)
protected static <T> List<T> extractMetadataListNotNull(IResource resource, ResourceMetadataKeyEnum<List<T>> key)
Copyright © 2014–2017 University Health Network. All rights reserved.