From 2eca4ce6165824fb3c22147a80d670fe30cd7e9d Mon Sep 17 00:00:00 2001 From: Malo Toudic <mtc@kereval.com> Date: Fri, 29 Nov 2024 13:56:40 +0100 Subject: [PATCH] GOC-238 --- .../validator-archetype-instantiator/pom.xml | 2 +- .../validator-archetype/pom.xml | 2 +- hl7templates/goc-tests/pom.xml | 2 +- .../ehdsi/scripts/EHDSIL1Transformer.java | 48 +++++++++++++++++++ .../ehdsi/scripts/EHDSIL3Transformer.java | 48 +++++++++++++++++++ .../ehdsi/scripts/TemplateL1Processor.java | 28 +++++++++++ .../ehdsi/scripts/TemplateL1Provider.java | 24 ++++++++++ .../ehdsi/scripts/TemplateL3Processor.java | 32 +++++++++++++ .../ehdsi/scripts/TemplateL3Provider.java | 24 ++++++++++ .../adapters/scripts/EHDSITransformers.java | 31 +++++++++--- .../assemble-scripts/eHDSIGeneration.sh | 36 +++++++------- 11 files changed, 250 insertions(+), 27 deletions(-) create mode 100644 hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/EHDSIL1Transformer.java create mode 100644 hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/EHDSIL3Transformer.java create mode 100644 hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL1Processor.java create mode 100644 hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL1Provider.java create mode 100644 hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL3Processor.java create mode 100644 hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL3Provider.java diff --git a/archetype/generated-validator/validator-archetype-instantiator/pom.xml b/archetype/generated-validator/validator-archetype-instantiator/pom.xml index 3f1e5e4..9fdf838 100644 --- a/archetype/generated-validator/validator-archetype-instantiator/pom.xml +++ b/archetype/generated-validator/validator-archetype-instantiator/pom.xml @@ -11,4 +11,4 @@ <version>3.2.3-SNAPSHOT</version> <packaging>jar</packaging> -</project> \ No newline at end of file +</project> diff --git a/archetype/generated-validator/validator-archetype/pom.xml b/archetype/generated-validator/validator-archetype/pom.xml index 7463f26..9a6baf5 100644 --- a/archetype/generated-validator/validator-archetype/pom.xml +++ b/archetype/generated-validator/validator-archetype/pom.xml @@ -19,4 +19,4 @@ </extension> </extensions> </build> -</project> \ No newline at end of file +</project> diff --git a/hl7templates/goc-tests/pom.xml b/hl7templates/goc-tests/pom.xml index b2266e9..1f14c49 100644 --- a/hl7templates/goc-tests/pom.xml +++ b/hl7templates/goc-tests/pom.xml @@ -43,4 +43,4 @@ -</project> \ No newline at end of file +</project> diff --git a/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/EHDSIL1Transformer.java b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/EHDSIL1Transformer.java new file mode 100644 index 0000000..4b647c5 --- /dev/null +++ b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/EHDSIL1Transformer.java @@ -0,0 +1,48 @@ +package net.ihe.gazelle.tempgen.ehdsi.scripts; + +import net.ihe.gazelle.tempapi.visitor.DecorVisitor; +import net.ihe.gazelle.tempmodel.org.decor.art.model.Decor; +import net.ihe.gazelle.tempmodel.org.decor.art.model.TemplateDefinition; +import net.ihe.gazelle.tempmodel.org.decor.art.utils.DecorMarshaller; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.xml.bind.JAXBException; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.util.ArrayList; + +public class EHDSIL1Transformer { + + private static Logger log = LoggerFactory.getLogger(EHDSIL1Transformer.class); + + public static ArrayList<TemplateDefinition> templatesToDelete = new ArrayList<>(); + + public static void main(String[] args) throws FileNotFoundException, JAXBException { + + String bbrPath = "DEFINE_YOUR_DEFAULT_PATH_HERE"; + String outputBbrPath = "DEFINE_YOUR_OUT_PATH_HERE"; + + //Override input bbr path if exists as param + if (args.length > 0) { + bbrPath = args[0]; + } + + //Override output bbr path if exists as param + if (args.length > 1) { + outputBbrPath = args[1]; + } + + Decor dec = DecorMarshaller.loadDecor(bbrPath); + DecorVisitor.INSTANCE.visitAndProcess(dec, new TemplateL1Provider()); + + for (TemplateDefinition template : templatesToDelete) { + if (template.getId() != null && !template.getId().isEmpty() && template.getParentObject() != null) { + template.getParentObject().getTemplateAssociationOrTemplate().remove(template); + } + } + + DecorMarshaller.marshallDecor(dec, new FileOutputStream(outputBbrPath)); + } + +} diff --git a/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/EHDSIL3Transformer.java b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/EHDSIL3Transformer.java new file mode 100644 index 0000000..cb1fbe3 --- /dev/null +++ b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/EHDSIL3Transformer.java @@ -0,0 +1,48 @@ +package net.ihe.gazelle.tempgen.ehdsi.scripts; + +import net.ihe.gazelle.tempapi.visitor.DecorVisitor; +import net.ihe.gazelle.tempmodel.org.decor.art.model.Decor; +import net.ihe.gazelle.tempmodel.org.decor.art.model.TemplateDefinition; +import net.ihe.gazelle.tempmodel.org.decor.art.utils.DecorMarshaller; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.xml.bind.JAXBException; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.util.ArrayList; + +public class EHDSIL3Transformer { + + private static Logger log = LoggerFactory.getLogger(EHDSIL3Transformer.class); + + public static ArrayList<TemplateDefinition> templatesToDelete = new ArrayList<>(); + + public static void main(String[] args) throws FileNotFoundException, JAXBException { + + String bbrPath = "DEFINE_YOUR_DEFAULT_PATH_HERE"; + String outputBbrPath = "DEFINE_YOUR_OUT_PATH_HERE"; + + //Override input bbr path if exists as param + if (args.length > 0) { + bbrPath = args[0]; + } + + //Override output bbr path if exists as param + if (args.length > 1) { + outputBbrPath = args[1]; + } + + Decor dec = DecorMarshaller.loadDecor(bbrPath); + DecorVisitor.INSTANCE.visitAndProcess(dec, new TemplateL3Provider()); + + for (TemplateDefinition template : templatesToDelete) { + if (template.getId() != null && !template.getId().isEmpty() && template.getParentObject() != null) { + template.getParentObject().getTemplateAssociationOrTemplate().remove(template); + } + } + + DecorMarshaller.marshallDecor(dec, new FileOutputStream(outputBbrPath)); + } + +} diff --git a/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL1Processor.java b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL1Processor.java new file mode 100644 index 0000000..4a65d80 --- /dev/null +++ b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL1Processor.java @@ -0,0 +1,28 @@ +package net.ihe.gazelle.tempgen.ehdsi.scripts; + + +import net.ihe.gazelle.tempapi.impl.TemplateDefinitionProcessorImpl; +import net.ihe.gazelle.tempmodel.org.decor.art.model.TemplateDefinition; + +import java.util.Arrays; +import java.util.List; + +public class TemplateL1Processor extends TemplateDefinitionProcessorImpl { + + private TemplateDefinition currentTemplateDefinition; + + //eHDSI ePrescription, eHDSI eDispensation and eHDSI Patient Summary are CDA L3 Templates: + // they must be excluded from the L1 validators + private List<String> templateOidToExclude = Arrays.asList("1.3.6.1.4.1.12559.11.10.1.3.1.1.1", + "1.3.6.1.4.1.12559.11.10.1.3.1.1.2", + "1.3.6.1.4.1.12559.11.10.1.3.1.1.3"); + + @Override + public void process(TemplateDefinition t, Object... objects) { + this.currentTemplateDefinition = t; + if (this.currentTemplateDefinition != null && this.currentTemplateDefinition.getId() != null + && templateOidToExclude.contains(this.currentTemplateDefinition.getId())) { + EHDSIL1Transformer.templatesToDelete.add(this.currentTemplateDefinition); + } + } +} diff --git a/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL1Provider.java b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL1Provider.java new file mode 100644 index 0000000..04b656e --- /dev/null +++ b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL1Provider.java @@ -0,0 +1,24 @@ +package net.ihe.gazelle.tempgen.ehdsi.scripts; + +import net.ihe.gazelle.tempapi.interfaces.TemplateDefinitionProcessor; +import net.ihe.gazelle.tempapi.interfaces.VocabularyProcessor; +import net.ihe.gazelle.tempapi.utils.ImplProvider; +import net.ihe.gazelle.tempapi.utils.Processor; + +/** + * + * @author Abderrazek Boufahja + * + */ +public class TemplateL1Provider implements ImplProvider { + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public <T extends Processor> T provideImpl(Class<T> t) { + if (t.equals(TemplateDefinitionProcessor.class)){ + return (T) new TemplateL1Processor(); + } + return null; + } + +} diff --git a/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL3Processor.java b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL3Processor.java new file mode 100644 index 0000000..3cfb51c --- /dev/null +++ b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL3Processor.java @@ -0,0 +1,32 @@ +package net.ihe.gazelle.tempgen.ehdsi.scripts; + + +import net.ihe.gazelle.tempapi.impl.TemplateDefinitionProcessorImpl; +import net.ihe.gazelle.tempmodel.org.decor.art.model.TemplateDefinition; + +import java.util.Arrays; +import java.util.List; + +public class TemplateL3Processor extends TemplateDefinitionProcessorImpl { + + private TemplateDefinition currentTemplateDefinition; + + //eHDSI ePrescription PDF embedded, eHDSI Patient Summary PDF embedded, eHDSI OrCD Laboratory Result, + // eHDSI OrCD Hospital Discharge Report, eHDSI OrCD Medical Imaging Report + // and eHDSI OrCD Medical Imaging Reportare CDA L1 Templates: they must be excluded from the L1 validators + private List<String> templateOidToExclude = Arrays.asList("1.3.6.1.4.1.12559.11.10.1.3.1.1.6", + "1.3.6.1.4.1.12559.11.10.1.3.1.1.7", + "1.3.6.1.4.1.12559.11.10.1.3.1.1.8", + "1.3.6.1.4.1.12559.11.10.1.3.1.1.9", + "1.3.6.1.4.1.12559.11.10.1.3.1.1.10", + "1.3.6.1.4.1.12559.11.10.1.3.1.1.11"); + + @Override + public void process(TemplateDefinition t, Object... objects) { + this.currentTemplateDefinition = t; + if (this.currentTemplateDefinition != null && this.currentTemplateDefinition.getId() != null + && templateOidToExclude.contains(this.currentTemplateDefinition.getId())) { + EHDSIL3Transformer.templatesToDelete.add(this.currentTemplateDefinition); + } + } +} diff --git a/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL3Provider.java b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL3Provider.java new file mode 100644 index 0000000..936a447 --- /dev/null +++ b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/ehdsi/scripts/TemplateL3Provider.java @@ -0,0 +1,24 @@ +package net.ihe.gazelle.tempgen.ehdsi.scripts; + +import net.ihe.gazelle.tempapi.interfaces.TemplateDefinitionProcessor; +import net.ihe.gazelle.tempapi.interfaces.VocabularyProcessor; +import net.ihe.gazelle.tempapi.utils.ImplProvider; +import net.ihe.gazelle.tempapi.utils.Processor; + +/** + * + * @author Abderrazek Boufahja + * + */ +public class TemplateL3Provider implements ImplProvider { + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public <T extends Processor> T provideImpl(Class<T> t) { + if (t.equals(TemplateDefinitionProcessor.class)){ + return (T) new TemplateL3Processor(); + } + return null; + } + +} diff --git a/hl7templates/hl7templates-packager-jar/src/main/java/net/ihe/gazelle/lib/hl7templatespackager/adapters/scripts/EHDSITransformers.java b/hl7templates/hl7templates-packager-jar/src/main/java/net/ihe/gazelle/lib/hl7templatespackager/adapters/scripts/EHDSITransformers.java index d3ebc94..7261e71 100644 --- a/hl7templates/hl7templates-packager-jar/src/main/java/net/ihe/gazelle/lib/hl7templatespackager/adapters/scripts/EHDSITransformers.java +++ b/hl7templates/hl7templates-packager-jar/src/main/java/net/ihe/gazelle/lib/hl7templatespackager/adapters/scripts/EHDSITransformers.java @@ -1,18 +1,19 @@ package net.ihe.gazelle.lib.hl7templatespackager.adapters.scripts; import net.ihe.gazelle.tempgen.ehdsi.scripts.EHDSIFriendlyTransformer; +import net.ihe.gazelle.tempgen.ehdsi.scripts.EHDSIL1Transformer; +import net.ihe.gazelle.tempgen.ehdsi.scripts.EHDSIL3Transformer; import javax.xml.bind.JAXBException; import java.io.IOException; - public class EHDSITransformers { public static void main(String[] args) throws JAXBException, IOException { //Set required system properties for log4j to avoid errors (not used) - System.setProperty("workspaceRoot","/tmp"); - System.setProperty("generationDate","tmp"); + System.setProperty("workspaceRoot", "/tmp"); + System.setProperty("generationDate", "tmp"); EHDSITransformers e = new EHDSITransformers(); e.transformBBRToFriendly(); } @@ -20,14 +21,30 @@ public class EHDSITransformers { public void transformBBRToFriendly() throws IOException, JAXBException { String bbrPath = System.getProperty("bbrPath"); String bbrOutput = System.getProperty("bbrOutput"); - if(bbrPath == null || "".equals(bbrPath) || bbrOutput == null || "".equals(bbrOutput)){ + String validator = System.getProperty("validator"); + + if (validator == null || "".equals(validator)) { + throw new IllegalArgumentException("Validator name not set"); + } + if (bbrPath == null || "".equals(bbrPath) || bbrOutput == null || "".equals(bbrOutput)) { throw new IOException("BBR File not set"); } - System.out.println("Using BBR: "+bbrPath); - if(!bbrPath.endsWith(".xml")){ + System.out.println("Using BBR: " + bbrPath); + if (!bbrPath.endsWith(".xml")) { throw new IOException("Invalid XML File"); } String[] args = new String[]{bbrPath, bbrOutput}; - EHDSIFriendlyTransformer.main(args); + switch (validator) { + case "pivot": + EHDSIL3Transformer.main(args); + break; + case "scanned": + EHDSIL1Transformer.main(args); + break; + case "friendly": + EHDSIL3Transformer.main(args); + EHDSIFriendlyTransformer.main(args); + break; + } } } diff --git a/hl7templates/hl7templates-packager-jar/src/main/resources/assemble-scripts/eHDSIGeneration.sh b/hl7templates/hl7templates-packager-jar/src/main/resources/assemble-scripts/eHDSIGeneration.sh index 7064d45..a505852 100755 --- a/hl7templates/hl7templates-packager-jar/src/main/resources/assemble-scripts/eHDSIGeneration.sh +++ b/hl7templates/hl7templates-packager-jar/src/main/resources/assemble-scripts/eHDSIGeneration.sh @@ -18,7 +18,7 @@ NC='\033[0m' ## FUNCTIONS DEFINITION function readBBR { - read -r bbrPath + read -e -r bbrPath isAbsPath=`echo "${bbrPath}" | grep ^/.* | wc -l` if [ $isAbsPath -eq 0 ]; then echo -e "${RED}[ ${bbrPath} ] is not an absolute path${NC}" @@ -30,22 +30,23 @@ function readBBR { fi } -function friendly_trannsform { - bbrFriendlyOutput=`echo "$bbrPath" | sed --expression="s/.xml/-friendly.xml/g"` -# bbrOutput=`echo "$bbrPath" | sed --expression="s/.xml/-friendly.xml/g"` +function bbr_transform { + echo $1 + bbrOutput=`echo "$bbrPath" | sed --expression="s/.xml/-$1.xml/g"` + echo $bbrOutput packagerPath=`realpath ..` packagerFolder=${packagerPath##*/} if [ $packagerFolder == "hl7templates-packager-jar" ]; then - $mavenPath -f "$packagerPath/pom.xml" compile org.codehaus.mojo:exec-maven-plugin:3.0.0:java -Dexec.mainClass="net.ihe.gazelle.lib.hl7templatespackager.adapters.scripts.EHDSITransformers" -DbbrPath="$bbrPath" -DbbrOutput="$bbrFriendlyOutput" + $mavenPath -f "$packagerPath/pom.xml" compile org.codehaus.mojo:exec-maven-plugin:3.0.0:java -Dexec.mainClass="net.ihe.gazelle.lib.hl7templatespackager.adapters.scripts.EHDSITransformers" -Dvalidator="$1" -DbbrPath="$bbrPath" -DbbrOutput="$bbrOutput" if [ $? == 0 ]; then - bbrPath=$bbrFriendlyOutput - echo -e "${GREEN}BBR Transformed to friendly at: ${bbrFriendlyOutput}${NC}" + bbrPath=$bbrOutput + echo -e "${GREEN}BBR Transformed to $1 at: ${bbrOutput}${NC}" else - echo -e "${ORANGE}Transformartion to frienly BBR Failed! Please provide Friendly manually, or contact support${NC}" + echo -e "${ORANGE}Transformation to $1 BBR Failed! Please provide $1 manually, or contact support${NC}" readBBR fi else - echo -e "${ORANGE}Could not found 'packager module' at $packagerPath, cannot perform transformation, please provide Friendly BBR manually${NC}" + echo -e "${ORANGE}Could not found 'packager module' at $packagerPath, cannot perform transformation, please provide $1 BBR manually${NC}" readBBR fi } @@ -76,12 +77,12 @@ jarPath=`ls -l | grep -oh -e "[^ ]*-jar-with-dependencies\.jar"` if [ -z $jarPath ]; then echo -e "${ORANGE}Could not detect the JAR of GOC, please provide the path manually${NC}" - read -r jarPath + read -e -r jarPath else absJarPath=`realpath $jarPath` echo -e "${GREEN}A GOC JAR has been detected at: (${jarPath}) want you to use it?${NC}" printf "hit enter for yes, provide an other path to change it: " - read -r newJarPath + read -e -r newJarPath if [ ! -z $newJarPath ]; then isAbsPath=`echo "${newJarPath}" | grep ^/.* | wc -l` if [ $isAbsPath -eq 0 ]; then @@ -114,7 +115,7 @@ if [ -z "$mavenPath" ];then mvnVersion=$(echo "$mavenPath" |grep -oh -e "3\.5\..*") if [ -z "$mavenPath" ] || [ -z "$mvnVersion" ];then echo -e "${ORANGE}Could not detect the required maven installation [5.3.x], please enter the absolute to the binary file of maven: ${NC}" - read -r mavenPath + read -e -r mavenPath testMaven2=$($mavenPath -v) if [ -z "$testMaven2" ];then echo -e "${RED}Wrong maven executable...${NC}" @@ -128,7 +129,7 @@ if [ -z "$mavenPath" ];then else echo -e "${GREEN}A valid maven version detect ${mvnVersion}, do you want to use it?${NC}" printf "Press enter for yes, enter absolute path for maven binary to change it: " - read -r newMaven + read -e -r newMaven if [ -z newMaven ]; then mavenPath="${mavenPath}/bin/mvn" else @@ -185,13 +186,14 @@ case $choice in 3) echo -e "${GREEN}generation friendly${NC}" validator="friendly" - friendly_trannsform echo -e "Friendly BBR Will be used for generation" ;; esac +bbr_transform $validator + printf "Please enter workspace path (where you want to generate the validator): " -read -r workspaceDir +read -e -r workspaceDir if [ ! -d $workspaceDir ]; then echo "${RED}The provided workspace is not a valid directory" exit 0 @@ -224,7 +226,7 @@ if [ -d ./classes/eHDSI-resources/xsd ]; then else echo -e "${ORANGE}Could not find resources, please provide the path to the XSD folder manually${NC}" echo -e "${ORANGE}be careful, the directory should contain correct XSD files for the validator to run. This is not checked by the script!${NC}" - read -r pathToResources + read -e -r pathToResources if [ ! -d $pathToResources ]; then echo -e "${RED} invalid path to directory" exit 1; @@ -253,4 +255,4 @@ documentationPath=$(realpath $(find $workspaceDir/$folderName -type d -wholename cp -r $documentationPath $appPath #Zipping -zip -r "validator-$_currDate.zip" bbr/ documentation/ repo/ bin/ \ No newline at end of file +zip -r "validator-$_currDate.zip" bbr/ documentation/ repo/ bin/ -- GitLab