Class FHIRPersistenceSupport
- java.lang.Object
-
- org.linuxforhealth.fhir.persistence.FHIRPersistenceSupport
-
public class FHIRPersistenceSupport extends java.lang.Object
Collection of helper methods related to the persistence of FHIR resource payload data
-
-
Constructor Summary
Constructors Constructor Description FHIRPersistenceSupport()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Instant
getCurrentInstant()
Get the current time which can be used for the lastUpdated fieldstatic java.time.Instant
getLastUpdatedFromResource(Resource resource)
Get the lastUpdated value from a Resource as aInstant
.static int
getMetaVersionId(Resource resource)
Obtain the versionId value from the Resource meta element, converting to an int for use by the persistence layerstatic Instant
getNewLastUpdatedInstant(java.time.Instant currentLastUpdated)
Get the lastUpdated time to use for the next version of a resource.static <T extends Resource>
Tparse(java.lang.Class<T> resourceType, java.io.InputStream in, java.util.List<java.lang.String> elements, boolean uncompress)
Parse the given stream, using elements if neededstatic InputOutputByteStream
render(Resource resource, boolean compress)
Render the payload
-
-
-
Method Detail
-
render
public static InputOutputByteStream render(Resource resource, boolean compress) throws FHIRGeneratorException, java.io.IOException
Render the payload- Parameters:
resource
-compress
-- Returns:
- Throws:
FHIRGeneratorException
java.io.IOException
-
parse
public static <T extends Resource> T parse(java.lang.Class<T> resourceType, java.io.InputStream in, java.util.List<java.lang.String> elements, boolean uncompress) throws FHIRParserException, java.io.IOException
Parse the given stream, using elements if needed- Type Parameters:
T
-- Parameters:
resourceType
-in
-elements
-uncompress
-- Returns:
- Throws:
FHIRParserException
java.io.IOException
-
getCurrentInstant
public static Instant getCurrentInstant()
Get the current time which can be used for the lastUpdated field- Returns:
- current time in UTC
-
getMetaVersionId
public static int getMetaVersionId(Resource resource) throws FHIRPersistenceException
Obtain the versionId value from the Resource meta element, converting to an int for use by the persistence layer- Parameters:
resource
-- Returns:
- Throws:
FHIRPersistenceException
-
getLastUpdatedFromResource
public static java.time.Instant getLastUpdatedFromResource(Resource resource)
Get the lastUpdated value from a Resource as aInstant
.- Parameters:
resource
-- Returns:
-
getNewLastUpdatedInstant
public static Instant getNewLastUpdatedInstant(java.time.Instant currentLastUpdated) throws FHIRPersistenceException
Get the lastUpdated time to use for the next version of a resource. If a current version of the resource exists, pass its lastUpdated time as the currenLastUpdated parameter (all times should be UTC). If the gap falls within a grace period of 2 seconds, then we make the new lastUpdated time equal the current time + 1 ms to maintain consistent ordering. Clusters should easily be able to maintain clocks synchronized within 2 seconds if they are configured with a reliable network time service.- Parameters:
currentLastUpdated
-- Returns:
- Throws:
FHIRPersistenceException
- if current time is 2 or more seconds before currentLastUpdated
-
-