Search in sources :

Example 1 with QppOutputEncoder

use of gov.cms.qpp.conversion.encode.QppOutputEncoder 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 2 with QppOutputEncoder

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

the class AciNumeratorDenominatorRoundTripTest method parseAciNumeratorDenominatorAsNode.

@Test
void parseAciNumeratorDenominatorAsNode() throws Exception {
    String xmlFragment = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<entry xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:hl7-org:v3\">\n" + "	<organizer classCode=\"CLUSTER\" moodCode=\"EVN\">\n" + "		<!-- Implied template Measure Reference templateId -->\n" + "		<!-- ACI Numerator Denominator Type Measure Reference and Results templateId -->\n" + "		<templateId root=\"2.16.840.1.113883.10.20.27.3.28\" extension=\"2017-06-01\"/>\n" + "		<id root=\"ac575aef-7062-4ea2-b723-df517cfa470a\"/>\n" + "		<statusCode code=\"completed\"/>\n" + "		<reference typeCode=\"REFR\">\n" + "			<!-- Reference to a particular ACI measure's unique identifier. -->\n" + "			<externalDocument classCode=\"DOC\" moodCode=\"EVN\">\n" + "				<!-- This is a temporary root OID that indicates this is an ACI measure identifier -->\n" + "				<!-- extension is the unique identifier for an ACI measure. \"ACI-PEA-1\" is for illustration only. -->\n" + "				<id root=\"2.16.840.1.113883.3.7031\" extension=\"ACI-PEA-1\"/>\n" + "				<!-- ACI measure title -->\n" + "				<text>Patient Access</text>\n" + "			</externalDocument>\n" + "		</reference>\n" + "		<component>\n" + "			<observation classCode=\"OBS\" moodCode=\"EVN\">\n" + "				<!-- Performance Rate templateId -->\n" + "				<templateId root=\"2.16.840.1.113883.10.20.27.3.30\"\n" + "					extension=\"2016-09-01\"/>\n" + "				<code code=\"72510-1\" codeSystem=\"2.16.840.1.113883.6.1\" codeSystemName=\"LOINC\" displayName=\"Performance Rate\"/>\n" + "				<statusCode code=\"completed\"/>\n" + "				<value xsi:type=\"REAL\" value=\"0.750000\"/>\n" + "			</observation>\n" + "		</component>\n" + "		<component>\n" + "			<observation classCode=\"OBS\" moodCode=\"EVN\">\n" + "				<!-- ACI Numerator Denominator Type Measure Numerator Data templateId -->\n" + "				<templateId root=\"2.16.840.1.113883.10.20.27.3.31\"\n" + "					extension=\"2016-09-01\"/>\n" + "				<code code=\"ASSERTION\" codeSystem=\"2.16.840.1.113883.5.4\"\n" + "					codeSystemName=\"ActCode\" displayName=\"Assertion\"/>\n" + "				<statusCode code=\"completed\"/>\n" + "				<value xsi:type=\"CD\" code=\"NUMER\"\n" + "					codeSystem=\"2.16.840.1.113883.5.4\" codeSystemName=\"ActCode\"/>\n" + "				<!-- Numerator Count-->\n" + "				<entryRelationship typeCode=\"SUBJ\" inversionInd=\"true\">\n" + "					<observation classCode=\"OBS\" moodCode=\"EVN\">\n" + "						<templateId root=\"2.16.840.1.113883.10.20.27.3.3\"/>\n" + "						<code code=\"MSRAGG\" codeSystem=\"2.16.840.1.113883.5.4\"\n" + "							codeSystemName=\"ActCode\"\n" + "							displayName=\"rate aggregation\"/>\n" + "						<statusCode code=\"completed\"/>\n" + "						<value xsi:type=\"INT\" value=\"600\"/>\n" + "						<methodCode code=\"COUNT\"\n" + "							codeSystem=\"2.16.840.1.113883.5.84\"\n" + "							codeSystemName=\"ObservationMethod\"\n" + "							displayName=\"Count\"/>\n" + "					</observation>\n" + "				</entryRelationship>\n" + "			</observation>\n" + "		</component>\n" + "		<component>\n" + "			<observation classCode=\"OBS\" moodCode=\"EVN\">\n" + "				<!-- ACI Numerator Denominator Type Measure Denominator Data templateId -->\n" + "				<templateId root=\"2.16.840.1.113883.10.20.27.3.32\"\n" + "					extension=\"2016-09-01\"/>\n" + "				<code code=\"ASSERTION\" codeSystem=\"2.16.840.1.113883.5.4\"\n" + "					codeSystemName=\"ActCode\" displayName=\"Assertion\"/>\n" + "				<statusCode code=\"completed\"/>\n" + "				<value xsi:type=\"CD\" code=\"DENOM\"\n" + "					codeSystem=\"2.16.840.1.113883.5.4\" codeSystemName=\"ActCode\"/>\n" + "				<!-- Denominator Count-->\n" + "				<entryRelationship typeCode=\"SUBJ\" inversionInd=\"true\">\n" + "					<observation classCode=\"OBS\" moodCode=\"EVN\">\n" + "						<templateId root=\"2.16.840.1.113883.10.20.27.3.3\"/>\n" + "						<code code=\"MSRAGG\" codeSystem=\"2.16.840.1.113883.5.4\"\n" + "							codeSystemName=\"ActCode\"\n" + "							displayName=\"rate aggregation\"/>\n" + "						<statusCode code=\"completed\"/>\n" + "						<value xsi:type=\"INT\" value=\"800\"/>\n" + "						<methodCode code=\"COUNT\"\n" + "							codeSystem=\"2.16.840.1.113883.5.84\"\n" + "							codeSystemName=\"ObservationMethod\"\n" + "							displayName=\"Count\"/>\n" + "					</observation>\n" + "				</entryRelationship>\n" + "			</observation>\n" + "		</component>\n" + "	</organizer>\n" + "</entry>";
    Context context = new Context();
    Node numeratorDenominatorNode = new QrdaDecoderEngine(context).decode(XmlUtils.stringToDom(xmlFragment));
    // remove default nodes (will fail if defaults change)
    DefaultDecoder.removeDefaultNode(numeratorDenominatorNode.getChildNodes());
    String xPathExpected = "/*[local-name() = 'entry' and namespace-uri() = 'urn:hl7-org:v3']/*[local-name() = 'organizer' " + "and namespace-uri() = 'urn:hl7-org:v3']";
    QppOutputEncoder encoder = new QppOutputEncoder(context);
    List<Node> nodes = new ArrayList<>();
    nodes.add(numeratorDenominatorNode);
    encoder.setNodes(nodes);
    StringWriter sw = new StringWriter();
    encoder.encode(new BufferedWriter(sw));
    String jsonExpected = "{\n  \"measureId\" : \"ACI-PEA-1\",\n  \"value\" : {\n    \"numerator\" : 600,\n    \"denominator\" : 800\n  }\n}";
    assertWithMessage("The XPath of the numerator denominator node is incorrect").that(numeratorDenominatorNode.getChildNodes().get(0).getPath()).isEqualTo(xPathExpected);
    assertWithMessage("expected encoder to return a representation of a measure").that(sw.toString()).isEqualTo(jsonExpected);
}
Also used : Context(gov.cms.qpp.conversion.Context) QppOutputEncoder(gov.cms.qpp.conversion.encode.QppOutputEncoder) StringWriter(java.io.StringWriter) Node(gov.cms.qpp.conversion.model.Node) ArrayList(java.util.ArrayList) QrdaDecoderEngine(gov.cms.qpp.conversion.decode.QrdaDecoderEngine) BufferedWriter(java.io.BufferedWriter) Test(org.junit.jupiter.api.Test)

