Search in sources :

Example 61 with Annotation

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;
}
Also used : BundleReturnProperties(gov.cms.dpc.fhir.annotations.BundleReturnProperties) OutputStream(java.io.OutputStream) Arrays(java.util.Arrays) Bundle(org.hl7.fhir.dstu3.model.Bundle) Produces(javax.ws.rs.Produces) Provider(javax.ws.rs.ext.Provider) FHIR(gov.cms.dpc.fhir.annotations.FHIR) Resource(org.hl7.fhir.dstu3.model.Resource) Collection(java.util.Collection) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) IOException(java.io.IOException) TypeToken(com.google.common.reflect.TypeToken) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) MediaType(javax.ws.rs.core.MediaType) List(java.util.List) Consumes(javax.ws.rs.Consumes) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) WebApplicationException(javax.ws.rs.WebApplicationException) Optional(java.util.Optional) BundleReturnProperties(gov.cms.dpc.fhir.annotations.BundleReturnProperties) FHIRMediaTypes(gov.cms.dpc.fhir.FHIRMediaTypes) Bundle(org.hl7.fhir.dstu3.model.Bundle)

Example 62 with Annotation

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);
}
Also used : OutputStream(java.io.OutputStream) Arrays(java.util.Arrays) Bundle(org.hl7.fhir.dstu3.model.Bundle) Produces(javax.ws.rs.Produces) Provider(javax.ws.rs.ext.Provider) FHIR(gov.cms.dpc.fhir.annotations.FHIR) Resource(org.hl7.fhir.dstu3.model.Resource) Collection(java.util.Collection) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) IOException(java.io.IOException) TypeToken(com.google.common.reflect.TypeToken) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) MediaType(javax.ws.rs.core.MediaType) List(java.util.List) Consumes(javax.ws.rs.Consumes) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) WebApplicationException(javax.ws.rs.WebApplicationException) Optional(java.util.Optional) BundleReturnProperties(gov.cms.dpc.fhir.annotations.BundleReturnProperties) FHIRMediaTypes(gov.cms.dpc.fhir.FHIRMediaTypes) Bundle(org.hl7.fhir.dstu3.model.Bundle)

Example 63 with Annotation

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);
        });
    }
}
Also used : Logger(org.slf4j.Logger) Resource(org.hl7.fhir.dstu3.model.Resource) DataFormatException(ca.uhn.fhir.parser.DataFormatException) Factory(org.glassfish.hk2.api.Factory) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Injector(com.google.inject.Injector) HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) Parameters(org.hl7.fhir.dstu3.model.Parameters) WebApplicationException(javax.ws.rs.WebApplicationException) FHIRParameter(gov.cms.dpc.fhir.annotations.FHIRParameter) Parameter(org.glassfish.jersey.server.model.Parameter) IParser(ca.uhn.fhir.parser.IParser) WebApplicationException(javax.ws.rs.WebApplicationException) FHIRParameter(gov.cms.dpc.fhir.annotations.FHIRParameter)

Example 64 with Annotation

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;
        }
    }
}
Also used : CompiledLibrary(org.cqframework.cql.cql2elm.model.CompiledLibrary) ExpressionDef(org.hl7.elm.r1.ExpressionDef) FunctionDef(org.hl7.elm.r1.FunctionDef) Tag(org.hl7.cql_annotations.r1.Tag) Annotation(org.hl7.cql_annotations.r1.Annotation) Test(org.testng.annotations.Test)

Example 65 with Annotation

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);
    }
}
Also used : Element(org.hl7.elm.r1.Element) Annotation(org.hl7.cql_annotations.r1.Annotation)

Aggregations

NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 Trace (com.newrelic.api.agent.Trace)13 Operation (gov.cms.bfd.server.war.Operation)13 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)12 Annotation (org.hl7.fhir.r4.model.Annotation)12 NoResultException (javax.persistence.NoResultException)11 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)9 Annotation (org.hl7.fhir.dstu3.model.Annotation)9 Search (ca.uhn.fhir.rest.annotation.Search)8 OffsetLinkBuilder (gov.cms.bfd.server.war.commons.OffsetLinkBuilder)8 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)8 Read (ca.uhn.fhir.rest.annotation.Read)7 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)7 Patient (org.hl7.fhir.dstu3.model.Patient)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)6 Resource (org.hl7.fhir.r4.model.Resource)6 Test (org.junit.jupiter.api.Test)6