Skip to content

Commit

Permalink
Update refresh ig 2 (cqframework#524)
Browse files Browse the repository at this point in the history
* Update Refresh IG Operation

- Updated namespace support
- Tested locally with NHSN IG (Lantana)
- Updated packaging
- Added an operation that publishes bundles to a FHIR server (Lantana)

* Update Refresh IG Operation - 2

* Build fix

* Build fix 2

* Build fix 3

* Fixed package url for StructureMap testing

* Build fix 4

* Update on fhir version for npm package manager

* Update on fhir version for npm package manager (library refresh)

---------

Co-authored-by: c-schuler <[email protected]>
  • Loading branch information
ddieppois and c-schuler authored Apr 25, 2024
1 parent 9af262c commit f322c86
Show file tree
Hide file tree
Showing 35 changed files with 1,921 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,8 @@
import org.opencds.cqf.tooling.measure.r4.RefreshR4MeasureOperation;
import org.opencds.cqf.tooling.measure.stu3.RefreshStu3MeasureOperation;
import org.opencds.cqf.tooling.modelinfo.StructureDefinitionToModelInfo;
import org.opencds.cqf.tooling.operation.BundleResources;
import org.opencds.cqf.tooling.operation.BundleToResources;
import org.opencds.cqf.tooling.operation.BundleToTransactionOperation;
import org.opencds.cqf.tooling.operation.ExecuteMeasureTestOperation;
import org.opencds.cqf.tooling.operation.ExtractMatBundleOperation;
import org.opencds.cqf.tooling.operation.GenerateCQLFromDroolOperation;
import org.opencds.cqf.tooling.operation.IgBundler;
import org.opencds.cqf.tooling.operation.PostBundlesInDirOperation;
import org.opencds.cqf.tooling.operation.PostmanCollectionOperation;
import org.opencds.cqf.tooling.operation.ProfilesToSpreadsheet;
import org.opencds.cqf.tooling.operation.QICoreElementsToSpreadsheet;
import org.opencds.cqf.tooling.operation.RefreshIGOperation;
import org.opencds.cqf.tooling.operation.RefreshLibraryOperation;
import org.opencds.cqf.tooling.operation.ScaffoldOperation;
import org.opencds.cqf.tooling.operation.StripGeneratedContentOperation;
import org.opencds.cqf.tooling.operation.TestIGOperation;
import org.opencds.cqf.tooling.operation.VmrToFhirOperation;
import org.opencds.cqf.tooling.operation.*;
import org.opencds.cqf.tooling.operation.ig.NewRefreshIGOperation;
import org.opencds.cqf.tooling.operations.ExecutableOperation;
import org.opencds.cqf.tooling.operations.OperationParam;
import org.opencds.cqf.tooling.qdm.QdmToQiCore;
Expand Down Expand Up @@ -174,6 +159,8 @@ static Operation createOperation(String operationName) {
return new GenerateCQLFromDroolOperation();
case "VmrToFhir":
return new VmrToFhirOperation();
case "NewRefreshIG":
return new NewRefreshIGOperation();
case "RefreshIG":
return new RefreshIGOperation();
case "RefreshLibrary":
Expand Down Expand Up @@ -214,6 +201,8 @@ static Operation createOperation(String operationName) {
return new SpreadsheetToCQLOperation();
case "PostmanCollection":
return new PostmanCollectionOperation();
case "PublishBundle":
return new BundlePublish();
case "TransformErsd":
return new ErsdTransformer();
case "RollTestsDataDates":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -553,16 +554,13 @@ else if (value instanceof String) {
@SuppressWarnings("FromTemporalAccessor")
private Instant toInstant(Object value) {
if (value instanceof Instant) {
return (Instant)value;
}
else if (value instanceof LocalDateTime) {
return Instant.from((LocalDateTime)value);
}
else if (value instanceof LocalDate) {
return Instant.from((LocalDate)value);
}
else if (value instanceof String) {
return Instant.parse((String)value);
return (Instant) value;
} else if (value instanceof LocalDateTime) {
return ((LocalDateTime) value).toInstant(ZoneOffset.UTC);
} else if (value instanceof LocalDate) {
return ((LocalDate) value).atStartOfDay(ZoneOffset.UTC).toInstant();
} else if (value instanceof String) {
return Instant.parse((String) value);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void getBindings(String sdName, List<ElementDefinition> eds, String sdUR
sdbo.setSdURL(sdURL);
sdbo.setSdVersion(sdVersion);
sdbo.setBindingStrength(ed.getBinding().getStrength().toString().toLowerCase());
if(ed.hasMin()){
if(ed.hasMin() && ed.hasMax()){
String edCardinality = ed.getMin() + "..." + ed.getMax();
sdbo.setCardinality(edCardinality);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void getElements(String sdName, List<ElementDefinition> eds, String sdUR
sdeo.setSdName(sdName);
sdeo.setSdURL(sdURL);
sdeo.setSdVersion(sdVersion);
if (ed.hasMin()) {
if (ed.hasMin() && ed.hasMax()) {
String edCardinality = ed.getMin() + "..." + ed.getMax();
sdeo.setCardinality(edCardinality);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,73 +1,23 @@
package org.opencds.cqf.tooling.cql_generation.builder;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.tuple.Pair;
import org.cqframework.cql.cql2elm.CqlCompilerException;
import org.cqframework.cql.cql2elm.CqlSemanticException;
import org.cqframework.cql.cql2elm.DataTypes;
import org.cqframework.cql.cql2elm.LibraryBuilder;
import org.cqframework.cql.cql2elm.LibrarySourceProvider;
import org.cqframework.cql.cql2elm.*;
import org.cqframework.cql.cql2elm.model.QueryContext;
import org.cqframework.cql.cql2elm.model.invocation.InValueSetInvocation;
import org.hl7.cql.model.ClassType;
import org.hl7.cql.model.DataType;
import org.hl7.cql.model.ListType;
import org.hl7.cql.model.NamedType;
import org.hl7.cql.model.TupleType;
import org.hl7.cql.model.TupleTypeElement;
import org.hl7.elm.r1.AccessModifier;
import org.hl7.elm.r1.AggregateClause;
import org.hl7.elm.r1.AliasRef;
import org.hl7.elm.r1.AliasedQuerySource;
import org.hl7.elm.r1.And;
import org.hl7.elm.r1.AnyInCodeSystem;
import org.hl7.elm.r1.AnyInValueSet;
import org.hl7.elm.r1.BinaryExpression;
import org.hl7.elm.r1.ByDirection;
import org.hl7.elm.r1.CodeDef;
import org.hl7.elm.r1.CodeRef;
import org.hl7.elm.r1.CodeSystemDef;
import org.hl7.elm.r1.CodeSystemRef;
import org.hl7.elm.r1.Contains;
import org.hl7.elm.r1.Element;
import org.hl7.elm.r1.Exists;
import org.hl7.elm.r1.Expression;
import org.hl7.elm.r1.In;
import org.hl7.elm.r1.InCodeSystem;
import org.hl7.elm.r1.InValueSet;
import org.hl7.elm.r1.IncludeDef;
import org.hl7.elm.r1.LetClause;
import org.hl7.elm.r1.Not;
import org.hl7.elm.r1.ObjectFactory;
import org.hl7.elm.r1.Or;
import org.hl7.elm.r1.Property;
import org.hl7.elm.r1.Query;
import org.hl7.elm.r1.RelationshipClause;
import org.hl7.elm.r1.Retrieve;
import org.hl7.elm.r1.ReturnClause;
import org.hl7.elm.r1.SortByItem;
import org.hl7.elm.r1.SortClause;
import org.hl7.elm.r1.ToConcept;
import org.hl7.elm.r1.ToList;
import org.hl7.elm.r1.Tuple;
import org.hl7.elm.r1.TupleElement;
import org.hl7.elm.r1.ValueSetDef;
import org.hl7.elm.r1.ValueSetRef;
import org.hl7.elm.r1.Xor;
import org.hl7.cql.model.*;
import org.hl7.elm.r1.*;
import org.hl7.elm_modelinfo.r1.ModelInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.List;
import java.util.*;

// Some of these methods should probably live in LibraryBuilder... possible all
/**
* @author Joshua Reynolds
Expand Down Expand Up @@ -583,6 +533,8 @@ public Retrieve resolveRetrieve(LibraryBuilder libraryBuilder, String resource,
break;

default:
// ERROR:
// WARNING:
libraryBuilder.recordParsingException(new CqlSemanticException(String.format("Unknown code comparator %s in retrieve", codeComparator),
useStrictRetrieveTyping ? CqlCompilerException.ErrorSeverity.Error : CqlCompilerException.ErrorSeverity.Warning));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
import org.fhir.ucum.UcumEssenceService;
import org.fhir.ucum.UcumException;
import org.fhir.ucum.UcumService;
import org.hl7.elm.r1.ContextDef;
import org.hl7.elm.r1.Expression;
import org.hl7.elm.r1.ExpressionRef;
import org.hl7.elm.r1.Library;
import org.hl7.elm.r1.UsingDef;
import org.hl7.elm.r1.VersionedIdentifier;
import org.hl7.elm.r1.*;
import org.opencds.cqf.tooling.cql_generation.IOUtil;
import org.opencds.cqf.tooling.cql_generation.builder.VmrToModelElmBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,26 @@ public Void visitLetClause(LetClause let, ElmContext context) {
return null;
}

/**
* Visit WhereClause. This method will be called for
* WhereClause expression nodes.
*
* @param where the Expression
* @param context the context passed to the visitor
* @return the visitor result
*/
public Void visitWhereClause(Expression where, ElmContext context) {
try {
enterClause();
output.append("where");
visitElement(where, context);
return null;
}
finally {
exitClause();
}
}

/**
* Visit ReturnClause. This method will be called for
* every node in the tree that is a ReturnClause.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
package org.opencds.cqf.tooling.modelinfo;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.file.Paths;
import java.util.Map;

import javax.xml.namespace.QName;

import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Marshaller;

import org.hl7.elm_modelinfo.r1.ClassInfo;
import org.hl7.elm_modelinfo.r1.ConversionInfo;
import org.hl7.elm_modelinfo.r1.ModelInfo;
Expand All @@ -31,6 +20,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.namespace.QName;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.file.Paths;
import java.util.Map;

public class StructureDefinitionToModelInfo extends Operation {

private static final Logger logger = LoggerFactory.getLogger(StructureDefinitionToModelInfo.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.opencds.cqf.tooling.npm;

import java.util.Objects;

public class NamespaceInfo extends org.hl7.cql.model.NamespaceInfo {
private String version;
public NamespaceInfo(String name, String uri, String version) {
super(name, uri);
if (version != null && !version.isEmpty()) {
this.version = version;
} else {
throw new IllegalArgumentException("Version is required");
}
}

public String getVersion() {
return version;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), version);
}

@Override
public boolean equals(Object that) {
if (that instanceof NamespaceInfo) {
NamespaceInfo thatInfo = (NamespaceInfo)that;
return this.getName().equals(thatInfo.getName()) && this.getUri().equals(thatInfo.getUri())
&& this.getVersion().equals(thatInfo.getVersion());
}

return false;
}

@Override
public String toString() {
return String.format("%s: %s|%s", getName(), getUri(), getVersion());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.opencds.cqf.tooling.npm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class NamespaceManager extends org.hl7.cql.model.NamespaceManager {
private final Map<String, List<NamespaceInfo>> namespaces;

public NamespaceManager() {
this.namespaces = new HashMap<>();
}

@Override
public boolean hasNamespaces() {
return !this.namespaces.isEmpty();
}

@Override
public void ensureNamespaceRegistered(org.hl7.cql.model.NamespaceInfo namespaceInfo) {
if (namespaceInfo == null) {
throw new IllegalArgumentException("namespaceInfo is required");
}

if (!namespaces.containsKey(namespaceInfo.getName())) {
if (namespaceInfo instanceof NamespaceInfo) {
addNamespace(namespaceInfo.getName(), namespaceInfo.getUri(), ((NamespaceInfo) namespaceInfo).getVersion());
} else {
addNamespace(namespaceInfo.getName(), namespaceInfo.getUri());
}
}
}

@Override
public void addNamespace(org.hl7.cql.model.NamespaceInfo namespaceInfo) {
if (namespaceInfo == null) {
throw new IllegalArgumentException("namespaceInfo is required");
}

if (namespaceInfo instanceof NamespaceInfo) {
addNamespace(namespaceInfo.getName(), namespaceInfo.getUri(), ((NamespaceInfo) namespaceInfo).getVersion());
} else {
addNamespace(namespaceInfo.getName(), namespaceInfo.getUri());
}
}

public void addNamespace(String name, String uri, String version) {
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("Namespace name is required");
}

if (uri == null || uri.isEmpty()) {
throw new IllegalArgumentException("Namespace uri is required");
}

if (version == null || version.isEmpty()) {
throw new IllegalArgumentException("Namespace version is required");
}

namespaces.computeIfAbsent(name, s -> new ArrayList<>()).add(new NamespaceInfo(name, uri, version));
}

public String resolveNamespaceUri(String name, String version) {
if (namespaces.containsKey(name)) {
return namespaces.get(name).stream().filter(x -> x.getVersion().equals(version)).findFirst().orElseThrow().getUri();
}

return null;
}

public org.hl7.cql.model.NamespaceInfo getNamespaceInfoFromUri(String uri, String version) {
return namespaces.values().stream().flatMap(List::stream).filter(
x -> x.getUri().equals(uri) && x.getVersion().equals(version)).findFirst().orElseThrow();
}
}
Loading

0 comments on commit f322c86

Please sign in to comment.