diff --git a/hl7templates/hl7templates-packager-jar/src/main/resources/assemble-scripts/xehealthGeneration.sh b/hl7templates/hl7templates-packager-jar/src/main/resources/assemble-scripts/xehealthGeneration.sh index 13a92f125f715aefeeddcb697bceec13f2c524a8..354e5220d19b7666cf069d37b99a6abd25e36c6c 100755 --- a/hl7templates/hl7templates-packager-jar/src/main/resources/assemble-scripts/xehealthGeneration.sh +++ b/hl7templates/hl7templates-packager-jar/src/main/resources/assemble-scripts/xehealthGeneration.sh @@ -1,22 +1,35 @@ #!/bin/bash #################################### -# SEQUOIA Generation & Adaptation Script -# Created by Achraf Achkari - 09 Nov 2021 -# Last revision - 09 Nov 2021 -# Version 1.0.0 +# Xehealth Generation Script +# Created by Nabila Aazibou - 03 Aout 2023 +# Last revision - 03 Aout 2023 +# Version 3.5.1 ##################################### + #Colors definitions for terminal RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' NC='\033[0m' -#SEQUOIA Validators -MU3="HL7 - C-CDA R2.1 - Meaningful Use Stage 3" -USCDI="HL7 - C-CDA R2.1 - USCDI" -CCDA_R_1="HL7 - C-CDA R1.1" + +## FUNCTIONS DEFINITION + +function readBBR { + read -r bbrPath + isAbsPath=`echo "${bbrPath}" | grep ^/.* | wc -l` + if [ $isAbsPath -eq 0 ]; then + echo -e "${RED}[ ${bbrPath} ] is not an absolute path${NC}" + exit 1 + fi + if [ ! -f $bbrPath ]; then + echo -e "${RED}[ ${bbrPath} ] is not a file or doesn't exist !${NC}" + exit 1 + fi +} + #UNCOMENT THIS TO OVERRIDE DEFAULT JAVA VERSION USED BY SYSTEM @@ -37,20 +50,22 @@ if [ -z "$javaVersion" ]; then exit 1 fi +## JAR DETECTION + # Try to get the jar of GOC automatically -jarPath=$(ls -l | grep -oh -e "[^ ]*-jar-with-dependencies\.jar") +jarPath=`ls -l | grep -oh -e "[^ ]*-jar-with-dependencies\.jar"` -if [ -z "$jarPath" ]; then +if [ -z $jarPath ]; then echo -e "${ORANGE}Could not detect the JAR of GOC, please provide the path manually${NC}" read -r jarPath else - absJarPath=$(realpath "$jarPath") + 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, enter an other path to change it: " + printf "hit enter for yes, provide an other path to change it: " read -r newJarPath - if [ ! -z "$newJarPath" ]; then - isAbsPath=$(echo "${newJarPath}" | grep -c "^/.*") - if [ "$isAbsPath" -eq 0 ]; then + if [ ! -z $newJarPath ]; then + isAbsPath=`echo "${newJarPath}" | grep ^/.* | wc -l` + if [ $isAbsPath -eq 0 ]; then echo -e "${RED}[ ${newJarPath} ] is not an absolute path${NC}" exit 1 fi @@ -58,10 +73,10 @@ else fi fi +## MAVEN VERIFICATION #Try to use maven wrapper if [ -f ./classes/maven-wrapper/mvnw ];then -# base_dir=$(realpath ./classes/maven-wrapper) mavenPath=$(realpath "./classes/maven-wrapper/mvnw") testMaven=$($mavenPath -v) if [ ! -z "$testMaven" ]; then @@ -121,109 +136,65 @@ fi; echo -e "${GREEN}Using maven at: ${mavenPath}${NC}" +## BBR READING printf "Please enter a path to your BBR (Absolute Path) : " -read -r bbrPath -isAbsPath=$(echo "${bbrPath}" | grep ^/.* | wc -l) -if [ "$isAbsPath" -eq 0 ]; then - echo -e "${RED}[ ${bbrPath} ] is not an absolute path${NC}" - exit 1 -fi -if [ ! -f "$bbrPath" ]; then - echo -e "${RED}[ ${bbrPath} ] is not a file or doesn't exist !${NC}" - exit 1 -fi - -printf "Please choose the kind of validator you want to generate: \n" -printf "\t 1- $MU3\n" -printf "\t 2- $USCDI\n" -printf "\t 3- $CCDA_R_1\n" -printf "your choice: " -read -r choice - -if [ "$choice" -gt 3 -o "$choice" -lt 1 ]; then - echo "${RED}Wrong choice, please repeat and choose between 1 and 3${NC}" - exit 1 -fi - -versionLabel="" -case $choice in - - 1) - echo -e "${GREEN}generating ${MU3// /}${NC}" - validator=${MU3// /} - versionLabel="2.1" - ;; - -esac +readBBR +validator="xehealth" printf "Please enter workspace path (where you want to generate the validator): " read -r workspaceDir -if [ ! -d "$workspaceDir" ]; then +if [ ! -d $workspaceDir ]; then echo "${RED}The provided workspace is not a valid directory" - exit 1 + exit 0 fi -isAbsPath=$(echo "${workspaceDir}" | grep -c "^/.*") -if [ "$isAbsPath" -eq 0 ]; then +isAbsPath=`echo "${workspaceDir}" | grep ^/.* | wc -l` +if [ $isAbsPath -eq 0 ]; then echo -e "${RED}[ ${workspaceDir} ] is not an absolute path" - exit 1 + exit 0 fi -_currDate=$(date +%Y-%m-%d-%H-%M-%S) -printf "Please enter the folder name of your validator: (output-${validator}-${_currDate})?: " +_currDate=`date +%Y-%m-%d-%H-%M-%S` +printf "Please enter the folder name of your validator: (output-${validator}-${_currDate})?" read -r folderName -if [ -z "$folderName" ]; then +if [ -z $folderName ]; then folderName="output-${validator}-${_currDate}" fi; echo -e "${GREEN}your validator will be generated in: ${workspaceDir}/${folderName}${NC}" ######## GENERATION COMMAND ######## -$JAVA_HOME/bin/java -jar "$absJarPath" -bbr "$bbrPath" -out "${workspaceDir}/${folderName}" -mvn "$mavenPath" -serviceName "$validator" -versionLabel "$versionLabel" -ignoreTemplateIdRequirements -ignoreCdaBasicRequirements +$JAVA_HOME/bin/java -jar $jarPath -bbr $bbrPath -out "${workspaceDir}/${folderName}" -mvn $mavenPath -serviceName $validator -HL7TEMP_CDACONFFOLDERNAME cdaxehealth -ignoreCdaBasicRequirements #################################### -if [ $? != 0 ]; then - echo "${RED}Generation Failed${NC}" - exit 1 -fi - -echo -e "${GREEN}Validator generated successfully${NC}" - -echo -e "${NC}Start SVS Adaptations..." - -if [ ! -f ./xehealthGeneration.sh ]; then - echo -e "${RED}Could not find the xehealthGeneration script, please recompile GOC and rerun this script" - exit 1; -fi; - -# adapt only if version is higher than 1.1 -if [ "$versionLabel" != "1.1" ]; then - pathToResources='' - - if [ ! -d ./classes/xehealth-resources.xsd ]; then - echo -e "${RED}Resources for adaptations not found, please provide a path manually" - read -r $pathToResources - else - pathToResources=$(realpath ./classes/xehealth-resources.xsd) - fi - - if [ ! -x ./xehealthGeneration.sh ]; then - chmod +x xehealthGeneration.sh +#Replacing XSD +pathToResources="" +if [ -d ./classes/xehealth-resources/xsd ]; then + pathToResources=$(realpath "./classes/xehealth-resources/xsd") + echo -e "${GREEN}XSD Resources found at $pathToResources${NC}" +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 + if [ ! -d $pathToResources ]; then + echo -e "${RED} invalid path to directory" + exit 1; fi; +fi; - env JAVA_HOME=$JAVA_HOME M2_BIN=$mavenPath ./xehealthGeneration.sh "$workspaceDir/$folderName" $pathToResources +pathToXSD=$(realpath $(find "${workspaceDir}/${folderName}" -type d -name "xsd" | grep -e ".*-app/.*")) +echo "$pathToXSD" +XSDDirname=$(dirname "$pathToXSD") +echo "$XSDDirname" +rm -r "$pathToXSD" +cp -r "$pathToResources" "$XSDDirname" - if [ $? != 0 ]; then - echo "${RED}Adaptations failed" - exit 1 - fi -fi; #Zip validator - #move to bin path -appassemblerPath=$(realpath $(find $workspaceDir/$folderName -type d -wholename */appassembler)) -cd $appassemblerPath + #move to app path +appPath=$(realpath $(find $workspaceDir/$folderName -type d -wholename *validator-app)) +cd $appPath #Create bbr folder mkdir "bbr" || echo "File already exist, that won't affect next steps" @@ -231,7 +202,7 @@ cp $bbrPath bbr #create documentation folder documentationPath=$(realpath $(find $workspaceDir/$folderName -type d -wholename "*/documentation")) -cp -r $documentationPath $appassemblerPath +cp -r $documentationPath $appPath #Zipping zip -r "validator-$_currDate.zip" bbr/ documentation/ repo/ bin/ \ No newline at end of file