001package org.hl7.fhir.utilities; 002 003import java.util.ArrayList; 004import java.util.Collections; 005import java.util.HashSet; 006import java.util.List; 007import java.util.Set; 008 009public class SIDUtilities { 010 011 private static final Set<String> CODE_SYSTEMS; 012 private static final Set<String> ID_SYSTEMS; 013 private static final Set<String> INCORRECT_SIDS; 014 private static final Set<String> ALL_SYSTEMS; 015 016 static { 017 // Initialize code systems 018 Set<String> codeSystems = new HashSet<>(); 019 codeSystems.add("http://hl7.org/fhir/sid/ndc"); 020 codeSystems.add("http://hl7.org/fhir/sid/icpc-2"); 021 codeSystems.add("http://hl7.org/fhir/sid/icpc-1"); 022 codeSystems.add("http://hl7.org/fhir/sid/icpc-1-nl"); 023 codeSystems.add("http://hl7.org/fhir/sid/icd-9"); 024 codeSystems.add("http://hl7.org/fhir/sid/icd-10"); 025 codeSystems.add("http://hl7.org/fhir/sid/cvx"); 026 codeSystems.add("http://hl7.org/fhir/sid/srt"); 027 codeSystems.add("http://hl7.org/fhir/sid/icd-10-vn"); 028 codeSystems.add("http://hl7.org/fhir/sid/icd-10-cm"); 029 codeSystems.add("http://hl7.org/fhir/sid/icd-10-am"); 030 codeSystems.add("http://hl7.org/fhir/sid/icd-9-cm"); 031 codeSystems.add("http://hl7.org/fhir/sid/icf-nl"); 032 codeSystems.add("http://hl7.org/fhir/sid/ca-hc-npn"); 033 codeSystems.add("http://hl7.org/fhir/sid/ca-hc-din"); 034 codeSystems.add("http://hl7.org/fhir/sid/dsm5"); 035 codeSystems.add("http://hl7.org/fhir/sid/ex-icd-10-procedures"); 036 CODE_SYSTEMS = Collections.unmodifiableSet(codeSystems); 037 038 // Initialize ID systems 039 Set<String> idSystems = new HashSet<>(); 040 idSystems.add("http://hl7.org/fhir/sid/us-ssn"); 041 idSystems.add("http://hl7.org/fhir/sid/us-npi"); 042 idSystems.add("http://hl7.org/fhir/sid/eui-48/bluetooth"); 043 idSystems.add("http://hl7.org/fhir/sid/eui-48/ethernet"); 044 ID_SYSTEMS = Collections.unmodifiableSet(idSystems); 045 046 // Initialize incorrect SIDs 047 Set<String> incorrectSids = new HashSet<>(); 048 incorrectSids.add("http://hl7.org/fhir/sid/icpc2"); 049 incorrectSids.add("http://hl7.org/fhir/sid/icf-nl"); 050 incorrectSids.add("http://hl7.org/fhir/sid/ca-hc-npn"); 051 incorrectSids.add("http://hl7.org/fhir/sid/ca-hc-din"); 052 incorrectSids.add("http://hl7.org/fhir/sid/dsm5"); 053 INCORRECT_SIDS = Collections.unmodifiableSet(incorrectSids); 054 055 // Initialize all systems 056 Set<String> allSystems = new HashSet<>(); 057 allSystems.addAll(CODE_SYSTEMS); 058 allSystems.addAll(ID_SYSTEMS); 059 ALL_SYSTEMS = Collections.unmodifiableSet(allSystems); 060 } 061 062 public static Set<String> codeSystemList() { 063 return CODE_SYSTEMS; 064 } 065 066 public static Set<String> idSystemList() { 067 return ID_SYSTEMS; 068 } 069 070 private static boolean isPassPortSID(String url) { 071 // TODO: verify ISO countrycode part vs country code list 072 return url.matches("^http:\\/\\/hl7.org\\/fhir\\/sid\\/passport-[a-zA-Z]{3}$"); 073 } 074 075 public static boolean isknownCodeSystem(String system) { 076 return CODE_SYSTEMS.contains(system); 077 } 078 079 public static boolean isKnownSID(String url) { 080 return isknownCodeSystem(url) || isknownIDSystem(url); 081 } 082 083 public static boolean isIncorrectSID(String url) { 084 return INCORRECT_SIDS.contains(url); 085 } 086 087 private static boolean isknownIDSystem(String url) { 088 return ID_SYSTEMS.contains(url) || isPassPortSID(url); 089 } 090 091 public static Set<String> allSystemsList() { 092 return ALL_SYSTEMS; 093 } 094 095 public static boolean isInvalidVersion(String u, String v) { 096 if (v == null) { 097 return false; 098 } else { 099 if (ID_SYSTEMS.contains(u)) { 100 return true; 101 } else { 102 switch (u) { 103 case "http://hl7.org/fhir/sid/ndc": 104 return v.matches("[\\d]{8}"); 105 case "http://hl7.org/fhir/sid/icpc2": 106 return false; 107 case "http://hl7.org/fhir/sid/icd-10": 108 return false; 109 case "http://hl7.org/fhir/sid/icd-9": 110 return false; 111 case "http://hl7.org/fhir/sid/cvx": 112 return v.matches("[\\d]{8}"); 113 case "http://hl7.org/fhir/sid/srt": 114 return false; 115 case "http://hl7.org/fhir/sid/icd-10-vn": 116 return false; 117 case "http://hl7.org/fhir/sid/icd-10-cm": 118 return false; 119 case "http://hl7.org/fhir/sid/icd-10-am": 120 return false; 121 case "http://hl7.org/fhir/sid/icd-9-cm": 122 return false; 123 default: 124 return true; 125 } 126 } 127 } 128 } 129 130}