1 /*
2 * Copyright 2012 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.xds.core.validate;
17
18 import ca.uhn.hl7v2.model.v25.datatype.HD;
19 import org.apache.commons.lang3.StringUtils;
20
21 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.*;
22 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;
23
24 /**
25 * Validator for HL7 v2 HD elements.
26 * @author Dmytro Rud
27 */
28 public class HDValidator {
29 private static final OIDValidator OID_VALIDATOR = new OIDValidator();
30
31
32 /**
33 * Validates an HL7 v2 HD element.
34 * @param hd
35 * HD element.
36 * @param original
37 * original string from XDS message where which contained the given HD element.
38 */
39 public void validate(HD hd, String original) {
40 metaDataAssert(StringUtils.isEmpty(hd.getHd1_NamespaceID().getValue()),
41 HD_MUST_NOT_HAVE_NAMESPACE_ID, original);
42
43 metaDataAssert("ISO".equals(hd.getHd3_UniversalIDType().getValue()),
44 UNIVERSAL_ID_TYPE_MUST_BE_ISO, original);
45
46 String oid = hd.getHd2_UniversalID().getValue();
47 metaDataAssert(StringUtils.isNotEmpty(oid), HD_NEEDS_UNIVERSAL_ID, original);
48
49 OID_VALIDATOR.validate(oid);
50 }
51 }