Search in sources :

Example 91 with Context

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

the class MeasureDataRoundTripTest method test.

private void test(SubPopulationLabel type) throws Exception {
    // setup
    String typeLabel = type.name();
    Node placeholder = new QrdaDecoderEngine(new Context()).decode(XmlUtils.stringToDom(happy));
    Node measure = placeholder.findChildNode(n -> n.getValue(MEASURE_TYPE).equals(typeLabel));
    // when
    StringWriter sw = encode(placeholder);
    // then
    assertThat(measure).isNotNull();
    assertThat(measure.getChildNodes().get(0).getType()).isEquivalentAccordingToCompareTo(TemplateId.ACI_AGGREGATE_COUNT);
    assertThat(sw.toString()).isEqualTo(expected);
}
Also used : Context(gov.cms.qpp.conversion.Context) StringWriter(java.io.StringWriter) Node(gov.cms.qpp.conversion.model.Node) QrdaDecoderEngine(gov.cms.qpp.conversion.decode.QrdaDecoderEngine)

Example 92 with Context

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

the class MeasureDataRoundTripTest method encode.

private StringWriter encode(Node placeholder) throws EncodeException {
    QppOutputEncoder encoder = new QppOutputEncoder(new Context());
    List<Node> nodes = new ArrayList<>();
    nodes.add(placeholder);
    encoder.setNodes(nodes);
    StringWriter sw = new StringWriter();
    encoder.encode(new BufferedWriter(sw));
    return sw;
}
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) BufferedWriter(java.io.BufferedWriter)

Example 93 with Context

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

the class AciNumeratorDenominatorDecoderTest method decodeAciNumeratorDenominatorNullValueAsNode.

@Test
void decodeAciNumeratorDenominatorNullValueAsNode() throws Exception {
    String xmlFragment = XmlUtils.buildString("<root xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"urn:hl7-org:v3\" >", "  <observation classCode=\"OBS\" moodCode=\"EVN\">", "    <templateId root=\"2.16.840.1.113883.10.20.27.3.3\"/>", "    <value xsi:type=\"INT\"/>", "  </observation>", "</root>");
    Node numDenomNode = new QrdaDecoderEngine(new Context()).decode(XmlUtils.stringToDom(xmlFragment));
    assertWithMessage("aci numerator/denominator value should be null").that(numDenomNode.getChildNodes().get(0).getValue("aggregateCount")).isNull();
}
Also used : Context(gov.cms.qpp.conversion.Context) Node(gov.cms.qpp.conversion.model.Node) Test(org.junit.jupiter.api.Test)

Example 94 with Context

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

the class AciNumeratorDenominatorDecoderTest method testInternalDecode.

@Test
void testInternalDecode() {
    // set-up
    Namespace rootns = Namespace.getNamespace("urn:hl7-org:v3");
    Namespace ns = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    Element element = new Element("organizer", rootns);
    Element templateIdElement = new Element("templateId", rootns).setAttribute("root", "2.16.840.1.113883.10.20.27.3.28");
    Element referenceElement = new Element("reference", rootns);
    Element externalDocumentElement = new Element("externalDocument", rootns);
    Element idElement = new Element("id", rootns).setAttribute("extension", MEASURE_ID);
    externalDocumentElement.addContent(idElement);
    referenceElement.addContent(externalDocumentElement);
    element.addContent(templateIdElement);
    element.addContent(referenceElement);
    element.addNamespaceDeclaration(ns);
    Node thisNode = new Node();
    AciNumeratorDenominatorDecoder objectUnderTest = new AciNumeratorDenominatorDecoder(new Context());
    objectUnderTest.setNamespace(element.getNamespace());
    // execute
    objectUnderTest.decode(element, thisNode);
    // assert
    assertThat(thisNode.getValue("measureId")).isEqualTo(MEASURE_ID);
}
Also used : Context(gov.cms.qpp.conversion.Context) Element(org.jdom2.Element) Node(gov.cms.qpp.conversion.model.Node) Namespace(org.jdom2.Namespace) Test(org.junit.jupiter.api.Test)

Example 95 with Context

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

the class AciNumeratorDenominatorDecoderTest method decodeValidAciNumeratorDenominatorTest.

@Test
void decodeValidAciNumeratorDenominatorTest() throws XmlException {
    Node aciMeasureNode = new QrdaDecoderEngine(new Context()).decode(XmlUtils.stringToDom(getValidXmlFragment()));
    Node numeratorDenominatorNode = aciMeasureNode.getChildNodes().get(0);
    int numberNodes = countNodes(aciMeasureNode);
    List<Node> nodeList = aciMeasureNode.findNode(TemplateId.ACI_NUMERATOR);
    assertThat(numeratorDenominatorNode.getValue("measureId")).isEqualTo(MEASURE_ID);
    assertThat(numeratorDenominatorNode.getChildNodes().get(0).getType()).isEqualTo(TemplateId.ACI_NUMERATOR);
    assertThat(numeratorDenominatorNode.getChildNodes().get(1).getType()).isEqualTo(TemplateId.ACI_DENOMINATOR);
    nodeList = nodeList.get(0).findNode(TemplateId.ACI_AGGREGATE_COUNT);
    assertWithMessage("Decoded xml fragment %s should contain %s", TemplateId.ACI_NUMERATOR.name(), TemplateId.ACI_AGGREGATE_COUNT.name()).that(nodeList).hasSize(1);
    nodeList = aciMeasureNode.findNode(TemplateId.ACI_DENOMINATOR);
    assertWithMessage("Decoded xml fragment should contain %s", TemplateId.ACI_DENOMINATOR.name()).that(nodeList).hasSize(1);
    nodeList = nodeList.get(0).findNode(TemplateId.ACI_AGGREGATE_COUNT);
    assertWithMessage("Decoded xml fragment %s should contain %s", TemplateId.ACI_NUMERATOR.name(), TemplateId.ACI_AGGREGATE_COUNT.name()).that(nodeList).hasSize(1);
    assertWithMessage("Decoded xml fragment %s should contain 6 nodes", aciMeasureNode.getType().name()).that(numberNodes).isEqualTo(6);
    assertWithMessage("measureId should be %s", MEASURE_ID).that(numeratorDenominatorNode.getValue("measureId")).isEqualTo(MEASURE_ID);
}
Also used : Context(gov.cms.qpp.conversion.Context) Node(gov.cms.qpp.conversion.model.Node) Test(org.junit.jupiter.api.Test)

Aggregations

Context (gov.cms.qpp.conversion.Context)114 Test (org.junit.jupiter.api.Test)92 Node (gov.cms.qpp.conversion.model.Node)63 BufferedWriter (java.io.BufferedWriter)17 StringWriter (java.io.StringWriter)17 QrdaDecoderEngine (gov.cms.qpp.conversion.decode.QrdaDecoderEngine)14 Element (org.jdom2.Element)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 QppOutputEncoder (gov.cms.qpp.conversion.encode.QppOutputEncoder)8 ArrayList (java.util.ArrayList)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 TemplateId (gov.cms.qpp.conversion.model.TemplateId)4 Detail (gov.cms.qpp.conversion.model.error.Detail)4 InputStream (java.io.InputStream)4 Namespace (org.jdom2.Namespace)4 Map (java.util.Map)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 Converter (gov.cms.qpp.conversion.Converter)2 PathSource (gov.cms.qpp.conversion.PathSource)2 ComponentKey (gov.cms.qpp.conversion.model.ComponentKey)2