001package org.hl7.fhir.r4.utils;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import org.hl7.fhir.utilities.Utilities;
007
008
009public class TypesUtilities {
010
011  public static class WildcardInformation {
012    private String typeName;
013    private String comment;
014    public WildcardInformation(String typeName, String comment) {
015      super();
016      this.typeName = typeName;
017      this.comment = comment;
018    }
019    public WildcardInformation(String typeName) {
020      super();
021      this.typeName = typeName;
022    }
023    public String getTypeName() {
024      return typeName;
025    }
026    public String getComment() {
027      return comment;
028    }
029    
030  }
031  
032  public static List<String> wildcardTypes() {
033    List<String> res = new ArrayList<String>();
034    for (WildcardInformation wi : wildcards())
035      res.add(wi.getTypeName());
036    return res;
037  }
038  
039  // this is the master list for what data types are allowed where the types = *
040  // that this list is incomplete means that the following types cannot have fixed values in a profile:
041  //   Narrative
042  //   Meta
043  //   Any of the IDMP data types
044  // You have to walk into them to profile them.
045  //
046  public static List<WildcardInformation> wildcards() {
047    List<WildcardInformation> res = new ArrayList<WildcardInformation>();
048
049    // primitive types
050    res.add(new WildcardInformation("base64Binary"));
051    res.add(new WildcardInformation("boolean"));
052    res.add(new WildcardInformation("canonical"));
053    res.add(new WildcardInformation("code", "(only if the extension definition provides a <a href=\"terminologies.html#code\">fixed</a> binding to a suitable set of codes)"));
054    res.add(new WildcardInformation("date"));
055    res.add(new WildcardInformation("dateTime"));
056    res.add(new WildcardInformation("decimal"));
057    res.add(new WildcardInformation("id"));
058    res.add(new WildcardInformation("instant"));
059    res.add(new WildcardInformation("integer"));
060    res.add(new WildcardInformation("markdown"));
061    res.add(new WildcardInformation("oid"));
062    res.add(new WildcardInformation("positiveInt"));
063    res.add(new WildcardInformation("string"));
064    res.add(new WildcardInformation("time"));
065    res.add(new WildcardInformation("unsignedInt"));
066    res.add(new WildcardInformation("uri"));
067    res.add(new WildcardInformation("url"));
068    res.add(new WildcardInformation("uuid"));
069
070    // Complex general purpose data types
071    res.add(new WildcardInformation("Address"));
072    res.add(new WildcardInformation("Age"));
073    res.add(new WildcardInformation("Annotation"));
074    res.add(new WildcardInformation("Attachment"));
075    res.add(new WildcardInformation("CodeableConcept"));
076    res.add(new WildcardInformation("Coding"));
077    res.add(new WildcardInformation("ContactPoint"));
078    res.add(new WildcardInformation("Count"));
079    res.add(new WildcardInformation("Distance"));
080    res.add(new WildcardInformation("Duration"));
081    res.add(new WildcardInformation("HumanName"));
082    res.add(new WildcardInformation("Identifier"));
083    res.add(new WildcardInformation("Money"));
084    res.add(new WildcardInformation("Period"));
085    res.add(new WildcardInformation("Quantity"));
086    res.add(new WildcardInformation("Range"));
087    res.add(new WildcardInformation("Ratio"));
088    res.add(new WildcardInformation("Reference", " - a reference to another resource"));
089    res.add(new WildcardInformation("SampledData"));
090    res.add(new WildcardInformation("Signature"));
091    res.add(new WildcardInformation("Timing"));
092    
093    // metadata types
094    res.add(new WildcardInformation("ParameterDefinition"));
095    res.add(new WildcardInformation("DataRequirement"));
096    res.add(new WildcardInformation("RelatedArtifact"));
097    res.add(new WildcardInformation("ContactDetail"));
098    res.add(new WildcardInformation("Contributor"));
099    res.add(new WildcardInformation("TriggerDefinition"));
100    res.add(new WildcardInformation("Expression"));
101    res.add(new WildcardInformation("UsageContext"));
102    
103    // special cases
104    res.add(new WildcardInformation("Dosage"));
105    return res;
106  }
107
108  public static boolean isPrimitive(String code) {
109    return Utilities.existsInList(code, "boolean", "integer", "string", "decimal", "uri", "url", "canonical", "base64Binary", "instant", "date", "dateTime", "time", "code", "oid", "id", "markdown", "unsignedInt", "positiveInt", "xhtml");
110  }
111}
112