001package org.hl7.fhir.r5.terminologies.utilities; 002 003import org.hl7.fhir.r5.model.Parameters; 004import org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent; 005import org.hl7.fhir.utilities.Utilities; 006 007 008//URL: http://snomed.info/sct/[module]/version/[e.g. 20150131]' 009//International: 900000000000207008 010//US: 731000124108 011//Australia: 32506021000036107 012//Belgium: 11000172109 013//Canada: 20611000087101 014//Spain: 449081005 015//Denmark: 554471000005108 016//Netherlands: 11000146104 017//Sweden: 45991000052106 018//Switzerland: 2011000195101 019//UK: 83821000000107 020//IPS: 827022005 021 022public class SnomedUtilities { 023 024 public static String getVersionFromParameters(Parameters p, String version) { 025 for (ParametersParameterComponent pp : p.getParameter()) { 026 switch (pp.getName()) { 027 case "system-version" : 028 if (version == null) { 029 return pp.getValue().primitiveValue(); 030 } 031 case "force-system-version": 032 return pp.getValue().primitiveValue(); 033 } 034 } 035 return version; 036 } 037 038 public static String getEditionFromVersion(String version) { 039 if (version == null) { 040 return null; 041 } 042 if (version.startsWith("http://snomed.info/sct/")) { 043 version = version.substring(23); 044 } 045 if (version.contains("/")) { 046 version = version.substring(0, version.indexOf("/")); 047 } 048 if (Utilities.existsInList(version, "900000000000207008", "731000124108", "32506021000036107", "11000172109", "20611000087101", 049 "449081005", "554471000005108", "11000146104", "45991000052106", "2011000195101", "83821000000107", "827022005")) { 050 return version; 051 } else { 052 return null; 053 } 054 } 055 056 public static String getSctLink(String version, String code, Parameters p) { 057 if (!Utilities.noString(code)) { 058 version = SnomedUtilities.getVersionFromParameters(p, version); 059 String edId = SnomedUtilities.getEditionFromVersion(version); 060 if (edId != null) { 061 // if there's a version that's an edition, then: 062 // http://snomed.info/sct/11000172109/id//371305003 063 return "http://snomed.info/sct/"+edId+"/id/"+code; 064 } else { 065 // no, version: 066 return "http://snomed.info/id/"+code; 067 } 068 } else { 069 return "https://browser.ihtsdotools.org/"; 070 } 071 } 072} 073 074