Example 3 with QppOutputEncoder

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

the class AciProportionNumeratorRoundTripTest method parseAciNumeratorDenominatorAsNode.

@Test
void parseAciNumeratorDenominatorAsNode() throws Exception {
    String xmlFragment = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<component xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:hl7-org:v3\">\n" + "	<observation classCode=\"OBS\" moodCode=\"EVN\">\n" + "		<templateId root=\"2.16.840.1.113883.10.20.27.3.31\" extension=\"2016-09-01\" />\n" + "		<code code=\"ASSERTION\" codeSystem=\"2.16.840.1.113883.5.4\" codeSystemName=\"ActCode\" displayName=\"Assertion\" />\n" + "		<statusCode code=\"completed\" />\n" + "		<value xsi:type=\"CD\" code=\"NUMER\" codeSystem=\"2.16.840.1.113883.5.4\" codeSystemName=\"ActCode\" />\n" + "		<!-- Numerator Count -->\n" + "		<entryRelationship typeCode=\"SUBJ\" inversionInd=\"true\">\n" + "			<observation classCode=\"OBS\" moodCode=\"EVN\">\n" + "				<templateId root=\"2.16.840.1.113883.10.20.27.3.3\" />\n" + "				<code code=\"MSRAGG\" codeSystem=\"2.16.840.1.113883.5.4\" codeSystemName=\"ActCode\" displayName=\"rate aggregation\" />\n" + "				<statusCode code=\"completed\" />\n" + "				<value xsi:type=\"INT\" value=\"600\" />\n" + "				<methodCode code=\"COUNT\" codeSystem=\"2.16.840.1.113883.5.84\" codeSystemName=\"ObservationMethod\" displayName=\"Count\" />\n" + "			</observation>\n" + "		</entryRelationship>\n" + "	</observation>\n" + "</component>";
    Context context = new Context();
    Node numDenomNode = new QrdaDecoderEngine(context).decode(XmlUtils.stringToDom(xmlFragment));
    QppOutputEncoder encoder = new QppOutputEncoder(context);
    List<Node> nodes = new ArrayList<>();
    nodes.add(numDenomNode);
    encoder.setNodes(nodes);
    StringWriter sw = new StringWriter();
    encoder.encode(new BufferedWriter(sw));
    String EXPECTED = "{\n  \"numerator\" : 600\n}";
    assertThat(sw.toString()).isEqualTo(EXPECTED);
}
Also used : Context(gov.cms.qpp.conversion.Context) QppOutputEncoder(gov.cms.qpp.conversion.encode.QppOutputEncoder) StringWriter(java.io.StringWriter) Node(gov.cms.qpp.conversion.model.Node) ArrayList(java.util.ArrayList) QrdaDecoderEngine(gov.cms.qpp.conversion.decode.QrdaDecoderEngine) BufferedWriter(java.io.BufferedWriter) Test(org.junit.jupiter.api.Test)

