Search in sources :

Example 6 with JsonWrapper

use of gov.cms.qpp.conversion.encode.JsonWrapper in project qpp-conversion-tool by CMSgov.

the class Converter method transform.

/**
 * Transform the content in a given input stream
 *
 * @param inStream source content
 * @return a transformed representation of the source content
 * @throws XmlException during transform
 */
private JsonWrapper transform(InputStream inStream) {
    Element doc = XmlUtils.parseXmlStream(inStream);
    decoded = XmlDecoderEngine.decodeXml(context, doc);
    JsonWrapper qpp = null;
    if (null != decoded) {
        DEV_LOG.info("Decoded template ID {}", decoded.getType());
        if (!context.isDoDefaults()) {
            DefaultDecoder.removeDefaultNode(decoded.getChildNodes());
        }
        if (context.isDoValidation()) {
            QrdaValidator validator = new QrdaValidator(context);
            details.addAll(validator.validate(decoded));
        }
        if (details.isEmpty()) {
            qpp = encode();
        }
    } else {
        Detail detail = Detail.forErrorCode(ErrorCode.NOT_VALID_QRDA_DOCUMENT.format(Context.REPORTING_YEAR, Context.IG_URL));
        details.add(detail);
    }
    return qpp;
}
Also used : JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) QrdaValidator(gov.cms.qpp.conversion.validate.QrdaValidator) Element(org.jdom2.Element) Detail(gov.cms.qpp.conversion.model.error.Detail)

Example 7 with JsonWrapper

use of gov.cms.qpp.conversion.encode.JsonWrapper in project qpp-conversion-tool by CMSgov.

the class QrdaServiceImplTest method successConverter.

private Converter successConverter() {
    Converter mockConverter = mock(Converter.class);
    JsonWrapper qpp = new JsonWrapper();
    qpp.putString(KEY, MOCK_SUCCESS_QPP_STRING);
    ConversionReport report = mock(ConversionReport.class);
    when(report.getEncoded()).thenReturn(qpp);
    when(mockConverter.getReport()).thenReturn(report);
    return mockConverter;
}
Also used : JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) Converter(gov.cms.qpp.conversion.Converter) ConversionReport(gov.cms.qpp.conversion.ConversionReport)

Example 8 with JsonWrapper

use of gov.cms.qpp.conversion.encode.JsonWrapper in project qpp-conversion-tool by CMSgov.

the class QrdaServiceImplTest method testConvertQrda3ToQppSuccess.

@Test
void testConvertQrda3ToQppSuccess() {
    JsonWrapper qpp = objectUnderTest.convertQrda3ToQpp(MOCK_SUCCESS_QRDA_SOURCE).getEncoded();
    assertThat(qpp.getString(KEY)).isSameAs(MOCK_SUCCESS_QPP_STRING);
}
Also used : JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) Test(org.junit.jupiter.api.Test)

Example 9 with JsonWrapper

use of gov.cms.qpp.conversion.encode.JsonWrapper in project qpp-conversion-tool by CMSgov.

the class DefaultEncoderTest method encodeAllNodes.

@Test
void encodeAllNodes() throws Exception {
    InputStream stream = NioHelper.fileToStream(Paths.get("../qrda-files/valid-QRDA-III.xml"));
    String xmlFragment = IOUtils.toString(stream, StandardCharsets.UTF_8);
    Node node = new QrdaDecoderEngine(new Context()).decode(XmlUtils.stringToDom(xmlFragment));
    Node placeHolder = new Node(TemplateId.DEFAULT, node);
    node.addChildNode(placeHolder);
    JsonWrapper wrapper = new JsonWrapper();
    new QppOutputEncoder(new Context()).encode(wrapper, node);
    assertThat(wrapper.toString().length() > 10).isTrue();
}
Also used : Context(gov.cms.qpp.conversion.Context) JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) QppOutputEncoder(gov.cms.qpp.conversion.encode.QppOutputEncoder) InputStream(java.io.InputStream) Node(gov.cms.qpp.conversion.model.Node) QrdaDecoderEngine(gov.cms.qpp.conversion.decode.QrdaDecoderEngine) Test(org.junit.jupiter.api.Test)

Example 10 with JsonWrapper

use of gov.cms.qpp.conversion.encode.JsonWrapper in project qpp-conversion-tool by CMSgov.

the class ConversionFileWriterWrapper method executeConverter.

/**
 * Execute the converter and do initial handling of the result.
 *
 * @param converter The Converter to execute.
 */
private void executeConverter(Converter converter) {
    try {
        JsonWrapper jsonWrapper = converter.transform();
        Path outFile = getOutputFile(source.getName(), true);
        DEV_LOG.info("Successful conversion.  Writing out QPP to {}", outFile.toString());
        writeOutQpp(jsonWrapper, outFile);
    } catch (TransformException exception) {
        AllErrors allErrors = exception.getDetails();
        Path outFile = getOutputFile(source.getName(), false);
        DEV_LOG.warn("There were errors during conversion.  Writing out errors to " + outFile.toString(), exception);
        writeOutErrors(allErrors, outFile);
    }
}
Also used : Path(java.nio.file.Path) JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) TransformException(gov.cms.qpp.conversion.model.error.TransformException)

Aggregations

JsonWrapper (gov.cms.qpp.conversion.encode.JsonWrapper)24 Test (org.junit.jupiter.api.Test)10 Converter (gov.cms.qpp.conversion.Converter)9 PathSource (gov.cms.qpp.conversion.PathSource)8 Node (gov.cms.qpp.conversion.model.Node)3 Map (java.util.Map)3 Path (java.nio.file.Path)2 Test (org.junit.Test)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonPath (com.jayway.jsonpath.JsonPath)1 JsonPathAggregator (gov.cms.qpp.acceptance.helper.JsonPathAggregator)1 JsonPathToXpathHelper (gov.cms.qpp.acceptance.helper.JsonPathToXpathHelper)1 Context (gov.cms.qpp.conversion.Context)1 ConversionReport (gov.cms.qpp.conversion.ConversionReport)1 QrdaDecoderEngine (gov.cms.qpp.conversion.decode.QrdaDecoderEngine)1 XmlInputFileException (gov.cms.qpp.conversion.decode.XmlInputFileException)1 EncodeException (gov.cms.qpp.conversion.encode.EncodeException)1 JsonOutputEncoder (gov.cms.qpp.conversion.encode.JsonOutputEncoder)1