Skip to content

Commit

Permalink
Merge pull request #104 from cqframework/fix-99-support-fhir-stu3
Browse files Browse the repository at this point in the history
#99: Added support for FHIR STU3.
  • Loading branch information
cmoesel authored Mar 29, 2017
2 parents ee84b23 + 4c4de99 commit 33af977
Show file tree
Hide file tree
Showing 14 changed files with 6,508 additions and 319 deletions.
3 changes: 2 additions & 1 deletion Examples/Zika/zika-virus-intervention-logic.cql
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ define "Pregnancy Conditions":
[Condition: "Pregnancy"] C
where C.clinicalStatus = 'active'
and C.verificationStatus = 'confirmed'
// well, this is ugly....
and Interval[C.onsetDateTime, C.abatementDateTime] includes Today()

define "Is Patient Pregnant":
Expand Down Expand Up @@ -123,7 +124,7 @@ define "Has Possible Zika Exposure":
define "Zika Symptom Onset":
First(
"Zika Symptoms" S
sort by S.onsetDateTime
sort by (S.onsetDateTime)
).onsetDateTime
define "Time Since Symptom Onset":
Expand Down
700 changes: 421 additions & 279 deletions Examples/Zika/zika-virus-intervention-logic.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ private static void writeELM(Path inPath, Path outPath, Format format, boolean d

LibraryManager libraryManager = new LibraryManager();
libraryManager.getLibrarySourceLoader().registerProvider(new DefaultLibrarySourceProvider(inPath.getParent()));
libraryManager.getLibrarySourceLoader().registerProvider(new FhirLibrarySourceProvider());
CqlTranslator translator = fromFile(inPath.toFile(), libraryManager, options.toArray(new Options[options.size()]));
libraryManager.getLibrarySourceLoader().clearProviders();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public InputStream getLibrarySource(VersionedIdentifier libraryIdentifier) {
}
}

if (source == null) {
throw new IllegalArgumentException(String.format("Could not load source for library %s, version %s.",
libraryIdentifier.getId(), libraryIdentifier.getVersion()));
}

return source;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,21 @@ public boolean accept(File path, String name) {
}
}

if (mostRecentFile == null) {
throw new IllegalArgumentException(String.format("Could not resolve most recent source library for library %s.", libraryIdentifier.getId()));
}
// Do not throw, allow the loader to throw, just report null
//if (mostRecentFile == null) {
// throw new IllegalArgumentException(String.format("Could not resolve most recent source library for library %s.", libraryIdentifier.getId()));
//}

libraryFile = mostRecentFile;
}
try {
return new FileInputStream(libraryFile);
if (libraryFile != null) {
return new FileInputStream(libraryFile);
}
} catch (FileNotFoundException e) {
throw new IllegalArgumentException(String.format("Could not load source for library %s.", libraryIdentifier.getId()), e);
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.cqframework.cql.cql2elm;

import org.hl7.elm.r1.VersionedIdentifier;

import java.io.InputStream;

/**
* Created by Bryn on 3/28/2017.
*/
public class FhirLibrarySourceProvider implements LibrarySourceProvider {
@Override
public InputStream getLibrarySource(VersionedIdentifier libraryIdentifier) {
return FhirLibrarySourceProvider.class.getResourceAsStream(String.format("/org/hl7/fhir/%s-%s.cql", libraryIdentifier.getId(),
libraryIdentifier.getVersion()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ public ModelInfo load() {
ModelInfo.class);

case "1.8":
case "":
return JAXB.unmarshal(FhirModelInfoProvider.class.getResourceAsStream("/org/hl7/fhir/fhir-modelinfo-1.8.xml"),
ModelInfo.class);

case "3.0.0":
case "":
return JAXB.unmarshal(FhirModelInfoProvider.class.getResourceAsStream("/org/hl7/fhir/fhir-modelinfo-3.0.0.xml"),
ModelInfo.class);

default:
throw new IllegalArgumentException(String.format("Unknown version %s of the FHIR model.", localVersion));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ModelInfoLoader {
registerModelInfoProvider(new VersionedIdentifier().withId("FHIR").withVersion("1.6"), new FhirModelInfoProvider().withVersion("1.6"));
registerModelInfoProvider(new VersionedIdentifier().withId("FHIR").withVersion("1.4"), new FhirModelInfoProvider().withVersion("1.4"));
registerModelInfoProvider(new VersionedIdentifier().withId("FHIR").withVersion("1.8"), new FhirModelInfoProvider().withVersion("1.8"));
registerModelInfoProvider(new VersionedIdentifier().withId("FHIR").withVersion("3.0.0"), new FhirModelInfoProvider().withVersion("3.0.0"));
}

public static ModelInfoProvider getModelInfoProvider(VersionedIdentifier modelIdentifier) {
Expand Down
Loading

0 comments on commit 33af977

Please sign in to comment.