Example 4 with QppOutputEncoder

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

the class AciSectionRoundTripTest method parseAciSectionAsJson.

@Test
void parseAciSectionAsJson() throws EncodeException, XmlException {
    String xmlFragment = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<component xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:hl7-org:v3\">\n" + "	<section>\n" + "		<!-- Measure Section -->\n" + "		<templateId root=\"2.16.840.1.113883.10.20.24.2.2\"/>\n" + "		<!-- Advancing Care Information Section templateId -->\n" + "		<templateId root=\"2.16.840.1.113883.10.20.27.2.5\" extension=\"2017-06-01\"/>\n" + "		<code code=\"55186-1\" codeSystem=\"2.16.840.1.113883.6.1\" displayName=\"Measure Section\"/>\n" + "		<title>Measure Section</title>\n" + "		<text>\n" + "		</text>\n" + "		<entry>\n" + "			<qed resultName=\"measure\" resultValue=\"measure1\">\n" + "				<templateId root=\"Q.E.D\"/>\n" + "			</qed>" + "		</entry>\n" + "		<entry typeCode=\"DRIV\">" + "			<act classCode=\"ACT\" moodCode=\"EVN\">" + "				<templateId root=\"2.16.840.1.113883.10.20.17.3.8\"/>" + "				<id root=\"00b669fd-fa4d-4f5c-b109-65c6bbbf73ae\"/>" + "				<code code=\"252116004\" codeSystem=\"2.16.840.1.113883.6.96\"" + "					displayName=\"Observation Parameters\"/>" + "				<effectiveTime>" + "					<low value=\"20170101\"/>" + "					<high value=\"20170430\"/>" + "				</effectiveTime>" + "			</act>" + "		</entry>" + "	</section>\n" + "</component>";
    String expected = "{\n  \"category\" : \"aci\",\n  \"submissionMethod\" : \"electronicHealthRecord\",\n  \"measurements\" : [ {\n    \"measure\" : \"measure1\"\n  } ],\n  \"performanceStart\" : \"2017-01-01\",\n  \"performanceEnd\" : \"2017-04-30\"\n}";
    Context context = new Context();
    // Decode
    Node measureNode = new QrdaDecoderEngine(context).decode(XmlUtils.stringToDom(xmlFragment));
    // remove default nodes (will fail if defaults change)
    DefaultDecoder.removeDefaultNode(measureNode.getChildNodes());
    // Encode
    QppOutputEncoder encoder = new QppOutputEncoder(context);
    List<Node> nodes = new ArrayList<>();
    nodes.add(measureNode);
    encoder.setNodes(nodes);
    StringWriter sw = new StringWriter();
    encoder.encode(new BufferedWriter(sw));
    // Test
    assertThat(sw.toString()).isEqualTo(expected);
}
Also used : Context(gov.cms.qpp.conversion.Context) QppOutputEncoder(gov.cms.qpp.conversion.encode.QppOutputEncoder) StringWriter(java.io.StringWriter) Node(gov.cms.qpp.conversion.model.Node) ArrayList(java.util.ArrayList) QrdaDecoderEngine(gov.cms.qpp.conversion.decode.QrdaDecoderEngine) BufferedWriter(java.io.BufferedWriter) Test(org.junit.jupiter.api.Test)

