-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor implementation of getResourceKey and getReferenceKey
- Loading branch information
1 parent
a77bb1b
commit f033630
Showing
23 changed files
with
207 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
fhirpath/src/main/java/au/csiro/pathling/fhirpath/collection/EmptyCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package au.csiro.pathling.fhirpath.collection; | ||
|
||
import au.csiro.pathling.fhirpath.FhirPathType; | ||
import au.csiro.pathling.fhirpath.column.ColumnRepresentation; | ||
import au.csiro.pathling.fhirpath.column.EmptyRepresentation; | ||
import au.csiro.pathling.fhirpath.definition.NodeDefinition; | ||
import java.util.Optional; | ||
import javax.annotation.Nonnull; | ||
import org.hl7.fhir.r4.model.Enumerations.FHIRDefinedType; | ||
|
||
/** | ||
* Represents an empty collection. | ||
*/ | ||
public class EmptyCollection extends Collection { | ||
|
||
private static final EmptyCollection INSTANCE = new EmptyCollection( | ||
EmptyRepresentation.getInstance(), Optional.empty(), Optional.empty(), Optional.empty()); | ||
|
||
protected EmptyCollection(@Nonnull final ColumnRepresentation column, | ||
@Nonnull final Optional<FhirPathType> type, @Nonnull final Optional<FHIRDefinedType> fhirType, | ||
@Nonnull final Optional<? extends NodeDefinition> definition) { | ||
super(column, type, fhirType, definition); | ||
} | ||
|
||
/** | ||
* @return A singleton instance of this class | ||
*/ | ||
public static EmptyCollection getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public boolean isComparableTo(@Nonnull final Collection path) { | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
fhirpath/src/main/java/au/csiro/pathling/fhirpath/collection/ReferenceCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package au.csiro.pathling.fhirpath.collection; | ||
|
||
import au.csiro.pathling.fhirpath.FhirPathType; | ||
import au.csiro.pathling.fhirpath.TypeSpecifier; | ||
import au.csiro.pathling.fhirpath.column.ColumnRepresentation; | ||
import au.csiro.pathling.fhirpath.definition.NodeDefinition; | ||
import au.csiro.pathling.fhirpath.function.ColumnTransform; | ||
import java.util.Optional; | ||
import javax.annotation.Nonnull; | ||
import org.hl7.fhir.r4.model.Enumerations.FHIRDefinedType; | ||
|
||
/** | ||
* Represents a collection of Reference elements. | ||
* | ||
* @author John Grimes | ||
* @see <a href="https://hl7.org/fhir/R4/references.html#Reference">Resource References</a> | ||
*/ | ||
public class ReferenceCollection extends Collection { | ||
|
||
private static final String REFERENCE_ELEMENT_NAME = "reference"; | ||
|
||
protected ReferenceCollection(@Nonnull final ColumnRepresentation column, | ||
@Nonnull final Optional<FhirPathType> type, @Nonnull final Optional<FHIRDefinedType> fhirType, | ||
@Nonnull final Optional<? extends NodeDefinition> definition) { | ||
super(column, type, fhirType, definition); | ||
} | ||
|
||
/** | ||
* @param typeSpecifier The type specifier to filter by | ||
* @return a {@link Collection} containing the keys of the references in this collection, suitable | ||
* for joining with resource keys | ||
*/ | ||
@Nonnull | ||
public Collection getKeyCollection(@Nonnull final Optional<TypeSpecifier> typeSpecifier) { | ||
return typeSpecifier | ||
// If a type was specified, create a regular expression that matches references of this type. | ||
.map(ts -> ts.toFhirType().toCode() + "/.+") | ||
// Get a ColumnTransform that filters the reference column based on the regular expression. | ||
.map(this::keyFilter) | ||
// Apply the filter to the reference column. | ||
.map(this::filter) | ||
// Return a StringCollection of the reference elements.s | ||
.flatMap(c -> c.traverse(REFERENCE_ELEMENT_NAME)) | ||
// If no type was specified, return the reference column as is. | ||
.or(() -> this.traverse(REFERENCE_ELEMENT_NAME)) | ||
// If the reference column is not present, return an empty collection. | ||
.orElse(EmptyCollection.getInstance()); | ||
} | ||
|
||
@Nonnull | ||
private ColumnTransform keyFilter(@Nonnull final String pattern) { | ||
return col -> col.traverse(REFERENCE_ELEMENT_NAME, Optional.of(FHIRDefinedType.STRING)) | ||
.like(pattern); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.