001package org.hl7.fhir.r5.terminologies;
002
003import org.hl7.fhir.r5.model.ConceptMap;
004import org.hl7.fhir.r5.model.Identifier;
005import org.hl7.fhir.r5.model.ValueSet;
006
007public class ConceptMapUtilities {
008
009  public static boolean hasOID(ConceptMap cm) {
010    return getOID(cm) != null;
011  }
012
013  public static String getOID(ConceptMap cm) {
014    for (Identifier id : cm.getIdentifier()) {
015      if ("urn:ietf:rfc:3986".equals(id.getSystem()) && id.hasValue() && id.getValue().startsWith("urn:oid:"))
016        return id.getValue().substring(8);
017    }
018    return null;
019  }
020
021  public static void setOID(ConceptMap cm, String oid) {
022    if (!oid.startsWith("urn:oid:"))
023      oid = "urn:oid:" + oid;
024    for (Identifier id : cm.getIdentifier()) {
025      if ("urn:ietf:rfc:3986".equals(id.getSystem()) && id.hasValue() && id.getValue().startsWith("urn:oid:")) {
026        id.setValue(oid);
027        return;
028      }
029    }
030    cm.addIdentifier().setSystem("urn:ietf:rfc:3986").setValue(oid);
031  }
032
033
034}