Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Commit

Permalink
Feature support negation profiles 20 (#618)
Browse files Browse the repository at this point in the history
* #508,#552: Added support for profile validation in the retrieve
#520: Fixed incorrect handling of null enumerations and primitives for FHIR-based models

# Conflicts:
#	engine.fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/model/TestDstu2ModelResolver.java
#	engine.fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/model/TestDstu3ModelResolver.java
#	engine.fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/model/TestR4ModelResolver.java
#	pom.xml

* Add v15 branch to release scripting

* Merge master (#627)

* update v2.1.0 (#617)

* update v2.1.0

* update reference for FhirLibrarySourceProvider

* remove xpp3 exclusion

* update readme

* Rework xpp3 dependencies due to test failures

Co-authored-by: Jonathan Percival <[email protected]>

* snapshot v2.2.0 (#619)

* ModelResolver Task to Patient path returns `for` instead of `requester` (#624)

* Adding Android compliance check on the engine, engine.fhir and engine.jackson

* Correctly using plugin management

* Fixing Test case

* Using Assert equals and not assertTrue(equals(x))

* Fixing #621

Co-authored-by: mdnazmulkarim <[email protected]>
Co-authored-by: Jonathan Percival <[email protected]>
Co-authored-by: Vitor Pamplona <[email protected]>

Co-authored-by: mdnazmulkarim <[email protected]>
Co-authored-by: Jonathan Percival <[email protected]>
Co-authored-by: Vitor Pamplona <[email protected]>
  • Loading branch information
4 people authored Oct 20, 2022
1 parent e13c23d commit d245db1
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ script:
before_cache:
- rm -rf $HOME/.m2/repository/org/opencds/cqf/cql
after_success:
- test $TRAVIS_BRANCH = "master" && test $TRAVIS_PULL_REQUEST = "false" && ./scripts/deploy.sh
- test ($TRAVIS_BRANCH = "master" || $TRAVIS_BRANCH = "v15") && test $TRAVIS_PULL_REQUEST = "false" && ./scripts/deploy.sh
deploy:
provider: releases
api_key:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,10 @@ public TemporalPrecisionEnum toTemporalPrecisionEnum(Precision precision) {
*/

public Object toJavaPrimitive(Object result, Object source) {
if (source instanceof IPrimitiveType<?> && !((IPrimitiveType<?>)source).hasValue()) {
return null;
}

String simpleName = source.getClass().getSimpleName();
switch (simpleName) {
case "InstantType":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.opencds.cqf.cql.engine.fhir.retrieve;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.opencds.cqf.cql.engine.fhir.exception.UnknownElement;

import ca.uhn.fhir.rest.client.api.IGenericClient;
Expand All @@ -14,19 +16,25 @@ public class FhirBundleCursor implements Iterable<Object> {

public FhirBundleCursor(IGenericClient fhirClient, IBaseBundle results)
{
this(fhirClient, results, null);
this(fhirClient, results, null, null);
}

public FhirBundleCursor(IGenericClient fhirClient, IBaseBundle results, String dataType) { this(fhirClient, results, null, null); }

// This constructor filters the bundle based on dataType
public FhirBundleCursor(IGenericClient fhirClient, IBaseBundle results, String dataType) {
// If templateId is provided, this is a trusted cursor, meaning that it will only return results
// for resources that declare they conform to the given profile
public FhirBundleCursor(IGenericClient fhirClient, IBaseBundle results, String dataType, String templateId) {
this.fhirClient = fhirClient;
this.results = results;
this.dataType = dataType;
this.templateId = templateId;
}

private IGenericClient fhirClient;
private IBaseBundle results;
private String dataType;
private String templateId;


/**
Expand All @@ -35,15 +43,21 @@ public FhirBundleCursor(IGenericClient fhirClient, IBaseBundle results, String d
* @return an Iterator.
*/
public Iterator<Object> iterator() {
return new FhirBundleIterator(fhirClient, results, dataType);
return new FhirBundleIterator(fhirClient, results, dataType, templateId);
}

private class FhirBundleIterator implements Iterator<Object> {
public FhirBundleIterator(IGenericClient fhirClient, IBaseBundle results, String dataType) {
public FhirBundleIterator(IGenericClient fhirClient, IBaseBundle results, String dataType, String templateId) {
this.fhirClient = fhirClient;
this.results = results;
this.current = -1;
this.dataType = dataType;
this.templateId = templateId;

// Do not test templateId for base resource "profiles"
if (this.templateId != null && this.templateId.startsWith(String.format("http://hl7.org/fhir/StructureDefinition/%s", dataType))) {
this.templateId = null;
}

if (dataType != null) {
this.dataTypeClass = this.fhirClient.getFhirContext().getResourceDefinition(this.dataType).getImplementingClass();
Expand All @@ -56,6 +70,7 @@ public FhirBundleIterator(IGenericClient fhirClient, IBaseBundle results, String
private IBaseBundle results;
private int current;
private String dataType;
private String templateId;
private Class<? extends IBaseResource> dataTypeClass;
private List<? extends IBaseResource> currentEntry;

Expand All @@ -74,13 +89,33 @@ public boolean hasNext() {
private List<? extends IBaseResource> getEntry() {
if (this.dataTypeClass != null)
{
return BundleUtil.toListOfResourcesOfType(this.fhirClient.getFhirContext(), this.results, this.dataTypeClass);
List<? extends IBaseResource> entries = BundleUtil.toListOfResourcesOfType(this.fhirClient.getFhirContext(), this.results, this.dataTypeClass);
if (templateId != null) {
return getTrustedEntries(entries, templateId);
}
else {
return entries;
}
}
else {
return BundleUtil.toListOfResources(this.fhirClient.getFhirContext(), this.results);
}
}

private List<? extends IBaseResource> getTrustedEntries(List<? extends IBaseResource> entries, String templateId) {
List<IBaseResource> trustedEntries = new ArrayList<IBaseResource>();
for (IBaseResource entry : entries) {
if (entry.getMeta() != null && entry.getMeta().getProfile() != null) {
for (IPrimitiveType<?> profile : entry.getMeta().getProfile()) {
if (profile.hasValue() && profile.getValueAsString().equals(templateId)) {
trustedEntries.add(entry);
}
}
}
}
return trustedEntries;
}

private String getLink() {
return BundleUtil.getLinkUrlOfType(this.fhirClient.getFhirContext(), this.results, IBaseBundle.LINK_NEXT);
}
Expand All @@ -105,6 +140,7 @@ public Object next() {
}

// TODO: It would be possible to get here if the next link was present, but the returned page had 0 entries...
// NOTE: This is especially true if the page has only data that is not conformant to the given profile
throw new UnknownElement("The iteration has no more elements.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,14 @@ public void resolveNullEnumerationReturnsNull() {
Object result = resolver.resolvePath(sq, "comparator");
assertNull(result);
}

//@Test
public void resolveNullPrimitiveReturnsNull() {
FhirModelResolver<Base,BaseDateTimeType,?,?,?,?,?,?> resolver = new Dstu2FhirModelResolver(FhirContext.forCached(FhirVersionEnum.DSTU2));

DateTimeType dt = new DateTimeType();

Object result = resolver.resolvePath(dt, "value");
assertNull(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,14 @@ public void resolveNullEnumerationReturnsNull() {
Object result = resolver.resolvePath(sq, "comparator");
assertNull(result);
}

@Test
public void resolveNullPrimitiveReturnsNull() {
FhirModelResolver<Base,BaseDateTimeType,?,?,?,?,?,?> resolver = new Dstu3FhirModelResolver(FhirContext.forCached(FhirVersionEnum.DSTU3));

DateTimeType dt = new DateTimeType();

Object result = resolver.resolvePath(dt, "value");
assertNull(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,14 @@ public void resolveNullEnumerationReturnsNull() {
Object result = resolver.resolvePath(sq, "comparator");
assertNull(result);
}

@Test
public void resolveNullPrimitiveReturnsNull() {
FhirModelResolver<Base,BaseDateTimeType,?,?,?,?,?,?> resolver = new R4FhirModelResolver(FhirContext.forCached(FhirVersionEnum.R4));

DateTimeType dt = new DateTimeType();

Object result = resolver.resolvePath(dt, "value");
assertNull(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ private Field getProperty(Class<?> clazz, String path) {
Field field = clazz.getDeclaredField(path);
return field;
} catch (NoSuchFieldException e) {
if (clazz.getSuperclass() != null) {
Field field = getProperty(clazz.getSuperclass(), path);
return field;
}
throw new IllegalArgumentException(String.format("Could not determine field for path %s of type %s", path, clazz.getSimpleName()));
}
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
set -euxo pipefail
bash -n "$0"

if [[ "$TRAVIS_BRANCH" != "master" && -z "$TRAVIS_TAG" ]]
if [[ "$TRAVIS_BRANCH" != "master" && "$TRAVIS_BRANCH" != "v15" && -z "$TRAVIS_TAG" ]]
then
echo "Not on the master branch or a git tag. Skipping deploy."
echo "Not on the master or v15 branches or a git tag. Skipping deploy."
exit 0
fi

Expand Down

0 comments on commit d245db1

Please sign in to comment.