NIST’s Meaningful Use Validator is great to check if your CCDs are valid. However, it runs as a Command Line Utility that outputs XML. If you want to make validation part of your unit tests, you need it to be callable from code. This project aims to do just that. NIST made its code available here. Also, they consider their code to be public domain. That makes it possible for this project to exist. I am thankful for that.
This supports the legacy CLI usage as well as programmatic usage
Download the jar from Maven Central and unzip it. Then you can use it.
# Remove any older versions
rm -rf muval-*
# Download the latest version from Maven Central
mvn dependency:unpack \
-DrepoUrl=https://repo1.maven.org/maven2/ \
-Dartifact=com.github.rahulsom:muval:LATEST:zip \
-DoutputDirectory=$PWD
# cd to the unzipped directory
cd muval-*
# Run the validator
./bin/muval -input sampleCCD.xml -output result.xmlImport the dependency using Maven, Gradle, sbt, leiningen or Ivy. The example below is for Gradle. Look up instructions for your build tool from this badge.
dependencies {
// ...
implementation 'com.github.rahulsom:muval:<VERSION>'
}Then use it in your code. This example is a JUnit 5 Test. You could use it in test or production code.
import org.junit.jupiter.api.Test;
import java.io.InputStream;
import static gov.nist.mu.validation.Rulesets.*;
import static gov.nist.mu.validation.Validator.validate;
import static org.assertj.core.api.Assertions.assertThat;
class MyCcdTest {
private InputStream file(String resourceName) {
return this.getClass().getClassLoader().getResourceAsStream(resourceName);
}
@Test
void sampleCcdShouldValidate() {
// when: "I validate a CCD"
var result = validate(Cdar2c32, file("SampleCCDDocument.xml"), Ccd, Cda4Cdt, C32_v_2_5_c83_2_0);
// then: "There are 50 errors and 98 issues"
assertThat(result.getAllIssues()).hasSize(98);
assertThat(result.getErrors()).hasSize(50);
assertThat(result.getOtherIssues()).isEmpty();
}
}The downloadResources task will do the job. You need to delete the nist directory before that.
./gradlew downloadResourcesIf you run into network problems, you may rerun that command.