View Javadoc
1   /*
2    * Copyright 2011 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.hl7v2ws.pcd01;
17  
18  import ca.uhn.hl7v2.HL7Exception;
19  import ca.uhn.hl7v2.model.v26.message.ORU_R01;
20  import org.junit.Ignore;
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  
25  /**
26   * @author Kingsley Nwaigbo
27   * 
28   */
29  @Ignore
30  public class QA_Pcd01OBXValidatorTest extends AbstractPCD01ValidatorTest {
31  
32      @Test
33      public void testSyntheticMessageTrimmed() throws HL7Exception{
34          ORU_R01 adapter = (ORU_R01)getParser().parse(maximumMessage.toString().trim());
35          validate(adapter);
36          assertObservationCount(5, adapter);
37      }
38      
39      //################ OBX Segment tests ###############################
40      
41      @Test(expected = HL7Exception.class)
42      public void testMissingOBX1() throws HL7Exception {
43          validate(maxMsgReplace("OBX|1|NM|528391", "OBX||NM|528391"));
44      }
45      
46      @Test(expected = HL7Exception.class)
47      public void testWrongSetIDForOBX1() throws HL7Exception {
48          validate(maxMsgReplace("OBX|2||150020", "OBX|1||150020"));
49      }
50      
51      @Test(expected = HL7Exception.class) 
52      public void testMissingOBX2_filledOBX5() throws HL7Exception {
53          validate(maxMsgReplace("OBX|1|NM|528391", "OBX|1||528391"));
54      }
55      
56      @Test
57      public void testOBX2_SN() throws HL7Exception {
58          validate(maxMsgReplace("OBX|1|NM|528391^MDC_DEV_SPEC_PROFILE_BP^MDC|1|80|", "OBX|1|SN|528391^MDC_DEV_SPEC_PROFILE_BP^MDC|1|>80|"));
59      }
60      
61      
62      @Ignore
63      @Test(expected = HL7Exception.class)
64      public void testMissingOBX2_filledOBX11() throws HL7Exception {
65          // The check "OBX-2 must be valued if the value of OBX-11 is not X" seems to be too restrictive
66          // add the checkOBX2WhenOBX11NotX in PCD01Validator to switch on the check. 
67         validate(maxMsgReplace("OBX|1|NM|528391^MDC_DEV_SPEC_PROFILE_BP^MDC|1|80|", "OBX|1||528391^MDC_DEV_SPEC_PROFILE_BP^MDC|1||"));
68      }
69      
70      @Test(expected = HL7Exception.class)
71      public void testMissingOBX3() throws HL7Exception {
72          validate(maxMsgReplace("OBX|1|NM|528391^MDC_DEV_SPEC_PROFILE_BP^MDC|1|80|", "OBX|1|NM||1||"));
73      }
74      
75      @Test(expected = HL7Exception.class)
76      public void testSpaceAsOBX3() throws HL7Exception {
77          validate(maxMsgReplace("OBX|1|NM|528391^MDC_DEV_SPEC_PROFILE_BP^MDC|1|80|", "OBX|1|NM|    |1||"));
78      }
79      
80      
81      @Test(expected = HL7Exception.class)
82      public void testMissingOBX3_2() throws HL7Exception {
83          validate(maxMsgReplace("OBX|1|NM|528391^MDC_DEV_SPEC_PROFILE_BP^MDC|1|", "OBX|1|NM|528391^^MDC|1|"));
84      }
85      
86      @Test(expected = HL7Exception.class)
87      public void testSpaceAsOBX3_2() throws HL7Exception {
88          validate(maxMsgReplace("OBX|1|NM|528391^MDC_DEV_SPEC_PROFILE_BP^MDC|1|", "OBX|1|NM|528391^  ^MDC|1|"));
89      }
90      
91      @Test(expected = HL7Exception.class)
92      public void testMissingOBX4() throws HL7Exception {
93          validate(maxMsgReplace("OBX|1|NM|528391^MDC_DEV_SPEC_PROFILE_BP^MDC|1|80|", "OBX|1|NM|528391^MDC_DEV_SPEC_PROFILE_BP^MDC|||"));
94      }
95      
96      @Test(expected = HL7Exception.class)
97      public void testSpaceAsOBX4() throws HL7Exception {
98         validate(maxMsgReplace("OBX|1|NM|528391^MDC_DEV_SPEC_PROFILE_BP^MDC|1|80|", "OBX|1|NM|528391^MDC_DEV_SPEC_PROFILE_BP^MDC| ||"));
99      }
100     
101     @Test(expected = HL7Exception.class)
102     @Ignore
103     public void testSameValueIn2OBX3AndOBX4Fields() throws HL7Exception {
104         //TODO The spec does not say explicitly that the OBX-3 and OBX-4 can not be the same, ignoring currently this test
105         validate(maxMsgReplace("OBX|4|NM|1500212^MDC_PRESS_BLD_NONINV_SYS^MDC|1.0.1.2|", "OBX|4|NM|1500212^MDC_PRESS_BLD_NONINV_SYS^MDC|1.0.1.1|"));
106     }
107     
108     @Test 
109     public void testMissingOBX5() throws HL7Exception {
110         validate(maxMsgReplace("|80|mmHg|", "||mmHg|"));
111     }
112     
113     @Test 
114     public void testMissingOBX5_OBX6() throws HL7Exception {
115         validate(maxMsgReplace("|80|mmHg|", "|||"));
116     }
117     
118     @Test 
119     public void testMissingOBX7() throws HL7Exception {
120         validate(maxMsgReplace("|75 - 90|TEST|||R|", "||TEST|||R|"));
121     }
122     
123     @Test 
124     public void testMissingOBX8() throws HL7Exception {
125        validate(maxMsgReplace("|75 - 90|TEST|||R|", "|75 - 90||||R|"));
126     }
127     
128     @Test(expected = HL7Exception.class)
129     @Ignore
130     public void testMissingOBX6_filledOBX5() throws HL7Exception {
131         //This seems to be guaranteed by the parser, therefore no explicit check is needed
132         //The parser produces empty OBX-5 in this case (the isEmpty() DSL method returns true).
133         validate( maxMsgReplace("|80|mmHg|", "|80||"));
134     }
135     
136     @Test(expected = HL7Exception.class)
137     public void testMissingOBX11() throws HL7Exception {
138         validate(maxMsgReplace("|75 - 90|TEST|||R|||", "|75 - 90|TEST||||||"));
139     }
140 
141     @Ignore
142     @Test(expected = HL7Exception.class)
143     public void testMissingOBR7_OBR8_OBX14() throws HL7Exception {
144         ORU_R01 msg = (ORU_R01)getParser().parse(maximumMessage.toString().replace("|20090813095715+0500|20090813105715+0500", "||"));
145         msg = (ORU_R01)getParser().parse(msg.toString().replace("|R|||20090813095725+0500|", "|R||||"));
146         validate(msg);
147     }
148     
149     @Test(expected = HL7Exception.class)
150     @Ignore
151     public void testEquivalenceOfOBX14AndOBX19() throws HL7Exception {
152         //TODO Ignoring the test, as the spec says 'should' and 'may' for OBX-14 and OBX-19
153         validate(maxMsgReplace("|0123456789ABCDEF^EUI-64|20090813095725+0500||", "|0123456789ABCDEF^EUI-64|20100813095725+0500||"));
154     }
155     
156     //check for messages without OBR-7, OBR-8 and OBX-14
157     //check: OBX-14 and OBX-19 should be equivalent
158     private void assertObservationCount(int expected, ORU_R01 msg){
159         int observationsInMsg = msg.getPATIENT_RESULT().getORDER_OBSERVATION().getOBSERVATIONReps();
160         assertEquals(expected, observationsInMsg);
161     }
162     
163 }