Skip to content

Commit

Permalink
Issue #1980 - added Javadoc
Browse files Browse the repository at this point in the history
Signed-off-by: John T.E. Timm <johntimm@us.ibm.com>
  • Loading branch information
JohnTimm committed Mar 11, 2021
1 parent f1481d5 commit 50617bf
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,74 @@
* A graph that represents FHIR CodeSystem content and is backed by a graph database (Janusgraph)
*/
public interface FHIRTermGraph {
/**
* The edge label that represents an is-a relationship in the graph
*/
public static final String IS_A = "isa";

/**
* Get the configuration used to create this {@link FHIRTermGraph}
*
* @return
* the configuration
*/
Configuration configuration();

/**
* Get the underlying {@link JanusGraph} instance behind this {@link FHIRTermGraph}
*
* @return
* the {@link JanusGraph} instance
*/
JanusGraph getJanusGraph();

/**
* Get the graph traversal source associated with the underlying {@link JanusGraph} instance
*
* @return
* the graph traversal source
*/
GraphTraversalSource traversal();

/**
* Query the indexing backend using the <a href="https://lucene.apache.org/core/2_9_4/queryparsersyntax.html">Lucene query parser syntax</a>
*
* @param query
* the query
* @return
* results of the specified query
*/
default Stream<Result<JanusGraphVertex>> indexQuery(String query) {
return indexQuery(query, Integer.MAX_VALUE - 1);
return indexQuery(query, Integer.MAX_VALUE - 1, 0);
}
Stream<Result<JanusGraphVertex>> indexQuery(String query, int limit);

/**
* Query the indexing backend using the <a href="https://lucene.apache.org/core/2_9_4/queryparsersyntax.html">Lucene query parser syntax</a>
* and the provided limit and offset
*
* @param query
* the query
* @param limit
* the limit
* @param offset
* the offset
* @return
* results of the specified query using the provided limit and offset
*/
Stream<Result<JanusGraphVertex>> indexQuery(String query, int limit, int offset);

/**
* Close the graph and its underlying resources
*/
void close();

/**
* Drop the graph
*/
void drop();

/**
* Drop all vertices and edges from the graph
*/
void dropAllVertices();
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public GraphTraversalSource traversal() {
}

@Override
public Stream<Result<JanusGraphVertex>> indexQuery(String query, int limit) {
return graph.indexQuery("vertices", query).limit(limit).vertexStream();
public Stream<Result<JanusGraphVertex>> indexQuery(String query, int limit, int offset) {
return graph.indexQuery("vertices", query).limit(limit).offset(offset).vertexStream();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,30 @@ public Options options() {

public abstract Options options();
}

/**
* Load the {@link FHIRTermGraph}
*/
void load();

/**
* Close the loader and its underlying resources
*/
void close();

/**
* Get the options used to create this {@link FHIRTermGraphLoader}
*
* @return
* the options
*/
Map<String, String> options();

/**
* Get the underlying {@link FHIRTermGraph} instance
*
* @return
* the {@link FHIRTermGraph} instance
*/
FHIRTermGraph getGraph();
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public final class CodeSystemSupport {

private CodeSystemSupport() { }

/**
* Determine if the given FHIR string value can be converted to a FHIR Boolean value.
*
* @param value
* the FHIR string value
* @return
* true if the given FHIR string value can be converted to a FHIR Boolean value, false otherwise
*/
public static boolean convertsToBoolean(String value) {
return "true".equals(value.getValue()) || "false".equals(value.getValue());
}
Expand Down Expand Up @@ -97,6 +105,19 @@ public static Concept findConcept(CodeSystem codeSystem, Concept concept, Code c
return result;
}

/**
* Determine whether a code system filter with the specified property code and filter operator exists
* in the provided code system.
*
* @param codeSystem
* the code system
* @param code
* the property code
* @param operator
* the filter operator
* @return
* true if the code system filter exists, false otherwise
*/
public static boolean hasCodeSystemFilter(CodeSystem codeSystem, Code code, FilterOperator operator) {
return getCodeSystemFilter(codeSystem, code, operator) != null;
}
Expand Down Expand Up @@ -170,6 +191,18 @@ public static CodeSystem getCodeSystem(java.lang.String url) {
return FHIRRegistry.getInstance().getResource(url, CodeSystem.class);
}

/**
* Get the code system filter with the given property code and filter operator.
*
* @param codeSystem
* the code system
* @param code
* the property code
* @param operator
* the filter operator
* @return
* the code system filter with the given property code and filter operator, or null if no such filter exists
*/
public static CodeSystem.Filter getCodeSystemFilter(CodeSystem codeSystem, Code code, FilterOperator operator) {
for (CodeSystem.Filter filter : codeSystem.getFilter()) {
if (filter.getCode().equals(code) && filter.getOperator().contains(operator)) {
Expand Down Expand Up @@ -310,10 +343,29 @@ public static Set<Concept> getConcepts(Concept concept) {
return concepts;
}

/**
* Convert the given FHIR string value to a FHIR boolean value.
*
* @param value
* the FHIR string value
* @return
* the FHIR boolean value equivalent of the provided FHIR string value
*/
public static Boolean toBoolean(String value) {
return "true".equals(value.getValue()) ? Boolean.TRUE : Boolean.FALSE;
}

/**
* Convert the given FHIR string value to an Element value based on the provided property type.
*
* @param value
* the FHIR string value
* @param type
* the property type
* @return
* the Element value equivalent of the given FHIR string based on the provided property type,
* or null if the type isn't supported
*/
public static Element toElement(String value, PropertyType type) {
switch (type.getValueAsEnumConstant()) {
case BOOLEAN:
Expand All @@ -334,6 +386,17 @@ public static Element toElement(String value, PropertyType type) {
}
}

/**
* Convert the given Java string value to an Element based on the provided property type.
*
* @param value
* the Java string value
* @param type
* the property type
* @return
* the Element value equivalent of the given Java string based on the provided property type,
* or null if the type isn't supported
*/
public static Element toElement(java.lang.String value, PropertyType type) {
switch (type.getValueAsEnumConstant()) {
case BOOLEAN:
Expand Down

0 comments on commit 50617bf

Please sign in to comment.