001package org.hl7.fhir.utilities;
002
003import java.util.ArrayList;
004import java.util.List;
005
006public class SIDUtilities {
007
008  public static List<String> codeSystemList() {
009    List<String> codeSystems = new ArrayList<>();
010    codeSystems.add("http://hl7.org/fhir/sid/ndc");
011    codeSystems.add("http://hl7.org/fhir/sid/icpc2");
012    codeSystems.add("http://hl7.org/fhir/sid/icd-9");
013    codeSystems.add("http://hl7.org/fhir/sid/icd-10");  
014    codeSystems.add("http://hl7.org/fhir/sid/cvx");
015    codeSystems.add("http://hl7.org/fhir/sid/srt");
016    codeSystems.add("http://hl7.org/fhir/sid/icd-10-vn");
017    codeSystems.add("http://hl7.org/fhir/sid/icd-10-cm");
018    codeSystems.add("http://hl7.org/fhir/sid/icd-10-am");
019    codeSystems.add("http://hl7.org/fhir/sid/icd-9-cm");
020    codeSystems.add("http://hl7.org/fhir/sid/ex-icd-10-procedures");
021    return codeSystems;
022  }
023
024  public static List<String> idSystemList() {
025    List<String> idSystems = new ArrayList<>();
026    idSystems.add("http://hl7.org/fhir/sid/us-ssn");
027    idSystems.add("http://hl7.org/fhir/sid/us-npi");
028    idSystems.add("http://hl7.org/fhir/sid/eui-48/bluetooth");
029    idSystems.add("http://hl7.org/fhir/sid/eui-48/ethernet");
030    return idSystems;
031  }
032
033  private static boolean isPassPortSID(String url) {
034    // TODO: verify ISO countrycode part vs country code list
035    return url.matches("^http:\\/\\/hl7.org\\/fhir\\/sid\\/passport-[a-zA-Z]{3}$");
036  }
037  
038  public static boolean isknownCodeSystem(String system) {
039    return codeSystemList().contains(system);
040  }
041
042  public static boolean isKnownSID(String url) {
043    return isknownCodeSystem(url) || isknownIDSystem(url);
044  }
045
046  private static boolean isknownIDSystem(String url) {
047    return idSystemList().contains(url) || isPassPortSID(url);
048  }
049
050  public static List<String> allSystemsList() {
051    List<String> allSystems = new ArrayList<>();
052    allSystems.addAll(codeSystemList());
053    allSystems.addAll(idSystemList());
054    return allSystems;
055  }
056
057  public static boolean isInvalidVersion(String u, String v) {
058    if (v == null) {
059      return false;
060    } else {
061      if (idSystemList().contains(u)) {
062        return true;
063      } else {
064        switch (u) {
065        case "http://hl7.org/fhir/sid/ndc":
066          return v.matches("[\\d]{8}");
067        case "http://hl7.org/fhir/sid/icpc2": 
068          return false;
069        case "http://hl7.org/fhir/sid/icd-10":
070          return false;
071        case "http://hl7.org/fhir/sid/icd-9":
072          return false;
073        case "http://hl7.org/fhir/sid/cvx":
074          return v.matches("[\\d]{8}");
075        case "http://hl7.org/fhir/sid/srt":
076          return false;
077        case "http://hl7.org/fhir/sid/icd-10-vn":
078          return false;
079        case "http://hl7.org/fhir/sid/icd-10-cm":
080          return false;
081        case "http://hl7.org/fhir/sid/icd-10-am":
082          return false;
083        case "http://hl7.org/fhir/sid/icd-9-cm":
084          return false;
085        default:
086          return true;
087        }
088      }
089    }
090  }
091    
092}