Search in sources :

Example 1 with TemplateId

use of gov.cms.qpp.conversion.model.TemplateId in project qpp-conversion-tool by CMSgov.

the class AciSectionEncoder method encodeChildren.

/**
 * Encodes the children of the given section
 *
 * @param children child nodes of the given section
 * @param measurementsWrapper wrapper that holds the measurements of a section
 */
private void encodeChildren(List<Node> children, JsonWrapper measurementsWrapper) {
    JsonWrapper childWrapper;
    for (Node currentChild : children) {
        childWrapper = new JsonWrapper();
        TemplateId templateId = currentChild.getType();
        if (TemplateId.REPORTING_PARAMETERS_ACT != templateId) {
            JsonOutputEncoder childEncoder = encoders.get(templateId);
            if (childEncoder != null) {
                childEncoder.encode(childWrapper, currentChild);
                measurementsWrapper.putObject(childWrapper);
            } else {
                Detail detail = Detail.forErrorCode(ErrorCode.ENCODER_MISSING);
                detail.setPath(currentChild.getPath());
                addValidationError(detail);
            }
        }
    }
}
Also used : Node(gov.cms.qpp.conversion.model.Node) TemplateId(gov.cms.qpp.conversion.model.TemplateId) Detail(gov.cms.qpp.conversion.model.error.Detail)

Example 2 with TemplateId

use of gov.cms.qpp.conversion.model.TemplateId in project qpp-conversion-tool by CMSgov.

the class ClinicalDocumentEncoder method encodeMeasurementSets.

/**
 * Method for encoding each child measurement set
 *
 * @param childMapByTemplateId object that represents the document's children
 * @return encoded measurement sets
 */
private JsonWrapper encodeMeasurementSets(Map<TemplateId, Node> childMapByTemplateId) {
    JsonWrapper measurementSetsWrapper = new JsonWrapper();
    JsonWrapper childWrapper;
    JsonOutputEncoder sectionEncoder;
    for (Node child : childMapByTemplateId.values()) {
        TemplateId childType = child.getType();
        try {
            childWrapper = new JsonWrapper();
            sectionEncoder = encoders.get(childType);
            sectionEncoder.encode(childWrapper, child);
            measurementSetsWrapper.putObject(childWrapper);
        } catch (NullPointerException exc) {
            String message = "An unexpected error occured for " + child.getType();
            throw new EncodeException(message, exc);
        }
    }
    return measurementSetsWrapper;
}
Also used : Node(gov.cms.qpp.conversion.model.Node) TemplateId(gov.cms.qpp.conversion.model.TemplateId)

Example 3 with TemplateId

use of gov.cms.qpp.conversion.model.TemplateId in project qpp-conversion-tool by CMSgov.

the class EncoderTest method decodeTemplateIds.

/**
 * decodeTemplateIds for each TemplateId in the list ensure that it exists in
 * the registry.
 * @throws Exception
 */
@Test
void decodeTemplateIds() throws Exception {
    Registry<OutputEncoder> registry = new Registry<>(new Context(), Encoder.class);
    for (TemplateId templateId : templateIds) {
        OutputEncoder encoder = registry.get(templateId);
        assertWithMessage(templateId + " returned node should not be null").that(encoder).isNotNull();
    }
}
Also used : Context(gov.cms.qpp.conversion.Context) Registry(gov.cms.qpp.conversion.model.Registry) TemplateId(gov.cms.qpp.conversion.model.TemplateId) Test(org.junit.jupiter.api.Test)

Example 4 with TemplateId

use of gov.cms.qpp.conversion.model.TemplateId in project qpp-conversion-tool by CMSgov.

the class QrdaDecoderEngine method getDecoder.

/**
 * Retrieve a permitted {@link Decoder}. {@link #scope} is used to determine which DECODERS are allowable.
 *
 * @param templateId string representation of a would be decoder's template id
 * @return decoder that corresponds to the given template id
 */
private QrdaDecoder getDecoder(TemplateId templateId) {
    QrdaDecoder qppDecoder = decoders.get(templateId);
    if (qppDecoder != null) {
        if (scope == null) {
            return qppDecoder;
        }
        Decoder decoder = qppDecoder.getClass().getAnnotation(Decoder.class);
        TemplateId template = decoder == null ? TemplateId.DEFAULT : decoder.value();
        return !scope.contains(template) ? null : qppDecoder;
    }
    return null;
}
Also used : Decoder(gov.cms.qpp.conversion.model.Decoder) TemplateId(gov.cms.qpp.conversion.model.TemplateId)

Example 5 with TemplateId

use of gov.cms.qpp.conversion.model.TemplateId in project qpp-conversion-tool by CMSgov.

the class QrdaDecoderEngine method containsClinicalDocumentTemplateId.

/**
 * Checks whether the element has a child {@code templateId} element that is the Clinical Document {@link TemplateId}.
 *
 * @param rootElement The element to check.
 * @return True or false.
 */
private boolean containsClinicalDocumentTemplateId(Element rootElement) {
    boolean containsTemplateId = false;
    List<Element> clinicalDocumentChildren = rootElement.getChildren(TEMPLATE_ID, rootElement.getNamespace());
    for (Element currentChild : clinicalDocumentChildren) {
        TemplateId templateId = getTemplateId(currentChild);
        if (templateId == TemplateId.CLINICAL_DOCUMENT) {
            containsTemplateId = true;
            break;
        }
    }
    return containsTemplateId;
}
Also used : Element(org.jdom2.Element) TemplateId(gov.cms.qpp.conversion.model.TemplateId)

Aggregations

TemplateId (gov.cms.qpp.conversion.model.TemplateId)8 Node (gov.cms.qpp.conversion.model.Node)3 Context (gov.cms.qpp.conversion.Context)2 Registry (gov.cms.qpp.conversion.model.Registry)2 Element (org.jdom2.Element)2 Test (org.junit.jupiter.api.Test)2 DecodeData (gov.cms.qpp.conversion.model.DecodeData)1 Decoder (gov.cms.qpp.conversion.model.Decoder)1 Detail (gov.cms.qpp.conversion.model.error.Detail)1