1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.xds.core.validate;
17
18 import static org.apache.commons.lang3.Validate.notNull;
19 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.*;
20 import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.*;
21
22 import java.util.regex.Matcher;
23 import java.util.regex.Pattern;
24
25
26
27
28
29
30 public class PidValidator implements ValueValidator {
31 private static final Pattern PID_PATTERN = Pattern.compile("\\s*PID-([1-9][0-9]*)\\|(.*)\\s*");
32
33 @Override
34 public void validate(String value) throws XDSMetaDataException {
35 notNull(value, "value cannot be null");
36
37 Matcher matcher = PID_PATTERN.matcher(value);
38 metaDataAssert(matcher.matches(), INVALID_PID, value);
39
40 int number = Integer.parseInt(matcher.group(1));
41 metaDataAssert(number != 2 && number != 4 && number != 12 && number != 19 && number <= 39,
42 UNSUPPORTED_PID, value);
43 }
44 }