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;
}
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;
}
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);
}
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();
}
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);
}
}
Aggregations