Skip to content

Commit

Permalink
Add support for Questionnaire to Structure Map Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Apr 5, 2023
1 parent e774abc commit 82e4547
Show file tree
Hide file tree
Showing 9 changed files with 546 additions and 59 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ A command line utility to support FHIRCore content authoring. This tool supports

Download the latest release from https://github.com/opensrp/fhircore-tooling/releases

To run it as a java jar use the command `java -jar efsity-1.0.0.jar -h` . This is the help command and will list the available options.
To run it as a java jar by using the command `java -jar efsity-2.0.0.jar -h` . This is the help command and will list the available options.

If you are using a linux environment e.g. bash you can choose to create an _alias_ for this as shown below. _(Remember to reload the terminal)_

`alias fct='java -jar ~/Downloads/efsity-1.0.0.jar'`
`alias fct='java -jar ~/Downloads/efsity-2.0.0.jar'`

To run the previous help command you can then run `fct -h` in your terminal.

Expand Down Expand Up @@ -60,7 +60,12 @@ The above will output a list of errors and warnings based on any configuration r
-c or --composition - the composition json file of the project
-i or --input - the input directory path. This should point to the folder with the app configurations e.g. ~/Workspace/fhir-resources/ecbis_cha_preview/
-o or --output - the output path, can be a file or directory. Optional - default is current directory
-sm or --structure-maps - (Optional) the directory path to the location of structure map .txt or .map files. Must be a directory. Must be used with the -q flag
-q or --questionnaires - (Optional) the directory path to the location of questionnaires .json files. Must be a directory. Must be used with the -sm flag
```

**Note:** To include _Questionnaire_ and _Structure Map_ validation add the `-sm` and `-q` flags

**Sample screenshot output**
<br/>
<img width="715" alt="Screenshot 2023-03-27 at 21 43 09" src="https://user-images.githubusercontent.com/10017086/228037581-209f9bab-d1b9-45eb-a920-aa12c70c5b98.png">
Expand Down
70 changes: 53 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.smartregister</groupId>
<artifactId>fhircore-tooling</artifactId>
<version>1.0.0</version>
<version>2.0.0</version>

<properties>
<code.name>efsity</code.name>
Expand Down Expand Up @@ -118,22 +118,48 @@
<dependency>
<groupId>org.opencds.cqf.cql</groupId>
<artifactId>evaluator</artifactId>
<version>${opencds.cql.version}</version>
<version>${cql.version}</version>
<exclusions>
<exclusion>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>org.hl7.fhir.r5</artifactId>
</exclusion>
<exclusion>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>org.hl7.fhir.dstu2</artifactId>
</exclusion>
<exclusion>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>org.hl7.fhir.dstu3</artifactId>
</exclusion>
<exclusion>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>org.hl7.fhir.dstu2016may</artifactId>
</exclusion>
<exclusion>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu3</artifactId>
</exclusion>
<exclusion>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-r5</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.opencds.cqf.cql</groupId>
<artifactId>evaluator.builder</artifactId>
<version>${opencds.cql.version}</version>
<version>${cql.version}</version>
</dependency>
<dependency>
<groupId>org.opencds.cqf.cql</groupId>
<artifactId>evaluator.dagger</artifactId>
<version>${opencds.cql.version}</version>
<version>${cql.version}</version>
</dependency>
<dependency>
<groupId>org.opencds.cqf.cql</groupId>
<artifactId>evaluator.plandefinition</artifactId>
<version>${opencds.cql.version}</version>
<version>${cql.version}</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -291,19 +317,29 @@
</executions>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.plugin.version}</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>org.smartregister.Main</mainClass>
</manifest>
</archive>
</configuration>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>single</goal>
</goals>
<phase>package</phase>
<configuration>
<archive>
<manifest>
<mainClass>org.smartregister.Main</mainClass>
</manifest>
</archive>
<descriptors>
<descriptor>src/main/resources/dependency-set.xml</descriptor>
</descriptors>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/smartregister/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
@Command(
name = "fct",
description = "FHIRCore tooling to make content authoring easier.",
version = "1.0.0",
version = "2.0.0",
mixinStandardHelpOptions = true,
subcommands = {
ConvertCommand.class,
StructureMapExtractResourcesCommand.class,
ValidateCommand.class
})
public class Main implements Runnable {
public static final String VERSION = "1.0.0";
public static final String VERSION = "2.0.0";

@CommandLine.Option(
names = {"-v"},
Expand Down
40 changes: 38 additions & 2 deletions src/main/java/org/smartregister/command/ValidateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,53 @@ public class ValidateCommand implements Runnable {
required = true)
private String compositionFilePath;

@CommandLine.Option(
names = {"-sm", "--structure-maps"},
description =
"directory path to the location of structure map .txt or .map files. Must be a directory. Must be used with the -q flag",
required = false)
private String structureMapsFolderPath;

@CommandLine.Option(
names = {"-q", "--questionnaires"},
description =
"directory path to the location of questionnaires .json files. Must be a directory. Must be used with the -sm flag",
required = false)
private String questionnairesFolderPath;

@Override
public void run() {

if (!Files.isDirectory(Paths.get(inputFolder))) {
throw new RuntimeException("path needs to be a directory");
throw new RuntimeException("-i, --input configs input path needs to be a directory");
}

if (structureMapsFolderPath != null && questionnairesFolderPath == null) {

throw new RuntimeException(
"You have supplied a -sm, --structure-maps flag without a corresponding -q, --questionnaires flag");

} else if (structureMapsFolderPath == null && questionnairesFolderPath != null) {
throw new RuntimeException(
"You have supplied a -q, --questionnaires flag without a corresponding -sm, --structure-maps flag");
}

if (structureMapsFolderPath != null) {

if (!Files.isDirectory(Paths.get(structureMapsFolderPath))) {
throw new RuntimeException("-sm, --structure-maps path needs to be a directory");
}

if (!Files.isDirectory(Paths.get(questionnairesFolderPath))) {
throw new RuntimeException("-q, --questionnaires path needs to be a directory");
}
}

try {

FCTValidationEngine FCTValidationEngine = new FCTValidationEngine();
FCTValidationEngine.process(compositionFilePath, inputFolder);
FCTValidationEngine.process(
compositionFilePath, structureMapsFolderPath, questionnairesFolderPath, inputFolder);

} catch (IOException e) {
logger.severe(e.getMessage());
Expand Down
32 changes: 29 additions & 3 deletions src/main/java/org/smartregister/util/FCTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.smartregister.domain.FCTFile;

Expand Down Expand Up @@ -123,6 +124,31 @@ public static void printCompletedInDuration(long startTime) {
FCTUtils.getHumanDuration(System.currentTimeMillis() - startTime)));
}

public static Map<String, Map<String, String>> indexConfigurationFiles(String inputDirectoryPath)
throws IOException {
Map<String, Map<String, String>> filesMap = new HashMap<>();
Path rootDir = Paths.get(inputDirectoryPath);
Files.walkFileTree(
rootDir,
new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (!Files.isDirectory(file)) {

String parentDirKey =
file.getParent().equals(rootDir)
? FCTValidationEngine.Constants.ROOT
: file.getParent().getFileName().toString();
Map<String, String> fileList = filesMap.getOrDefault(parentDirKey, new HashMap<>());
fileList.put(file.getFileName().toString(), file.toAbsolutePath().toString());
filesMap.put(parentDirKey, fileList);
}
return FileVisitResult.CONTINUE;
}
});
return filesMap;
}

public static final class Constants {
public static final String HL7_FHIR_PACKAGE = "hl7.fhir.r4.core";
public static final String HL7_FHIR_PACKAGE_VERSION = "4.0.1";
Expand Down
Loading

0 comments on commit 82e4547

Please sign in to comment.