Example 5 with QppOutputEncoder

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

the class ConverterTest method testEncodingExceptions.

@Test
@PrepareForTest({ Converter.class, QppOutputEncoder.class })
public void testEncodingExceptions() throws Exception {
    QppOutputEncoder encoder = mock(QppOutputEncoder.class);
    whenNew(QppOutputEncoder.class).withAnyArguments().thenReturn(encoder);
    EncodeException ex = new EncodeException("mocked", new RuntimeException());
    doThrow(ex).when(encoder).encode();
    Path path = Paths.get("src/test/resources/converter/defaultedNode.xml");
    Converter converter = new Converter(new PathSource(path));
    converter.getContext().setDoDefaults(false);
    converter.getContext().setDoValidation(false);
    try {
        converter.transform();
        fail();
    } catch (TransformException exception) {
        checkup(exception, ErrorCode.NOT_VALID_XML_DOCUMENT);
    }
}
Also used : Path(java.nio.file.Path) QppOutputEncoder(gov.cms.qpp.conversion.encode.QppOutputEncoder) TransformException(gov.cms.qpp.conversion.model.error.TransformException) EncodeException(gov.cms.qpp.conversion.encode.EncodeException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

QppOutputEncoder (gov.cms.qpp.conversion.encode.QppOutputEncoder)9 Context (gov.cms.qpp.conversion.Context)8 Node (gov.cms.qpp.conversion.model.Node)8 BufferedWriter (java.io.BufferedWriter)7 StringWriter (java.io.StringWriter)7 Test (org.junit.jupiter.api.Test)7 QrdaDecoderEngine (gov.cms.qpp.conversion.decode.QrdaDecoderEngine)6 ArrayList (java.util.ArrayList)6 InputStream (java.io.InputStream)2 EncodeException (gov.cms.qpp.conversion.encode.EncodeException)1 JsonWrapper (gov.cms.qpp.conversion.encode.JsonWrapper)1 TransformException (gov.cms.qpp.conversion.model.error.TransformException)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1