use of org.hl7.fhir.r5.model.Annotation in project dpc-app by CMSgov.
the class BundleHandler method generateBaseBundle.
private Bundle generateBaseBundle(Annotation[] annotations, int entryCount) {
final Optional<BundleReturnProperties> maybeAnnotation = Arrays.stream(annotations).filter(a -> a.annotationType().equals(BundleReturnProperties.class)).map(a -> (BundleReturnProperties) a).findAny();
final Bundle.BundleType bundleType = maybeAnnotation.map(BundleReturnProperties::bundleType).orElse(Bundle.BundleType.SEARCHSET);
final Bundle bundle = new Bundle();
bundle.setType(bundleType);
if (bundleType.equals(Bundle.BundleType.SEARCHSET)) {
bundle.setTotal(entryCount);
}
return bundle;
}
use of org.hl7.fhir.r5.model.Annotation in project dpc-app by CMSgov.
the class BundleHandler method writeTo.
@Override
public void writeTo(Collection<Resource> baseResources, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
final Bundle bundle = generateBaseBundle(annotations, baseResources.size());
final List<Bundle.BundleEntryComponent> entries = baseResources.stream().map(resource -> {
final Bundle.BundleEntryComponent bundleEntryComponent = new Bundle.BundleEntryComponent();
bundleEntryComponent.setResource(resource);
return bundleEntryComponent;
}).collect(Collectors.toList());
bundle.setEntry(entries);
this.handler.writeTo(bundle, type, genericType, annotations, mediaType, httpHeaders, entityStream);
}
use of org.hl7.fhir.r5.model.Annotation in project dpc-app by CMSgov.
the class ParamResourceFactory method extractFHIRResource.
private Resource extractFHIRResource(Parameters fhirParameters) {
final FHIRParameter annotation = parameter.getAnnotation(FHIRParameter.class);
// Get the appropriate parameter
final String parameterName = annotation.name();
if (parameterName.equals("")) {
return fhirParameters.getParameterFirstRep().getResource();
} else {
return fhirParameters.getParameter().stream().filter(param -> param.hasName() && param.getName().equals(parameterName)).map(Parameters.ParametersParameterComponent::getResource).findAny().orElseThrow(() -> {
logger.error("Cannot find parameter named `{}` in resource", parameterName);
throw new WebApplicationException(String.format("Cannot find matching parameter named `%s`", parameterName), Response.Status.BAD_REQUEST);
});
}
}
use of org.hl7.fhir.r5.model.Annotation in project clinical_quality_language by cqframework.
the class CommentTests method testTags.
@Test
public void testTags() throws IOException {
CqlTranslator translator = TestUtils.runSemanticTest("TestTags.cql", 0);
CompiledLibrary library = translator.getTranslatedLibrary();
assertThat(library.getLibrary().getAnnotation(), notNullValue());
Annotation a = null;
for (Object o : library.getLibrary().getAnnotation()) {
if (o instanceof Annotation) {
a = (Annotation) o;
}
}
assertThat(a, notNullValue());
assertThat(a.getT(), notNullValue());
assertThat(a.getT().size(), equalTo(3));
for (int i = 0; i < a.getT().size(); i++) {
Tag t = a.getT().get(i);
switch(i) {
case 0:
assertThat(t.getName(), equalTo("author"));
assertThat(t.getValue(), equalTo("Frederic Chopin"));
break;
case 1:
assertThat(t.getName(), equalTo("description"));
assertThat(t.getValue(), equalTo("Test tags"));
break;
case 2:
assertThat(t.getName(), equalTo("allowFluent"));
assertThat(t.getValue(), equalTo("true"));
break;
}
}
ExpressionDef d = library.resolveExpressionRef("TestExpression");
assertThat(d.getAnnotation(), notNullValue());
for (Object o : d.getAnnotation()) {
if (o instanceof Annotation) {
a = (Annotation) o;
}
}
assertThat(a, notNullValue());
assertThat(a.getT(), notNullValue());
assertThat(a.getT().size(), equalTo(2));
for (int i = 0; i < a.getT().size(); i++) {
Tag t = a.getT().get(i);
switch(i) {
case 0:
assertThat(t.getName(), equalTo("author"));
assertThat(t.getValue(), equalTo("Frederic Chopin"));
break;
case 1:
assertThat(t.getName(), equalTo("description"));
assertThat(t.getValue(), equalTo("Test tags"));
break;
}
}
for (ExpressionDef e : library.getLibrary().getStatements().getDef()) {
if (e instanceof FunctionDef) {
d = e;
break;
}
}
assertThat(d.getAnnotation(), notNullValue());
for (Object o : d.getAnnotation()) {
if (o instanceof Annotation) {
a = (Annotation) o;
}
}
assertThat(a, notNullValue());
assertThat(a.getT(), notNullValue());
assertThat(a.getT().size(), equalTo(2));
for (int i = 0; i < a.getT().size(); i++) {
Tag t = a.getT().get(i);
switch(i) {
case 0:
assertThat(t.getName(), equalTo("author"));
assertThat(t.getValue(), equalTo("Frederic Chopin"));
break;
case 1:
assertThat(t.getName(), equalTo("description"));
assertThat(t.getValue(), equalTo("Test tags"));
break;
}
}
d = library.resolveExpressionRef("TestMultiline");
assertThat(d.getAnnotation(), notNullValue());
for (Object o : d.getAnnotation()) {
if (o instanceof Annotation) {
a = (Annotation) o;
}
}
assertThat(a, notNullValue());
assertThat(a.getT(), notNullValue());
assertThat(a.getT().size(), equalTo(3));
for (int i = 0; i < a.getT().size(); i++) {
Tag t = a.getT().get(i);
switch(i) {
case 0:
assertThat(t.getName(), equalTo("author"));
assertThat(t.getValue(), equalTo("Frederic Chopin"));
break;
case 1:
assertThat(t.getName(), equalTo("description"));
assertThat(t.getValue(), equalTo("This is a multi-line description that\n spans multiple lines."));
break;
case 2:
assertThat(t.getName(), equalTo("following"));
assertThat(t.getValue(), equalTo("true"));
break;
}
}
}
use of org.hl7.fhir.r5.model.Annotation in project clinical_quality_language by cqframework.
the class Cql2ElmVisitor method popChunk.
private void popChunk(ParseTree tree, Object o) {
Chunk chunk = chunks.pop();
if (o instanceof Element) {
Element element = (Element) o;
if (element.getLocalId() == null) {
element.setLocalId(Integer.toString(getNextLocalId()));
}
chunk.setElement(element);
if (!(tree instanceof cqlParser.LibraryContext)) {
if (element instanceof UsingDef || element instanceof IncludeDef || element instanceof CodeSystemDef || element instanceof ValueSetDef || element instanceof CodeDef || element instanceof ConceptDef || element instanceof ParameterDef || element instanceof ContextDef || element instanceof ExpressionDef) {
Annotation a = getAnnotation(element);
if (a == null || a.getS() == null) {
// Add header information (comments prior to the definition)
BaseInfo definitionInfo = libraryInfo.resolveDefinition(tree);
if (definitionInfo != null && definitionInfo.getHeaderInterval() != null) {
Chunk headerChunk = new Chunk().withInterval(definitionInfo.getHeaderInterval()).withIsHeaderChunk(true);
Chunk newChunk = new Chunk().withInterval(new org.antlr.v4.runtime.misc.Interval(headerChunk.getInterval().a, chunk.getInterval().b));
newChunk.addChunk(headerChunk);
newChunk.setElement(chunk.getElement());
for (Chunk c : chunk.getChunks()) {
newChunk.addChunk(c);
}
chunk = newChunk;
}
if (a == null) {
element.getAnnotation().add(buildAnnotation(chunk));
} else {
addNarrativeToAnnotation(a, chunk);
}
}
}
} else {
if (libraryInfo.getDefinition() != null && libraryInfo.getHeaderInterval() != null) {
Chunk headerChunk = new Chunk().withInterval(libraryInfo.getHeaderInterval()).withIsHeaderChunk(true);
Chunk definitionChunk = new Chunk().withInterval(libraryInfo.getDefinition().getSourceInterval());
Chunk newChunk = new Chunk().withInterval(new org.antlr.v4.runtime.misc.Interval(headerChunk.getInterval().a, definitionChunk.getInterval().b));
newChunk.addChunk(headerChunk);
newChunk.addChunk(definitionChunk);
newChunk.setElement(chunk.getElement());
chunk = newChunk;
Annotation a = getAnnotation(libraryBuilder.getLibrary());
if (a == null) {
libraryBuilder.getLibrary().getAnnotation().add(buildAnnotation(chunk));
} else {
addNarrativeToAnnotation(a, chunk);
}
}
}
}
if (!chunks.isEmpty()) {
chunks.peek().addChunk(chunk);
}
}
Aggregations