diff --git a/GazelleHL7v2Validator-ear/src/main/resources/soapui/GazelleHL7v2Validator-calibration-soapui-project.xml b/GazelleHL7v2Validator-ear/src/main/resources/soapui/GazelleHL7v2Validator-calibration-soapui-project.xml index 5ba9581026f8ef2d0f865cb68304f08cf4032894..3e8cad24aebb701d15df6f3b670a43e4fa5eda96 100644 --- a/GazelleHL7v2Validator-ear/src/main/resources/soapui/GazelleHL7v2Validator-calibration-soapui-project.xml +++ b/GazelleHL7v2Validator-ear/src/main/resources/soapui/GazelleHL7v2Validator-calibration-soapui-project.xml @@ -487,7 +487,7 @@ for (int i = 1; i <= 3; i++){ <xmlValidationMetadata></xmlValidationMetadata> <!--Test with valid xmlValidationContext --> <xmlValidationContext><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet type="text/xsl" href="https://gazelle.ihe.net/xsl/hl7Validation/resultStylesheet.xsl"?> - <ValidateContext> + <ValidationContext> <ProfileOID>1.3.6.1.4.12559.11.1.1.182</ProfileOID> <ValidationOptions> <MessageStructure>ERROR</MessageStructure> @@ -495,8 +495,8 @@ for (int i = 1; i <= 3; i++){ <DataType>ERROR</DataType> <DataValue>WARNING</DataValue> </ValidationOptions> - <CharacterEncoding>UTF-8</CharacterEncoding> - </ValidateContext>]]]]>><![CDATA[</xmlValidationContext> + <CharacterEncoding>ER7</CharacterEncoding> + </ValidationContext>]]]]>><![CDATA[</xmlValidationContext> <messageToValidate><![CDATA[MSH|^~\&|||||20171215150440+1100||OUL^R22^OUL_R22|123|P|2.5.1|||NE|AL||UNICODE UTF-8|||LAB-29^IHE| SPM|1|||BLD^Whole Blood^HL70487|||||||P^Patient^HL70369||||||||||||||||||| SAC|||VialBarcode|||||||||||||||||||||||||||||||||||||||||| OBR||""||IMX^ImmunoXpert^99000||||||||||||||||||||||||||||||||||||||||||||||| ORC|SC||||CM||||||||||||||||||||||||||| OBX|1|NM|TRAIL^TRAIL Concentration^99000|1^1^1|3.5|mg/ml^milligrams per milliliter^UCUM||IND^^HL70078|||F|||||""||InstrumentModel^Dover^^~InstrumentSerialNumber^Dover^^|20171211152000||ResultUID||||||||RSLT|| ]]]]>><![CDATA[</messageToValidate> </ws:validateMessage> @@ -694,7 +694,7 @@ for (int i = 1; i <= 3; i++){ <xmlValidationMetadata></xmlValidationMetadata> <!--Test with valid xmlValidationContext --> <xmlValidationContext><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet type="text/xsl" href="https://gazelle.ihe.net/xsl/hl7Validation/resultStylesheet.xsl"?> - <ValidateContext> + <ValidationContext> <ProfileOID>1.3.6.1.4.12559.11.1.1.36</ProfileOID> <ValidationOptions> <MessageStructure>ERROR</MessageStructure> @@ -702,8 +702,8 @@ for (int i = 1; i <= 3; i++){ <DataType>ERROR</DataType> <DataValue>ERROR</DataValue> </ValidationOptions> - <CharacterEncoding>UTF-8</CharacterEncoding> - </ValidateContext>]]]]>><![CDATA[</xmlValidationContext> + <CharacterEncoding>ER7</CharacterEncoding> + </ValidationContext>]]]]>><![CDATA[</xmlValidationContext> <!--Test with valid messageToValidate --> <messageToValidate><![CDATA[MSH|^~\&|Gazelle|IHE|PAMSimulator|IHE|20180514150208||ADT^A28^ADT_A05|20180514150208|P|2.5|1||||USA|UNICODE UTF-8 EVN||20180514150209||||20180514150209 @@ -788,7 +788,7 @@ PV1||N]]]]>><![CDATA[</messageToValidate> <xmlValidationMetadata></xmlValidationMetadata> <!--Test with valid xmlValidationContext --> <xmlValidationContext><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet type="text/xsl" href="https://gazelle.ihe.net/xsl/hl7Validation/resultStylesheet.xsl"?> - <ValidateContext> + <ValidationContext> <ProfileOID>1.3.6.1.4.12559.11.1.1.36</ProfileOID> <ValidationOptions> <MessageStructure>ERROR</MessageStructure> @@ -796,8 +796,8 @@ PV1||N]]]]>><![CDATA[</messageToValidate> <DataType>ERROR</DataType> <DataValue>WARNING</DataValue> </ValidationOptions> - <CharacterEncoding>UTF-8</CharacterEncoding> - </ValidateContext>]]]]>><![CDATA[</xmlValidationContext> + <CharacterEncoding>ER7</CharacterEncoding> + </ValidationContext>]]]]>><![CDATA[</xmlValidationContext> <!--Test with valid messageToValidate --> <messageToValidate><![CDATA[MSH|^~\&|Gazelle|IHE|PAMSimulator|IHE|20180514150208||ADT^A28^ADT_A05|20180514150208XXXXXXXXXX|P|2.5|1||||USA|UTF-8 EVN||20180514150209||||20180514150209 @@ -839,7 +839,7 @@ PV1||N]]]]>><![CDATA[</messageToValidate> <xmlValidationMetadata></xmlValidationMetadata> <!--Test with valid xmlValidationContext --> <xmlValidationContext><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet type="text/xsl" href="https://gazelle.ihe.net/xsl/hl7Validation/resultStylesheet.xsl"?> - <ValidateContext> + <ValidationContext> <ProfileOID>1.3.6.1.4.12559.11.1.1.36</ProfileOID> <ValidationOptions> <MessageStructure>ERROR</MessageStructure> @@ -847,8 +847,8 @@ PV1||N]]]]>><![CDATA[</messageToValidate> <DataType>ERROR</DataType> <DataValue>ERROR</DataValue> </ValidationOptions> - <CharacterEncoding>UTF-8</CharacterEncoding> - </ValidateContext>]]]]>><![CDATA[</xmlValidationContext> + <CharacterEncoding>ER7</CharacterEncoding> + </ValidationContext>]]]]>><![CDATA[</xmlValidationContext> <!--Test with valid messageToValidate --> <messageToValidate><![CDATA[MSH|^~\&|Gazelle|IHE|PAMSimulator|IHE|20180514150208||ADT^A28^ADT_A05|20180514150208XXXXXXXXXX|P|2.5|1||||USA|UNICODE UTF-8 EVN||20180514150209||||20180514150209 @@ -890,7 +890,7 @@ PV1||N]]]]>><![CDATA[</messageToValidate> <xmlValidationMetadata></xmlValidationMetadata> <!--Test with valid xmlValidationContext --> <xmlValidationContext><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet type="text/xsl" href="https://gazelle.ihe.net/xsl/hl7Validation/resultStylesheet.xsl"?> - <ValidateContext> + <ValidationContext> <ProfileOID>1.3.6.1.4.12559.11.1.1.36</ProfileOID> <ValidationOptions> <MessageStructure>ERROR</MessageStructure> @@ -898,8 +898,8 @@ PV1||N]]]]>><![CDATA[</messageToValidate> <DataType>ERROR</DataType> <DataValue>ERROR</DataValue> </ValidationOptions> - <CharacterEncoding>UTF-8</CharacterEncoding> - </ValidateContext>]]]]>><![CDATA[</xmlValidationContext> + <CharacterEncoding>ER7</CharacterEncoding> + </ValidationContext>]]]]>><![CDATA[</xmlValidationContext> <!--Test with valid messageToValidate --> <messageToValidate><![CDATA[MSH|^~\&|Gazelle|IHE|PAMSimulator|IHE|20180514150208||ADT^A28^ADT_A05|20180514150208|P|2.5|1||||USA|UTF-8 EVN||20180514150209||||20180514150209 @@ -941,7 +941,7 @@ PV1||N]]]]>><![CDATA[</messageToValidate> <xmlValidationMetadata></xmlValidationMetadata> <!--Test with valid xmlValidationContext --> <xmlValidationContext><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet type="text/xsl" href="https://gazelle.ihe.net/xsl/hl7Validation/resultStylesheet.xsl"?> - <ValidateContext> + <ValidationContext> <ProfileOID>1.3.6.1.4.12559.11.1.1.36</ProfileOID> <ValidationOptions> <MessageStructure>ERROR</MessageStructure> @@ -949,8 +949,8 @@ PV1||N]]]]>><![CDATA[</messageToValidate> <DataType>ERROR</DataType> <DataValue>WARNING</DataValue> </ValidationOptions> - <CharacterEncoding>UTF-8</CharacterEncoding> - </ValidateContext>]]]]>><![CDATA[</xmlValidationContext> + <CharacterEncoding>ER7</CharacterEncoding> + </ValidationContext>]]]]>><![CDATA[</xmlValidationContext> <!--Test with valid messageToValidate --> <messageToValidate><![CDATA[MSH|^~\&|Gazelle|IHE|PAMSimulator|IHE|20180514150208||ADT^A28^ADT_A05|20180514150208|P|2.5|1||||USA|UTF-8 EVN||20180514150209||||20180514150209 @@ -3837,4 +3837,4 @@ testRunner.testCase.setPropertyValue("message", messageToVal)</script></con:conf </queryByParameter> </controlActProcess> </PRPA_IN201306UV02>]]></con:value></con:property><con:property><con:name>messageName</con:name><con:value>GazelleHL7Model_PDQv3_response.xml</con:value></con:property><con:property><con:name>directoryName</con:name><con:value>GazelleHL7Model_PDQv3_response</con:value></con:property></con:properties> - </con:testCase><con:properties/></con:testSuite><con:properties><con:property><con:name>endPointGazelleHL7ModelBased</con:name><con:value>${#Project#domain}/GazelleHL7v2Validator-ejb/ModelBasedValidationWSService/ModelBasedValidationWS</con:value></con:property><con:property><con:name>endPointGazelleHL7Validation</con:name><con:value>${#Project#domain}/GazelleHL7v2Validator-ejb/gazelleHL7v2ValidationWSService/gazelleHL7v2ValidationWS</con:value></con:property><con:property><con:name>domain</con:name><con:value>http://localhost</con:value></con:property><con:property><con:name>calibration_file</con:name><con:value>false</con:value></con:property><con:property><con:name>response_path_save</con:name><con:value>/home/abe/workspace/GazelleHL7v2Validator/GazelleHL7v2Validator-ear/src/main/resources/soapui/</con:value></con:property></con:properties><con:wssContainer/><con:oAuth2ProfileContainer/><con:oAuth1ProfileContainer/><con:sensitiveInformation/></con:soapui-project> \ No newline at end of file + </con:testCase><con:properties/></con:testSuite><con:properties><con:property><con:name>endPointGazelleHL7ModelBased</con:name><con:value>${#Project#domain}/GazelleHL7v2Validator-ejb/ModelBasedValidationWSService/ModelBasedValidationWS</con:value></con:property><con:property><con:name>endPointGazelleHL7Validation</con:name><con:value>${#Project#domain}/GazelleHL7v2Validator-ejb/gazelleHL7v2ValidationWSService/gazelleHL7v2ValidationWS</con:value></con:property><con:property><con:name>domain</con:name><con:value>http://localhost</con:value></con:property><con:property><con:name>calibration_file</con:name><con:value>false</con:value></con:property><con:property><con:name>response_path_save</con:name><con:value>/home/abe/workspace/GazelleHL7v2Validator/GazelleHL7v2Validator-ear/src/main/resources/soapui/</con:value></con:property></con:properties><con:wssContainer/><con:oAuth2ProfileContainer/><con:oAuth1ProfileContainer/><con:sensitiveInformation/></con:soapui-project> diff --git a/GazelleHL7v2Validator-ear/src/main/resources/soapui/GazelleHL7v2Validator-soapui-project.xml b/GazelleHL7v2Validator-ear/src/main/resources/soapui/GazelleHL7v2Validator-soapui-project.xml index 49186e493d754685d98c9d42f8b6aabb9828a269..f5bcc11ca581bf4d2148f66ac6706eecf52ad48f 100644 --- a/GazelleHL7v2Validator-ear/src/main/resources/soapui/GazelleHL7v2Validator-soapui-project.xml +++ b/GazelleHL7v2Validator-ear/src/main/resources/soapui/GazelleHL7v2Validator-soapui-project.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<con:soapui-project id="08a70e69-a7a7-46d8-aa78-cacba8d3c837" activeEnvironment="Default" name="GazelleHL7Validator" resourceRoot="" soapui-version="5.4.0-EB" abortOnError="false" runType="SEQUENTIAL" xmlns:con="http://eviware.com/soapui/config"> +<con:soapui-project id="08a70e69-a7a7-46d8-aa78-cacba8d3c837" activeEnvironment="Default" name="GazelleHL7Validator" resourceRoot="" soapui-version="5.5.0" abortOnError="false" runType="SEQUENTIAL" xmlns:con="http://eviware.com/soapui/config"> <con:settings/> <con:interface xsi:type="con:WsdlInterface" id="c6ea546a-b41b-4473-a5bb-a3e6577dbc0b" wsaVersion="NONE" name="ModelBasedValidationWSServiceSoapBinding" type="wsdl" bindingName="{http://ws.mb.validator.gazelle.ihe.net}ModelBasedValidationWSServiceSoapBinding" soapVersion="1_1" anonymous="optional" definition="http://xfs-Inspiron-7559:8080/GazelleHL7v2Validator-ejb/ModelBasedValidationWSService/ModelBasedValidationWS?wsdl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <con:settings/> @@ -1173,7 +1173,7 @@ try { <xmlValidationMetadata>?</xmlValidationMetadata> <!--Test with valid xmlValidationContext:--> <xmlValidationContext><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet type="text/xsl" href="https://gazelle.ihe.net/xsl/hl7Validation/resultStylesheet.xsl"?> - <ValidateContext> + <ValidationContext> <ProfileOID>1.3.6.1.4.12559.11.1.1.182</ProfileOID> <ValidationOptions> <MessageStructure>EEROR</MessageStructure> @@ -1181,8 +1181,8 @@ try { <DataType>ERROR</DataType> <DataValue>WARNING</DataValue> </ValidationOptions> - <CharacterEncoding></CharacterEncoding> - </ValidateContext>]]]]>><![CDATA[</xmlValidationContext> + <CharacterEncoding>ER7</CharacterEncoding> + </ValidationContext>]]]]>><![CDATA[</xmlValidationContext> <!--Test without messageToValidate:--> <messageToValidate></messageToValidate> </ws:validateMessage> @@ -1388,7 +1388,7 @@ ORC|OK|5255^MED_LAB_OP^1.3.6.1.4.1.21367.2011.2.1.230^ISO|734^MED_LAB_OF^1.3.6.1 <xmlValidationMetadata></xmlValidationMetadata> <!--Test without valid xmlValidationContext --> <xmlValidationContext><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet type="text/xsl" href="https://gazelle.ihe.net/xsl/hl7Validation/resultStylesheet.xsl"?> - <ValidateContext> + <ValidationContext> <ProfileOID>333</ProfileOID> <ValidationOptions> <MessageStructure>ERROR</MessageStructure> @@ -1396,8 +1396,8 @@ ORC|OK|5255^MED_LAB_OP^1.3.6.1.4.1.21367.2011.2.1.230^ISO|734^MED_LAB_OF^1.3.6.1 <DataType>ERROR</DataType> <DataValue>WARNING</DataValue> </ValidationOptions> - <CharacterEncoding>UTF-8</CharacterEncoding> - </ValidateContext>]]]]>><![CDATA[</xmlValidationContext> + <CharacterEncoding>ER7</CharacterEncoding> + </ValidationContext>]]]]>><![CDATA[</xmlValidationContext> <!--Test with valid messageToValidate --> <messageToValidate><![CDATA[MSH|^~\&|OM_RAD_OP|IHE|IDeal Broker|ETIAM|20120606162515||ORM^O01^ORM_O01|20120606162515|P|2.3.1||||||8859/1 PID|||DDS-37698^^^DDS&1.3.6.1.4.1.12559.11.1.4.1.2&ISO^PI||Bisson^Anatole^^^^^L|Decroix^^^^^^M|19400601080400|M|||Clos de l'Oural^^Guyancourt^^78280^FRA @@ -1457,7 +1457,7 @@ OBR||1710^IHE_OM_OP^1.3.6.1.4.1.12559.11.1.2.2.4.2^ISO||10210^Radiological Exami <xmlValidationMetadata></xmlValidationMetadata> <!--Test with valid xmlValidationContext --> <xmlValidationContext><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet type="text/xsl" href="https://gazelle.ihe.net/xsl/hl7Validation/resultStylesheet.xsl"?> - <ValidateContext> + <ValidationContext> <ProfileOID>1.3.6.1.4.12559.11.1.1.103</ProfileOID> <ValidationOptions> <MessageStructure>ERROR</MessageStructure> @@ -1465,8 +1465,8 @@ OBR||1710^IHE_OM_OP^1.3.6.1.4.1.12559.11.1.2.2.4.2^ISO||10210^Radiological Exami <DataType>ERROR</DataType> <DataValue>WARNING</DataValue> </ValidationOptions> - <CharacterEncoding>UTF-8</CharacterEncoding> - </ValidateContext>]]]]>><![CDATA[</xmlValidationContext> + <CharacterEncoding>ER7</CharacterEncoding> + </ValidationContext>]]]]>><![CDATA[</xmlValidationContext> <!--Test without valid messageToValidate --> <messageToValidate><![CDATA[MSH|^~\&|ARE|QSP|ECSIMAGING|20170427124804||ORM^O01^ORM_O01|ECS004.HL7|P|2.3.1|||||FRA|8859/15|FRA|| PID|||80718^^^PAM_QSP^PI~222047506631201^^^^SS||FLOURAT^SUZANNE^^^Mme^^D~^SUZANNE^^^^^L||19220429|F|||4 RUE PIERRE CURIE^^LA FRETTE SUR SEINE^^95530^FRA^H||0139789078^PRN^PH|||M||31006456^^^PAM_QSP^AN|||||||||||| @@ -1526,7 +1526,7 @@ OBR|1|2^PAM_QSP|2^PAM_QSP|POA^Rx Poumon^PAM_QSP|||20170425151500|||||||||7515585 <xmlValidationMetadata></xmlValidationMetadata> <!--Test with valid xmlValidationContext --> <xmlValidationContext><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet type="text/xsl" href="https://gazelle.ihe.net/xsl/hl7Validation/resultStylesheet.xsl"?> - <ValidateContext> + <ValidationContext> <ProfileOID>1.3.6.1.4.12559.11.1.1.82</ProfileOID> <ValidationOptions> <MessageStructure>ERROR</MessageStructure> @@ -1534,8 +1534,8 @@ OBR|1|2^PAM_QSP|2^PAM_QSP|POA^Rx Poumon^PAM_QSP|||20170425151500|||||||||7515585 <DataType>ERROR</DataType> <DataValue>WARNING</DataValue> </ValidationOptions> - <CharacterEncoding>UTF-8</CharacterEncoding> - </ValidateContext>]]]]>><![CDATA[</xmlValidationContext> + <CharacterEncoding>ER7</CharacterEncoding> + </ValidationContext>]]]]>><![CDATA[</xmlValidationContext> <!--Test with valid messageToValidate --> <messageToValidate><![CDATA[MSH|^~\&|PAMSimulator|IHE|Summit|Summit|20141017062500||ADT^A08^ADT_A01|20141017062500|P|2.3.1||||||8859/1 EVN||20141017062500 @@ -3393,7 +3393,7 @@ count(//ns2:param)</path><content>3</content><allowWildcards>false</allowWildcar <input name="xmlValidationContext" embeddingMethod="STRING" type="?" encoding="?"> <!--Optional:--> <v11:value><![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?><?xml-stylesheet type="text/xsl" href="https://gazelle.ihe.net/xsl/hl7Validation/resultStylesheet.xsl"?> - <ValidateContext> + <ValidationContext> <ProfileOID>1.3.6.1.4.12559.11.1.1.82</ProfileOID> <ValidationOptions> <MessageStructure>ERROR</MessageStructure> @@ -3401,8 +3401,8 @@ count(//ns2:param)</path><content>3</content><allowWildcards>false</allowWildcar <DataType>ERROR</DataType> <DataValue>WARNING</DataValue> </ValidationOptions> - <CharacterEncoding>UTF-8</CharacterEncoding> - </ValidateContext>]]]]>><![CDATA[</v11:value> + <CharacterEncoding>ER7</CharacterEncoding> + </ValidationContext>]]]]>><![CDATA[</v11:value> </input> <input name="messageToValidate" embeddingMethod="STRING" type="?" encoding="?"> <!--Optional:--> @@ -3420,11 +3420,11 @@ declare namespace ns2='http://www.gitb.com/core/v1/'; count(*//ns4:ValidationResponse/report)</path><content>1</content><allowWildcards>false</allowWildcards><ignoreNamspaceDifferences>false</ignoreNamspaceDifferences><ignoreComments>false</ignoreComments></con:configuration></con:assertion><con:credentials><con:authType>No Authorization</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:wsaConfig mustUnderstand="NONE" version="200508" action="http://ws.hl7.gazelle.ihe.net/ValidationService/validate"/><con:wsrmConfig version="1.2"/></con:request></con:config></con:testStep><con:properties/></con:testCase><con:properties/></con:testSuite><con:properties> <con:property> <con:name>domain</con:name> - <con:value>http://127.0.0.1:8080</con:value> + <con:value>http://localhost</con:value> </con:property> </con:properties> <con:wssContainer/> <con:oAuth2ProfileContainer/> <con:oAuth1ProfileContainer/> <con:sensitiveInformation/> -</con:soapui-project> \ No newline at end of file +</con:soapui-project> diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/messageprofiles/model/ConformanceProfileFormat.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/messageprofiles/model/ConformanceProfileFormat.java new file mode 100644 index 0000000000000000000000000000000000000000..9dbc0e7d2250dbc30dc2b11208973ead264af439 --- /dev/null +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/messageprofiles/model/ConformanceProfileFormat.java @@ -0,0 +1,13 @@ +package net.ihe.gazelle.hl7.messageprofiles.model; + +/** + * <p>ConformanceProfileFormat enum.</p> + * + * @author abe + * @version 1.0: 09/07/19 + */ +public enum ConformanceProfileFormat { + + HL7v2xConformanceProfile, + ConformanceProfile +} diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/action/MessageLogger.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/action/MessageLogger.java index d4735d4355c7e9244ab0cc37869a785e65feb9ed..754420978a52fee9b7d83cdaf1b020e0c91427f7 100644 --- a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/action/MessageLogger.java +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/action/MessageLogger.java @@ -163,11 +163,6 @@ public class MessageLogger implements Serializable, QueryModifier<HL7Message> { } } - public void revalidate() { - HapiValidator validator = new HapiValidator(callerIP, selectedMessage.getMetadata(), - selectedMessage.getMessage(), selectedMessage.getValidationContextAsString(), false); - newValidationResult = validator.validate(); - } public String getProfileExceptions() { HL7v2ValidationReport report = HL7v2ValidationReport.createFromXml(selectedMessage.getDetailedResults()); diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/context/ProfileDefinition.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/context/ProfileDefinition.java new file mode 100644 index 0000000000000000000000000000000000000000..f71aecbecd2e877f2fbee10903dead1de9cab772 --- /dev/null +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/context/ProfileDefinition.java @@ -0,0 +1,87 @@ +package net.ihe.gazelle.hl7.validator.context; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * <p>ProfileDefinition class.</p> + * + * @author abe + * @version 1.0: 09/07/19 + */ + +@XmlRootElement(name = "ProfileDefinition") +@XmlAccessorType(XmlAccessType.NONE) +public class ProfileDefinition { + + @XmlElement(name = "DomainKeyword") + private String domainKeyword; + + @XmlElement(name = "ActorKeyword") + private String actorKeyword; + + @XmlElement(name = "TransactionKeyword") + private String transactionKeyword; + + @XmlElement(name = "MessageType") + private String messageType; + + @XmlElement(name = "HL7Version") + private String hl7Version; + + @XmlElement(name = "MessageOrderControlCode") + private String messageOrdreControlCode; + + public ProfileDefinition() { + } + + public String getDomainKeyword() { + return domainKeyword; + } + + public void setDomainKeyword(String domainKeyword) { + this.domainKeyword = domainKeyword; + } + + public String getActorKeyword() { + return actorKeyword; + } + + public void setActorKeyword(String actorKeyword) { + this.actorKeyword = actorKeyword; + } + + public String getTransactionKeyword() { + return transactionKeyword; + } + + public void setTransactionKeyword(String transactionKeyword) { + this.transactionKeyword = transactionKeyword; + } + + public String getMessageType() { + return messageType; + } + + public void setMessageType(String messageType) { + this.messageType = messageType; + } + + public String getHl7Version() { + return hl7Version; + } + + public void setHl7Version(String hl7Version) { + this.hl7Version = hl7Version; + } + + public String getMessageOrdreControlCode() { + return messageOrdreControlCode; + } + + public void setMessageOrdreControlCode(String messageOrdreControlCode) { + this.messageOrdreControlCode = messageOrdreControlCode; + } +} diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/context/ValidationContext.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/context/ValidationContext.java new file mode 100644 index 0000000000000000000000000000000000000000..f38a333c6ddd6c8bff3cc6009834c787d130b93f --- /dev/null +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/context/ValidationContext.java @@ -0,0 +1,107 @@ +package net.ihe.gazelle.hl7.validator.context; + +import net.ihe.gazelle.hl7.validator.report.HL7v2ValidationReport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.io.ByteArrayInputStream; +import java.nio.charset.Charset; + +/** + * <p>ValidationContext class.</p> + * + * @author abe + * @version 1.0: 09/07/19 + */ + +@XmlRootElement(name = "ValidationContext") +@XmlAccessorType(XmlAccessType.NONE) +public class ValidationContext { + + private static final Logger LOG = LoggerFactory.getLogger(ValidationContext.class); + + @XmlElement(name = "ProfileOID") + private String profileOid; + + @XmlElement(name = "Profile") + private ProfileDefinition profileDefinition; + + @XmlElement(name = "ValidationOptions") + private ValidationOptions validationOptions; + + @XmlElement(name = "CharacterEncoding") + private String encoding; + + public ValidationContext() { + this.validationOptions = new ValidationOptions(); + } + + public String getProfileOid() { + return profileOid; + } + + public void setProfileOid(String profileOid) { + this.profileOid = profileOid; + } + + public ProfileDefinition getProfileDefinition() { + return profileDefinition; + } + + public void setProfileDefinition(ProfileDefinition profileDefinition) { + this.profileDefinition = profileDefinition; + } + + public ValidationOptions getValidationOptions() { + return validationOptions; + } + + public void setValidationOptions(ValidationOptions validationOptions) { + this.validationOptions = validationOptions; + } + + public String getEncoding() { + return encoding; + } + + public void setEncoding(String encoding) { + this.encoding = encoding; + } + + public static ValidationContext createFromString(String xmlValidationContext){ + ByteArrayInputStream is = new ByteArrayInputStream(xmlValidationContext.getBytes(Charset.forName("UTF-8"))); + try { + JAXBContext jc = JAXBContext.newInstance(ValidationContext.class); + Unmarshaller u = jc.createUnmarshaller(); + ValidationContext validationContext = (ValidationContext) u.unmarshal(is); + return validationContext; + }catch(Exception e){ + LOG.error("Unable to unmarshall validation context: " + e.getMessage()); + e.printStackTrace(); + return new ValidationContext(); + } + } + + + public ValidationType getLength() { + return this.validationOptions.getLength(); + } + + public ValidationType getDataValue() { + return this.validationOptions.getDataValue(); + } + + public ValidationType getDatatype() { + return this.validationOptions.getDatatype(); + } + + public ValidationType getMessageStructure() { + return this.validationOptions.getMessageStructure(); + } +} diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/context/ValidationOptions.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/context/ValidationOptions.java new file mode 100644 index 0000000000000000000000000000000000000000..b8e287051071647e2ad6fc05085906111238535e --- /dev/null +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/context/ValidationOptions.java @@ -0,0 +1,65 @@ +package net.ihe.gazelle.hl7.validator.context; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * <p>ValidationOptions class.</p> + * + * @author abe + * @version 1.0: 09/07/19 + */ + +@XmlRootElement(name = "ValidationOptions") +@XmlAccessorType(XmlAccessType.NONE) +public class ValidationOptions { + + @XmlElement(name = "MessageStructure") + private ValidationType messageStructure; + + @XmlElement(name = "Length") + private ValidationType length; + + @XmlElement(name = "DataType") + private ValidationType datatype; + + @XmlElement(name = "DataValue") + private ValidationType dataValue; + + public ValidationOptions() { + } + + public ValidationType getMessageStructure() { + return messageStructure; + } + + public void setMessageStructure(ValidationType messageStructure) { + this.messageStructure = messageStructure; + } + + public ValidationType getLength() { + return length; + } + + public void setLength(ValidationType length) { + this.length = length; + } + + public ValidationType getDatatype() { + return datatype; + } + + public void setDatatype(ValidationType datatype) { + this.datatype = datatype; + } + + public ValidationType getDataValue() { + return dataValue; + } + + public void setDataValue(ValidationType dataValue) { + this.dataValue = dataValue; + } +} diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/context/ValidationType.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/context/ValidationType.java new file mode 100644 index 0000000000000000000000000000000000000000..f9e3ff932a1d7b649317ccee498185bb438ce2c5 --- /dev/null +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/context/ValidationType.java @@ -0,0 +1,18 @@ +package net.ihe.gazelle.hl7.validator.context; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; + +/** + * <p>ValidationType enum.</p> + * + * @author abe + * @version 1.0: 09/07/19 + */ +@XmlEnum +public enum ValidationType { + + @XmlEnumValue("ERROR") ERROR, + @XmlEnumValue("WARNING") WARNING, + @XmlEnumValue("IGNORE") IGNORE +} diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/GenericHL7Validator.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/GenericHL7Validator.java new file mode 100644 index 0000000000000000000000000000000000000000..d30cdf62792354a721541e6f8bdd4e4a7bb5edba --- /dev/null +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/GenericHL7Validator.java @@ -0,0 +1,55 @@ +package net.ihe.gazelle.hl7.validator.core; + +import net.ihe.gazelle.hl7.messageprofiles.model.Profile; +import net.ihe.gazelle.hl7.validator.context.ValidationContext; +import net.ihe.gazelle.hl7.validator.report.HL7v2ValidationReport; + +/** + * <p>GenericHL7Validator class.</p> + * + * @author abe + * @version 1.0: 09/07/19 + */ + +public abstract class GenericHL7Validator { + + private Profile selectedProfile; + private ValidationContext validationContext; + private String messageToValidate; + + GenericHL7Validator(){ + + } + + GenericHL7Validator(Profile profile, ValidationContext validationContext, String message){ + this.selectedProfile = profile; + this.validationContext = validationContext; + this.messageToValidate = message; + } + + abstract void validateMessage(HL7v2ValidationReport validationReport); + + public Profile getSelectedProfile() { + return selectedProfile; + } + + public void setSelectedProfile(Profile selectedProfile) { + this.selectedProfile = selectedProfile; + } + + public ValidationContext getValidationContext() { + return validationContext; + } + + public void setValidationContext(ValidationContext validationContext) { + this.validationContext = validationContext; + } + + public String getMessageToValidate() { + return messageToValidate; + } + + public void setMessageToValidate(String messageToValidate) { + this.messageToValidate = messageToValidate; + } +} diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/HL7Validator.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/HL7Validator.java new file mode 100644 index 0000000000000000000000000000000000000000..3da908a842101c80198a2fd3c2267b7b11e2f32b --- /dev/null +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/HL7Validator.java @@ -0,0 +1,69 @@ +package net.ihe.gazelle.hl7.validator.core; + +import net.ihe.gazelle.hl7.messageprofiles.model.Profile; +import net.ihe.gazelle.hl7.validator.context.ValidationContext; +import net.ihe.gazelle.hl7.validator.report.HL7v2ValidationReport; +import net.ihe.gazelle.hl7.validator.report.ValidationResults; + +/** + * <p>HL7Validator class.</p> + * + * @author abe + * @version 1.0: 09/07/19 + */ + +public class HL7Validator { + + private String callerIP; + private String xmlMessageMetadata; + private String messageToValidate; + private ValidationContext validationContext; + private HL7v2ValidationReport reporter; + + public HL7Validator(String callerIP, String xmlMessageMetaData, String messageToValidate, + String xmlValidationContext) { + this.callerIP = callerIP; + this.xmlMessageMetadata = xmlMessageMetaData; + setMessageToValidate(messageToValidate); + setValidationContext(xmlValidationContext); + + } + + private void setValidationContext(String xmlValidationContext) { + this.validationContext = ValidationContext.createFromString(xmlValidationContext); + } + + private void setMessageToValidate(String inMessage) { + // replace newline character to match HL7 standard + this.messageToValidate = inMessage.replace('\n', '\r'); + } + + public String validate() { + reporter = new HL7v2ValidationReport(); + ValidationResults results = new ValidationResults(validationContext.getLength(), validationContext.getDataValue(), + validationContext.getDatatype(), validationContext.getMessageStructure()); + reporter.setResults(results); + if (validationContext.getProfileOid() == null) { + reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.INVALID_REQUEST); + reporter.getOverview().setValidationAbortedReason("No profile OID provided"); + } else { + // look for the conformance profile + Profile hl7MessageProfile = Profile.getProfileByOID(validationContext.getProfileOid(), null); + if (hl7MessageProfile == null) { + reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.INVALID_REQUEST); + reporter.getOverview().setValidationAbortedReason( + "The given profile OID does not match any HL7 message profile"); + } else { + HapiValidator validator = new HapiValidator(hl7MessageProfile, validationContext, messageToValidate); + reporter.getOverview().setProfileOid(hl7MessageProfile.getOid()); + reporter.getOverview().setProfileRevision(hl7MessageProfile.getRevision()); + validator.validateMessage(reporter); + } + } + return reporter.toString(); + } + + public HL7v2ValidationReport getReport() { + return this.reporter; + } +} diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/HapiValidator.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/HapiValidator.java index 0817b300c4db8faa84d9ba525ec40cfc953e20ea..b1f5005c9a51763e5a2ecf73ef0647ad7fcb5bcb 100644 --- a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/HapiValidator.java +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/HapiValidator.java @@ -11,207 +11,140 @@ import ca.uhn.hl7v2.parser.Parser; import ca.uhn.hl7v2.parser.PipeParser; import net.ihe.gazelle.hl7.messageprofiles.model.Profile; import net.ihe.gazelle.hl7.messageprofiles.model.Resource; +import net.ihe.gazelle.hl7.validator.context.ValidationContext; import net.ihe.gazelle.hl7.validator.model.HL7Message; import net.ihe.gazelle.hl7.validator.model.HL7MessageResults; import net.ihe.gazelle.hl7.validator.report.HL7v2ValidationReport; -import net.ihe.gazelle.hl7.validator.report.ValidationResults; -import net.ihe.gazelle.hl7.validator.report.ValidationResultsOverview; import org.jboss.seam.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.persistence.EntityManager; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import java.io.ByteArrayOutputStream; +import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; -public class HapiValidator { +public class HapiValidator extends GenericHL7Validator { - private HL7Message currentMessage; - private boolean saveResult; - private static Logger log = LoggerFactory.getLogger(HapiValidator.class); + private static Logger LOG = LoggerFactory.getLogger(HapiValidator.class); - public HapiValidator(String callerIP, String xmlMessageMetaData, String messageToValidate, - String xmlValidationContext, boolean saveResult) { - this.saveResult = saveResult; - currentMessage = new HL7Message(xmlValidationContext, xmlMessageMetaData, messageToValidate); - currentMessage.setCallerIP(callerIP); - if (this.saveResult) { - currentMessage.setOid(OIDGenerator.generateNewOIDForMessage((EntityManager) Component - .getInstance("entityManager"))); - } - } + public HapiValidator(Profile profile, ValidationContext validationContext, String message) { + super(profile, validationContext, message); + } - /** - * Prepare the validated message for persistence and subsequently persist. - * - * @return The calculated detailed report. + /** + * Prepare the validated message for persistence and subsequently persist. + * + * @return The calculated detailed report. */ - public String save() { - // parse result to extract the validation status - if (currentMessage.getReport() != null) { - currentMessage.getReport().getCounters() - .setNbOfAssertions(currentMessage.getReport().getResults().getReportCounter()); - currentMessage.getReport().getCounters() - .setNbOfErrors(currentMessage.getReport().getResults().getErrorCounter()); - currentMessage.getReport().getCounters() - .setNbOfWarnings(currentMessage.getReport().getResults().getWarningCounter()); - currentMessage.setDetailedResults(); - currentMessage.setTestResult(currentMessage.getReport().getOverview().getValidationStatus().getStatus()); + public void save() { + HL7Message currentMessage = new HL7Message(); + // parse result to extract the validation status + if (currentMessage.getReport() != null) { + currentMessage.getReport().getCounters() + .setNbOfAssertions(currentMessage.getReport().getResults().getReportCounter()); + currentMessage.getReport().getCounters() + .setNbOfErrors(currentMessage.getReport().getResults().getErrorCounter()); + currentMessage.getReport().getCounters() + .setNbOfWarnings(currentMessage.getReport().getResults().getWarningCounter()); + currentMessage.setDetailedResults(); + currentMessage.setTestResult(currentMessage.getReport().getOverview().getValidationStatus().getStatus()); - } - if (saveResult) { - EntityManager entityManager = (EntityManager) Component.getInstance("entityManager"); - HL7MessageResults hl7MessageResults = entityManager.merge(currentMessage.getHL7MessageResults()); - entityManager.flush(); - currentMessage.setId(hl7MessageResults.getId()); - currentMessage.setHL7MessageResults(hl7MessageResults); - currentMessage = entityManager.merge(currentMessage); - entityManager.flush(); - } - return currentMessage.getDetailedResults(); - } + } + EntityManager entityManager = (EntityManager) Component.getInstance("entityManager"); + HL7MessageResults hl7MessageResults = entityManager.merge(currentMessage.getHL7MessageResults()); + entityManager.flush(); + currentMessage.setId(hl7MessageResults.getId()); + currentMessage.setHL7MessageResults(hl7MessageResults); + entityManager.merge(currentMessage); + entityManager.flush(); + } - /** - * Perform validation of current message and calculate report without persisting. - * - * @see HapiValidator#validate() - * @see HapiValidator#save() - */ - public void calculateReport() { - // parse validation context to retrieve profile OID, validation mode ... - ValidationContextHandler contextHandler = new ValidationContextHandler(currentMessage); - currentMessage = contextHandler.parseMessageContext(); - HL7v2ValidationReport reporter = new HL7v2ValidationReport(); - reporter.setOverview(new ValidationResultsOverview(currentMessage.getProfileOid(), currentMessage.getOid())); - ValidationResults results = new ValidationResults(currentMessage.getLength(), currentMessage.getData(), - currentMessage.getDatatype(), currentMessage.getMessageStructure()); - reporter.setResults(results); - ResourceStoreFactory resourceStoreFactory = new ResourceStoreFactory(); - - if (currentMessage.getProfileOid() == null) { - reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.INVALID_REQUEST); - reporter.getOverview().setValidationAbortedReason("No profile OID provided"); - currentMessage.setReport(reporter); - } else { - // replace newline character to match HL7 standard - String messageString = currentMessage.getMessage(); - - // look for the conformance profile - Profile hl7MessageProfile = Profile.getProfileByOID(currentMessage.getProfileOid(), null); - if (hl7MessageProfile == null) { - reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.INVALID_REQUEST); - reporter.getOverview().setValidationAbortedReason( - "The given profile OID does not match any HL7 message profile"); - currentMessage.setReport(reporter); - } else { - reporter.getOverview().setProfileRevision(hl7MessageProfile.getRevision()); - reporter.setResources(hl7MessageProfile.getResources()); - // Do not validate the profile against the DTD ! - ProfileParser profileParser = new ProfileParser(false); - RuntimeProfile runtimeProfile = null; - boolean proceed = true; - try { - runtimeProfile = profileParser.parse(new String(hl7MessageProfile.getContent(), Charset - .forName("UTF-8"))); - runtimeProfile.getMessage().setIdentifier(currentMessage.getProfileOid()); - } catch (ProfileException e) { - reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.ABORTED); - reporter.getOverview().setValidationAbortedReason("The HL7 message profile is not parsable"); - currentMessage.setReport(reporter); - log.error(e.getMessage(), e); - proceed = false; - } - if (proceed) { - // declare tables - if ((hl7MessageProfile.getResources() != null) && !hl7MessageProfile.getResources().isEmpty()) { - for (Resource resource : hl7MessageProfile.getResources()) { - try { - CodeStore codeStore = new ResourceCodeStore(resource.getContent(), resource.getOid()); - resourceStoreFactory.addCodeStore(codeStore, runtimeProfile.getMessage().getIdentifier(), - resource.getWeight()); - } catch (Exception e) { - reporter.getResults().addProfileException( - "Resource " + resource.getOid() + " : " + e.getMessage(), null, null); - } - } - } else { - reporter.getResults().addProfileException( - "No resources are available for profile: " + hl7MessageProfile.getOid(), null, null); - } - - // parse the message - Message hapiMessage = null; - Parser parser = null; - if (currentMessage.getEncoding() == null || currentMessage.getEncoding().equalsIgnoreCase("er7")){ - parser = PipeParser.getInstanceWithNoValidation(); - } else if (currentMessage.getEncoding().equalsIgnoreCase("xml")){ - parser = DefaultXMLParser.getInstanceWithNoValidation(); - } else{ - reporter.getOverview().setValidationAbortedReason(currentMessage.getEncoding() + " is not a valid encoding, use ER7 or XML"); - reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.ABORTED); - currentMessage.setReport(reporter); - proceed = false; - } - if (proceed) { - try { - if (hl7MessageProfile.getJavaPackage() != null) { - hapiMessage = parser.parseForSpecificPackage(messageString, - hl7MessageProfile.getJavaPackage()); - } else { - hapiMessage = parser.parse(messageString); - } - } catch (HL7Exception e) { - reporter.getOverview().setValidationAbortedReason("The HL7 message is not parsable"); - reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.ABORTED); - reporter.getResults().addNotification(e.getMessage(), GazelleErrorCode.FORMAT, null, null); - ((GazelleHL7Exception) reporter.getResults().getLastNotification()).getHl7Exception().setLocation( - e.getLocation()); - currentMessage.setReport(reporter); - proceed = false; - } - if (proceed) { - // Validation performed here ! - GazelleValidator validator = new GazelleValidator(resourceStoreFactory, reporter.getResults()); - validator.validate(hapiMessage, runtimeProfile.getMessage(), runtimeProfile.getHL7Version()); - - if (reporter.getResults().getExceptionCounter() > 0) { - currentMessage.setRaisesProfileExceptions(true); - } else { - currentMessage.setRaisesProfileExceptions(false); - } - - // successful validation (no error/no warning) - if (reporter.getResults().getErrorCounter() == 0) { - reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.PASSED); - } else { - reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.FAILED); - } - currentMessage.setReport(reporter); - } - } - } - } - } - } - - /** - * Validate the current message by first calculating the validation report and then persisting. - * - * @see HapiValidator#calculateReport() - * @see HapiValidator#save() - * - * @return The detailed validation report for the current message. + /** + * Perform validation of current message and calculate report without persisting. + * + * @see HapiValidator#save() */ - public String validate() { - calculateReport(); - return save(); - } + @Override + void validateMessage(HL7v2ValidationReport reporter) { + ResourceStoreFactory resourceStoreFactory = new ResourceStoreFactory(); + reporter.setResources(getSelectedProfile().getResources()); + // Do not validate the profile against the DTD ! + ProfileParser profileParser = new ProfileParser(false); + RuntimeProfile runtimeProfile = null; + boolean proceed = true; + try { + runtimeProfile = profileParser.parse(new String(getSelectedProfile().getContent(), Charset + .forName("UTF-8"))); + runtimeProfile.getMessage().setIdentifier(getSelectedProfile().getOid()); + } catch (ProfileException e) { + reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.ABORTED); + reporter.getOverview().setValidationAbortedReason("The HL7 message profile is not parsable"); + LOG.error(e.getMessage(), e); + proceed = false; + } + if (proceed) { + // declare tables + if ((getSelectedProfile().getResources() != null) && !getSelectedProfile().getResources().isEmpty()) { + for (Resource resource : getSelectedProfile().getResources()) { + try { + CodeStore codeStore = new ResourceCodeStore(resource.getContent(), resource.getOid()); + resourceStoreFactory.addCodeStore(codeStore, runtimeProfile.getMessage().getIdentifier(), + resource.getWeight()); + } catch (Exception e) { + reporter.getResults().addProfileException( + "Resource " + resource.getOid() + " : " + e.getMessage(), null, null); + } + } + } else { + reporter.getResults().addProfileException( + "No resources are available for profile: " + getSelectedProfile().getOid(), null, null); + } - /** - * Get the currently wrapped HL7 message. - * - * @return The message. - */ - public HL7Message getMessage() { - return currentMessage; - } + // parse the message + Message hapiMessage = null; + Parser parser = null; + if (getValidationContext().getEncoding() == null || getValidationContext().getEncoding().equalsIgnoreCase("er7")) { + parser = PipeParser.getInstanceWithNoValidation(); + } else if (getValidationContext().getEncoding().equalsIgnoreCase("xml")) { + parser = DefaultXMLParser.getInstanceWithNoValidation(); + } else { + reporter.getOverview().setValidationAbortedReason(getValidationContext().getEncoding() + " is not a valid encoding, use ER7 or XML"); + reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.ABORTED); + proceed = false; + } + if (proceed) { + try { + String javaPackage = getSelectedProfile().getJavaPackage(); + if (javaPackage != null) { + hapiMessage = parser.parseForSpecificPackage(getMessageToValidate(), javaPackage); + } else { + hapiMessage = parser.parse(getMessageToValidate()); + } + } catch (HL7Exception e) { + reporter.getOverview().setValidationAbortedReason("The HL7 message is not parsable"); + reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.ABORTED); + reporter.getResults().addNotification(e.getMessage(), GazelleErrorCode.FORMAT, null, null); + ((GazelleHL7Exception) reporter.getResults().getLastNotification()).getHl7Exception().setLocation( + e.getLocation()); + proceed = false; + } + if (proceed) { + // Validation performed here ! + GazelleValidator validator = new GazelleValidator(resourceStoreFactory, reporter.getResults()); + validator.validate(hapiMessage, runtimeProfile.getMessage(), runtimeProfile.getHL7Version()); + + // successful validation (no error/no warning) + if (reporter.getResults().getErrorCounter() == 0) { + reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.PASSED); + } else { + reporter.getOverview().setValidationStatus(net.ihe.gazelle.hl7.validator.report.ValidationStatus.FAILED); + } + } + } + } + } } diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/ValidationContextHandler.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/ValidationContextHandler.java index 024fc296e31804b60e0f4cc91dc77d96a9714544..bbfe35d96b8938c3d8082b6c964a0a9b272ad76c 100644 --- a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/ValidationContextHandler.java +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/core/ValidationContextHandler.java @@ -26,6 +26,7 @@ import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; +@Deprecated public class ValidationContextHandler extends DefaultHandler { private Log log = Logging.getLog(ValidationContextHandler.class); diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/report/HL7v2ValidationReport.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/report/HL7v2ValidationReport.java index e1c38f30c0e219d0493c0f371553b6add64b5b37..c1967900f42602d791fb3d22eee7b2f8a7f5703c 100644 --- a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/report/HL7v2ValidationReport.java +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/report/HL7v2ValidationReport.java @@ -49,12 +49,19 @@ public class HL7v2ValidationReport { @XmlElement(name = "ValidationResults") private ValidationResults results; + public HL7v2ValidationReport(){ + + } + /** * <p>Getter for the field <code>overview</code>.</p> * * @return a {@link net.ihe.gazelle.hl7.validator.report.ValidationResultsOverview} object. */ public ValidationResultsOverview getOverview() { + if (this.overview == null){ + this.overview = new ValidationResultsOverview(); + } return overview; } diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/report/ValidationResults.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/report/ValidationResults.java index c40577648c2eeb94f6aded540f38e17db4fd5554..d75c1dd0015be0673f18fa3ce6bac26b010e92e7 100644 --- a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/report/ValidationResults.java +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/report/ValidationResults.java @@ -1,6 +1,7 @@ package net.ihe.gazelle.hl7.validator.report; import ca.uhn.hl7v2.HL7Exception; +import net.ihe.gazelle.hl7.validator.context.ValidationType; import net.ihe.gazelle.hl7.validator.core.GazelleErrorCode; import net.ihe.gazelle.hl7.validator.core.GazelleHL7Assertion; import net.ihe.gazelle.hl7.validator.core.GazelleHL7Assertion.AssertionType; @@ -70,24 +71,24 @@ public class ValidationResults { * @param actionOnDatatype a {@link java.lang.String} object. * @param actionOnSequenceError a {@link java.lang.String} object. */ - public ValidationResults(String actionOnLength, String actionOnValueNotFound, String actionOnDatatype, - String actionOnSequenceError) { - if (HL7Message.ERROR.equals(actionOnLength)) { + public ValidationResults(ValidationType actionOnLength, ValidationType actionOnValueNotFound, ValidationType actionOnDatatype, + ValidationType actionOnSequenceError) { + if (ValidationType.ERROR.equals(actionOnLength)) { this.lengthIsAnError = true; } else { this.lengthIsAnError = false; } - if (HL7Message.ERROR.equals(actionOnValueNotFound)) { + if (ValidationType.ERROR.equals(actionOnValueNotFound)) { this.notFountValueIsAnError = true; } else { this.notFountValueIsAnError = false; } - if (HL7Message.ERROR.equals(actionOnDatatype)) { + if (ValidationType.ERROR.equals(actionOnDatatype)) { this.wrongDatatypeIsAnError = true; } else { this.wrongDatatypeIsAnError = false; } - if (HL7Message.ERROR.equals(actionOnSequenceError)) { + if (ValidationType.ERROR.equals(actionOnSequenceError)) { this.wrongSequenceIsAnError = true; } else { this.wrongSequenceIsAnError = false; diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/report/ValidationResultsOverview.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/report/ValidationResultsOverview.java index 1ad95423a59de351ea7731c3ed2265a0b9ba5396..f1ab56d21ac56b4764d6c53deb8b488258101c81 100644 --- a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/report/ValidationResultsOverview.java +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/validator/report/ValidationResultsOverview.java @@ -1,5 +1,7 @@ package net.ihe.gazelle.hl7.validator.report; +import net.ihe.gazelle.hl7.validator.core.OIDGenerator; +import net.ihe.gazelle.hql.providers.EntityManagerService; import net.ihe.version.ws.Interface.Preferences; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,221 +25,228 @@ import java.util.Locale; @XmlAccessorType(XmlAccessType.FIELD) public class ValidationResultsOverview { - private static Logger log = LoggerFactory.getLogger(ValidationResultsOverview.class); - - private final String SDF_DATE = "yyyy, MM dd"; - private final String SDF_TIME = "hh:mm (aa)"; - /** Constant <code>TOOL_NAME="Gazelle HL7 Validator"</code> */ - public static final String TOOL_NAME = "Gazelle HL7 Validator"; - private static final String DISCLAIMER = "The GazelleHL7v2Validator is an experimental system. IHE-Europe assumes no responsibility whatsoever " - + "for its use by other parties, and makes no guarantees, expressed or implied, about its quality, reliability, or " - + "any other characteristic. We would appreciate acknowledgement if the service is used. " - + "Bug tracking service is available at http://gazelle.ihe.net/jira/browse/HLVAL"; - - @XmlTransient - private Date validationDateTime; - - @XmlElement(name = "ProfileOID") - private String profileOid; - - @XmlElement(name = "ProfileRevision") - private String profileRevision; - - @XmlElement(name = "MessageOID") - private String messageOid; - - @XmlElement(name = "ValidationAbortedReason") - private String validationAbortedReason; - - @XmlTransient - private ValidationStatus validationStatus; - - /** - * <p>Constructor for ValidationResultsOverview.</p> - */ - public ValidationResultsOverview() { - - } - - /** - * <p>Constructor for ValidationResultsOverview.</p> - * - * @param profileOid a {@link java.lang.String} object. - * @param messageOid a {@link java.lang.String} object. - */ - public ValidationResultsOverview(String profileOid, String messageOid) { - this.profileOid = profileOid; - this.messageOid = messageOid; - this.validationDateTime = new Date(); - } - - /** - * <p>Getter for the field <code>validationDateTime</code>.</p> - * - * @return a {@link java.util.Date} object. - */ - public Date getValidationDateTime() { - return validationDateTime; - } - - /** - * <p>Setter for the field <code>validationDateTime</code>.</p> - * - * @param validationDateTime a {@link java.util.Date} object. - */ - public void setValidationDateTime(Date validationDateTime) { - this.validationDateTime = validationDateTime; - } - - /** - * <p>getValidationDate.</p> - * - * @return a {@link java.lang.String} object. - */ - @XmlElement(name = "ValidationDate") - public String getValidationDate() { - SimpleDateFormat sdf = new SimpleDateFormat(SDF_DATE, Locale.ENGLISH); - return sdf.format(validationDateTime); - } - - /** - * <p>getValidationTime.</p> - * - * @return a {@link java.lang.String} object. - */ - @XmlElement(name = "ValidationTime") - public String getValidationTime() { - SimpleDateFormat sdf = new SimpleDateFormat(SDF_TIME, Locale.ENGLISH); - return sdf.format(validationDateTime); - } - - /** - * <p>getValidationServiceVersion.</p> - * - * @return a {@link java.lang.String} object. - */ - @XmlElement(name = "ValidationServiceVersion") - public String getValidationServiceVersion() { - return Preferences.getProperty("buildVersion"); - } - - /** - * <p>getValidationServiceName.</p> - * - * @return a {@link java.lang.String} object. - */ - @XmlElement(name = "ValidationServiceName") - public String getValidationServiceName() { - return TOOL_NAME; - } - - /** - * <p>Getter for the field <code>profileOid</code>.</p> - * - * @return a {@link java.lang.String} object. - */ - public String getProfileOid() { - return profileOid; - } - - /** - * <p>Setter for the field <code>profileOid</code>.</p> - * - * @param profileOid a {@link java.lang.String} object. - */ - public void setProfileOid(String profileOid) { - this.profileOid = profileOid; - } - - /** - * <p>Getter for the field <code>profileRevision</code>.</p> - * - * @return a {@link java.lang.String} object. - */ - public String getProfileRevision() { - return profileRevision; - } - - /** - * <p>Setter for the field <code>profileRevision</code>.</p> - * - * @param profileRevision a {@link java.lang.String} object. - */ - public void setProfileRevision(String profileRevision) { - this.profileRevision = profileRevision; - } - - /** - * <p>Getter for the field <code>messageOid</code>.</p> - * - * @return a {@link java.lang.String} object. - */ - public String getMessageOid() { - return messageOid; - } - - /** - * <p>Setter for the field <code>messageOid</code>.</p> - * - * @param messageOid a {@link java.lang.String} object. - */ - public void setMessageOid(String messageOid) { - this.messageOid = messageOid; - } - - /** - * <p>getDisclaimer.</p> - * - * @return a {@link java.lang.String} object. - */ - @XmlElement(name = "Disclaimer") - public String getDisclaimer() { - return DISCLAIMER; - } - - /** - * <p>getValidationTestResult.</p> - * - * @return a {@link java.lang.String} object. - */ - @XmlElement(name = "ValidationTestResult") - public String getValidationTestResult() { - return validationStatus.getStatus(); - } - - /** - * <p>Getter for the field <code>validationAbortedReason</code>.</p> - * - * @return a {@link java.lang.String} object. - */ - public String getValidationAbortedReason() { - return validationAbortedReason; - } - - /** - * <p>Setter for the field <code>validationAbortedReason</code>.</p> - * - * @param validationAbortedReason a {@link java.lang.String} object. - */ - public void setValidationAbortedReason(String validationAbortedReason) { - this.validationAbortedReason = validationAbortedReason; - } - - /** - * <p>Getter for the field <code>validationStatus</code>.</p> - * - * @return a {@link ValidationStatus} object. - */ - public ValidationStatus getValidationStatus() { - return validationStatus; - } - - /** - * <p>Setter for the field <code>validationStatus</code>.</p> - * - * @param validationStatus a {@link ValidationStatus} object. - */ - public void setValidationStatus(ValidationStatus validationStatus) { - this.validationStatus = validationStatus; - } + private final String SDF_DATE = "yyyy, MM dd"; + private final String SDF_TIME = "hh:mm (aa)"; + /** + * Constant <code>TOOL_NAME="Gazelle HL7 Validator"</code> + */ + public static final String TOOL_NAME = "Gazelle HL7 Validator"; + private static final String DISCLAIMER = "The GazelleHL7v2Validator is an experimental system. IHE-Europe assumes no responsibility whatsoever " + + "for its use by other parties, and makes no guarantees, expressed or implied, about its quality, reliability, or " + + "any other characteristic. We would appreciate acknowledgement if the service is used. " + + "Bug tracking service is available at http://gazelle.ihe.net/jira/browse/HLVAL"; + + @XmlTransient + private Date validationDateTime; + + @XmlElement(name = "ProfileOID") + private String profileOid; + + @XmlElement(name = "ProfileRevision") + private String profileRevision; + + @XmlElement(name = "MessageOID") + private String messageOid; + + @XmlElement(name = "ValidationAbortedReason") + private String validationAbortedReason; + + @XmlTransient + private ValidationStatus validationStatus; + + /** + * <p>Constructor for ValidationResultsOverview.</p> + */ + public ValidationResultsOverview() { + this.validationDateTime = new Date(); + } + + /** + * <p>Constructor for ValidationResultsOverview.</p> + * + * @param profileOid a {@link java.lang.String} object. + */ + public ValidationResultsOverview(String profileOid) { + this.profileOid = profileOid; + this.messageOid = generateNextOid(); + this.validationDateTime = new Date(); + } + + private String generateNextOid() { + try { + return OIDGenerator.generateNewOIDForMessage(EntityManagerService.provideEntityManager()); + } catch (Exception e) { + return "testOID"; + } + } + + /** + * <p>Getter for the field <code>validationDateTime</code>.</p> + * + * @return a {@link java.util.Date} object. + */ + public Date getValidationDateTime() { + return validationDateTime; + } + + /** + * <p>Setter for the field <code>validationDateTime</code>.</p> + * + * @param validationDateTime a {@link java.util.Date} object. + */ + public void setValidationDateTime(Date validationDateTime) { + this.validationDateTime = validationDateTime; + } + + /** + * <p>getValidationDate.</p> + * + * @return a {@link java.lang.String} object. + */ + @XmlElement(name = "ValidationDate") + public String getValidationDate() { + SimpleDateFormat sdf = new SimpleDateFormat(SDF_DATE, Locale.ENGLISH); + return sdf.format(validationDateTime); + } + + /** + * <p>getValidationTime.</p> + * + * @return a {@link java.lang.String} object. + */ + @XmlElement(name = "ValidationTime") + public String getValidationTime() { + SimpleDateFormat sdf = new SimpleDateFormat(SDF_TIME, Locale.ENGLISH); + return sdf.format(validationDateTime); + } + + /** + * <p>getValidationServiceVersion.</p> + * + * @return a {@link java.lang.String} object. + */ + @XmlElement(name = "ValidationServiceVersion") + public String getValidationServiceVersion() { + return Preferences.getProperty("buildVersion"); + } + + /** + * <p>getValidationServiceName.</p> + * + * @return a {@link java.lang.String} object. + */ + @XmlElement(name = "ValidationServiceName") + public String getValidationServiceName() { + return TOOL_NAME; + } + + /** + * <p>Getter for the field <code>profileOid</code>.</p> + * + * @return a {@link java.lang.String} object. + */ + public String getProfileOid() { + return profileOid; + } + + /** + * <p>Setter for the field <code>profileOid</code>.</p> + * + * @param profileOid a {@link java.lang.String} object. + */ + public void setProfileOid(String profileOid) { + this.profileOid = profileOid; + } + + /** + * <p>Getter for the field <code>profileRevision</code>.</p> + * + * @return a {@link java.lang.String} object. + */ + public String getProfileRevision() { + return profileRevision; + } + + /** + * <p>Setter for the field <code>profileRevision</code>.</p> + * + * @param profileRevision a {@link java.lang.String} object. + */ + public void setProfileRevision(String profileRevision) { + this.profileRevision = profileRevision; + } + + /** + * <p>Getter for the field <code>messageOid</code>.</p> + * + * @return a {@link java.lang.String} object. + */ + public String getMessageOid() { + return messageOid; + } + + /** + * <p>Setter for the field <code>messageOid</code>.</p> + * + * @param messageOid a {@link java.lang.String} object. + */ + public void setMessageOid(String messageOid) { + this.messageOid = messageOid; + } + + /** + * <p>getDisclaimer.</p> + * + * @return a {@link java.lang.String} object. + */ + @XmlElement(name = "Disclaimer") + public String getDisclaimer() { + return DISCLAIMER; + } + + /** + * <p>getValidationTestResult.</p> + * + * @return a {@link java.lang.String} object. + */ + @XmlElement(name = "ValidationTestResult") + public String getValidationTestResult() { + return validationStatus.getStatus(); + } + + /** + * <p>Getter for the field <code>validationAbortedReason</code>.</p> + * + * @return a {@link java.lang.String} object. + */ + public String getValidationAbortedReason() { + return validationAbortedReason; + } + + /** + * <p>Setter for the field <code>validationAbortedReason</code>.</p> + * + * @param validationAbortedReason a {@link java.lang.String} object. + */ + public void setValidationAbortedReason(String validationAbortedReason) { + this.validationAbortedReason = validationAbortedReason; + } + + /** + * <p>Getter for the field <code>validationStatus</code>.</p> + * + * @return a {@link ValidationStatus} object. + */ + public ValidationStatus getValidationStatus() { + return validationStatus; + } + + /** + * <p>Setter for the field <code>validationStatus</code>.</p> + * + * @param validationStatus a {@link ValidationStatus} object. + */ + public void setValidationStatus(ValidationStatus validationStatus) { + this.validationStatus = validationStatus; + } } diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/ws/GazelleHL7v2ValidationGITBWS.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/ws/GazelleHL7v2ValidationGITBWS.java index 6b98152fa6b0582f17f173ecf35893035eec17b3..6a83ea22d80b846f7534ee274729ff29319b9795 100644 --- a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/ws/GazelleHL7v2ValidationGITBWS.java +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/ws/GazelleHL7v2ValidationGITBWS.java @@ -8,10 +8,12 @@ import com.gitb.vs.Void; import net.ihe.gazelle.common.interfacegenerator.GenerateInterface; import net.ihe.gazelle.hl7.validator.core.GazelleHL7Assertion; import net.ihe.gazelle.hl7.validator.core.GazelleHL7Exception; +import net.ihe.gazelle.hl7.validator.core.HL7Validator; import net.ihe.gazelle.hl7.validator.core.HapiValidator; import net.ihe.gazelle.hl7.validator.model.HL7Message; import net.ihe.gazelle.hl7.validator.report.Error; import net.ihe.gazelle.hl7.validator.report.GazelleProfileException; +import net.ihe.gazelle.hl7.validator.report.HL7v2ValidationReport; import net.ihe.gazelle.hl7.validator.report.ValidationResultsOverview; import net.ihe.gazelle.hl7.validator.report.Warning; import net.ihe.version.ws.Interface.Preferences; @@ -34,6 +36,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.net.*; +import java.util.Date; import java.util.GregorianCalendar; import java.util.List; @@ -131,12 +134,11 @@ public class GazelleHL7v2ValidationGITBWS implements GazelleHL7v2ValidationGITBW } Lifecycle.beginCall(); HttpServletRequest hRequest = (HttpServletRequest) jaxwsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST); - HapiValidator validator = new HapiValidator(hRequest.getRemoteAddr(), xmlValidationMetadata, messageToValidate, - xmlValidationContext, true); - validator.calculateReport(); + HL7Validator validator = new HL7Validator(hRequest.getRemoteAddr(), xmlValidationMetadata, messageToValidate, + xmlValidationContext); + validator.validate(); ValidationResponse result = new ValidationResponse(); - result.setReport(toTestReport(validateRequest, validator.getMessage())); - validator.save(); + result.setReport(toTestReport(validateRequest, validator.getReport())); Lifecycle.endCall(); return result; } @@ -203,34 +205,34 @@ public class GazelleHL7v2ValidationGITBWS implements GazelleHL7v2ValidationGITBW * Produce the GITB test report based on the received request and the processing outcome. * * @param validateRequest The request that was received by the validation service. - * @param processedMessage The deserialised HL7 message including its validation outcome. + * @param reportFromTool The deserialised HL7 message including its validation outcome. * @return The validation report in GITB TRL. */ - private TAR toTestReport(ValidateRequest validateRequest, HL7Message processedMessage) { + private TAR toTestReport(ValidateRequest validateRequest, HL7v2ValidationReport reportFromTool) { TAR report = new TAR(); // Validation request context. report.setContext(new AnyContent()); for (AnyContent input: validateRequest.getInput()) { report.getContext().getItem().add(input); } - if (processedMessage != null && processedMessage.getReport() != null) { + if (reportFromTool != null) { // Counters. report.setCounters(new ValidationCounters()); - report.getCounters().setNrOfAssertions(BigInteger.valueOf(processedMessage.getReport().getResults().getReportCounter())); - report.getCounters().setNrOfErrors(BigInteger.valueOf(processedMessage.getReport().getResults().getErrorCounter())); - report.getCounters().setNrOfWarnings(BigInteger.valueOf(processedMessage.getReport().getResults().getWarningCounter())); + report.getCounters().setNrOfAssertions(BigInteger.valueOf(reportFromTool.getResults().getReportCounter())); + report.getCounters().setNrOfErrors(BigInteger.valueOf(reportFromTool.getResults().getErrorCounter())); + report.getCounters().setNrOfWarnings(BigInteger.valueOf(reportFromTool.getResults().getWarningCounter())); // Date. GregorianCalendar c = new GregorianCalendar(); - c.setTime(processedMessage.getValidationDate()); + c.setTime(new Date()); try { report.setDate(DatatypeFactory.newInstance().newXMLGregorianCalendar(c)); } catch (DatatypeConfigurationException e) { throw new IllegalStateException("Unable to construct validation date", e); } // Overview information. - if (processedMessage.getReport().getOverview() != null) { + if (reportFromTool.getOverview() != null) { report.setOverview(new ValidationOverview()); - switch (processedMessage.getReport().getOverview().getValidationStatus()) { + switch (reportFromTool.getOverview().getValidationStatus()) { case PASSED: report.setResult(TestResultType.SUCCESS); break; @@ -241,17 +243,17 @@ public class GazelleHL7v2ValidationGITBWS implements GazelleHL7v2ValidationGITBW report.setResult(TestResultType.UNDEFINED); break; } - report.getOverview().setProfileID(processedMessage.getReport().getOverview().getProfileOid()); - report.getOverview().setNote(processedMessage.getReport().getOverview().getDisclaimer()); - report.getOverview().setValidationServiceName(processedMessage.getReport().getOverview().getValidationServiceName()); - report.getOverview().setValidationServiceVersion(processedMessage.getReport().getOverview().getValidationServiceVersion()); - report.getOverview().setTransactionID(processedMessage.getReport().getOverview().getMessageOid()); + report.getOverview().setProfileID(reportFromTool.getOverview().getProfileOid()); + report.getOverview().setNote(reportFromTool.getOverview().getDisclaimer()); + report.getOverview().setValidationServiceName(reportFromTool.getOverview().getValidationServiceName()); + report.getOverview().setValidationServiceVersion(reportFromTool.getOverview().getValidationServiceVersion()); + report.getOverview().setTransactionID(reportFromTool.getOverview().getMessageOid()); } // Results. report.setReports(new TestAssertionGroupReportsType()); ObjectFactory trFactory = new ObjectFactory(); - if (processedMessage.getReport().getResults() != null) { - List<Object> notifications = processedMessage.getReport().getResults().getNotifications(); + if (reportFromTool.getResults() != null) { + List<Object> notifications = reportFromTool.getResults().getNotifications(); for (Object notification: notifications) { if (notification instanceof Error) { addError(report.getReports(), (Error)notification, trFactory); diff --git a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/ws/GazelleHL7v2ValidationWS.java b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/ws/GazelleHL7v2ValidationWS.java index 44e520de2618ebce0b663929c61f4fb390636c27..a93a2b96274ef92b841ca34a94422132ff93e1c3 100644 --- a/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/ws/GazelleHL7v2ValidationWS.java +++ b/GazelleHL7v2Validator-ejb/src/main/java/net/ihe/gazelle/hl7/ws/GazelleHL7v2ValidationWS.java @@ -16,9 +16,14 @@ package net.ihe.gazelle.hl7.ws; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; +import net.ihe.gazelle.common.interfacegenerator.GenerateInterface; +import net.ihe.gazelle.hl7.validator.core.HL7Validator; +import net.ihe.version.ws.Interface.Preferences; +import org.jboss.seam.annotations.Name; +import org.jboss.seam.contexts.Lifecycle; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.w3c.dom.bootstrap.DOMImplementationRegistry; import javax.annotation.Resource; import javax.ejb.Stateless; @@ -31,16 +36,6 @@ import javax.xml.soap.SOAPException; import javax.xml.ws.WebServiceContext; import javax.xml.ws.handler.MessageContext; -import net.ihe.gazelle.common.interfacegenerator.GenerateInterface; -import net.ihe.gazelle.hl7.validator.core.HapiValidator; - -import net.ihe.version.ws.Interface.Preferences; -import org.jboss.seam.annotations.Name; -import org.jboss.seam.contexts.Lifecycle; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.w3c.dom.bootstrap.DOMImplementationRegistry; - @Stateless @Name("gazelleHL7v2ValidationWS") @WebService(name = "gazelleHL7v2ValidationWS", serviceName = "gazelleHL7v2ValidationWSService") @@ -70,8 +65,8 @@ public class GazelleHL7v2ValidationWS implements GazelleHL7v2ValidationWSRemote } Lifecycle.beginCall(); HttpServletRequest hRequest = (HttpServletRequest) jaxwsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST); - HapiValidator validator = new HapiValidator(hRequest.getRemoteAddr(), xmlValidationMetadata, messageToValidate, - xmlValidationContext, true); + HL7Validator validator = new HL7Validator(hRequest.getRemoteAddr(), xmlValidationMetadata, messageToValidate, + xmlValidationContext); String result = validator.validate(); Lifecycle.endCall(); return result; diff --git a/GazelleHL7v2Validator-ejb/src/test/java/net/ihe/gazelle/hl7/validator/test/AbstractTest.java b/GazelleHL7v2Validator-ejb/src/test/java/net/ihe/gazelle/hl7/validator/test/AbstractTest.java index 65fdb08e40708f697d3aeb6a5138656c48f47a27..960ee3a81a5cc425fd1c7fcaec3d4da52adf24f0 100644 --- a/GazelleHL7v2Validator-ejb/src/test/java/net/ihe/gazelle/hl7/validator/test/AbstractTest.java +++ b/GazelleHL7v2Validator-ejb/src/test/java/net/ihe/gazelle/hl7/validator/test/AbstractTest.java @@ -3,6 +3,7 @@ package net.ihe.gazelle.hl7.validator.test; import java.io.File; import java.io.FileInputStream; +import net.ihe.gazelle.hl7.validator.context.ValidationType; import net.ihe.gazelle.hl7.validator.core.GazelleValidator; import net.ihe.gazelle.hl7.validator.core.ResourceStoreFactory; import net.ihe.gazelle.hl7.validator.report.HL7v2ValidationReport; @@ -20,7 +21,10 @@ import ca.uhn.hl7v2.parser.PipeParser; public abstract class AbstractTest { + public static final ValidationType ERROR = ValidationType.ERROR; + public static final ValidationType IGNORE = ValidationType.IGNORE; private static Logger log = LoggerFactory.getLogger(AbstractTest.class); + private String ignore; protected HL7v2ValidationReport validate(String packageName, String messageToValidate, String profilePath) { try { @@ -32,8 +36,8 @@ public abstract class AbstractTest { message = parser.parseForSpecificPackage(messageToValidate, packageName); } HL7v2ValidationReport reporter = new HL7v2ValidationReport(); - reporter.setOverview(new ValidationResultsOverview("Test", "test")); - ValidationResults results = new ValidationResults("IGNORE", "IGNORE", "ERROR", "ERROR"); + reporter.setOverview(new ValidationResultsOverview("Test")); + ValidationResults results = new ValidationResults(IGNORE, IGNORE, ERROR, ERROR); reporter.setResults(results); GazelleValidator validator = new GazelleValidator(new ResourceStoreFactory(), reporter.getResults()); File profileFile = new File(profilePath); diff --git a/GazelleHL7v2Validator-ejb/src/test/java/net/ihe/gazelle/hl7/validator/test/Test.java b/GazelleHL7v2Validator-ejb/src/test/java/net/ihe/gazelle/hl7/validator/test/Test.java index b142491247f7397aa7bfdcb3760f7825441efdd7..811727ae6600ceadbf709b422cedfa8c1a246570 100644 --- a/GazelleHL7v2Validator-ejb/src/test/java/net/ihe/gazelle/hl7/validator/test/Test.java +++ b/GazelleHL7v2Validator-ejb/src/test/java/net/ihe/gazelle/hl7/validator/test/Test.java @@ -6,6 +6,7 @@ import ca.uhn.hl7v2.conf.parser.ProfileParser; import ca.uhn.hl7v2.conf.spec.RuntimeProfile; import ca.uhn.hl7v2.model.Message; import ca.uhn.hl7v2.parser.PipeParser; +import net.ihe.gazelle.hl7.validator.context.ValidationType; import net.ihe.gazelle.hl7.validator.core.GazelleValidator; import net.ihe.gazelle.hl7.validator.core.ResourceStoreFactory; import net.ihe.gazelle.hl7.validator.report.HL7v2ValidationReport; @@ -233,7 +234,7 @@ public class Test { // Message message = parser.parseForSpecificPackage(messageToValidate, packageName); HL7v2ValidationReport reporter = new HL7v2ValidationReport(); - reporter.setResults(new ValidationResults("WARNING", "WARNING", "ERROR", "ERROR")); + reporter.setResults(new ValidationResults(ValidationType.WARNING, ValidationType.WARNING, ValidationType.ERROR, ValidationType.ERROR)); GazelleValidator validator = new GazelleValidator(new ResourceStoreFactory(), reporter.getResults()); File profileFile = new File(profilePath);