001package org.hl7.fhir.r4.utils; 002 003import java.util.ArrayList; 004import java.util.HashMap; 005import java.util.List; 006import java.util.Map; 007 008import org.hl7.fhir.exceptions.FHIRException; 009import org.hl7.fhir.r4.model.Base; 010import org.hl7.fhir.r4.model.Element; 011import org.hl7.fhir.r4.model.ElementDefinition; 012import org.hl7.fhir.r4.model.IntegerType; 013import org.hl7.fhir.r4.model.Property; 014import org.hl7.fhir.r4.model.Resource; 015import org.hl7.fhir.r4.model.StringType; 016import org.hl7.fhir.r4.model.StructureDefinition; 017import org.hl7.fhir.r4.model.TypeDetails; 018import org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent; 019import org.hl7.fhir.utilities.Utilities; 020import org.hl7.fhir.utilities.i18n.I18nConstants; 021 022public class FHIRPathUtilityClasses { 023 024 025 public static class FHIRConstant extends Base { 026 027 private static final long serialVersionUID = -8933773658248269439L; 028 private String value; 029 030 public FHIRConstant(String value) { 031 this.value = value; 032 } 033 034 @Override 035 public String fhirType() { 036 return "%constant"; 037 } 038 039 @Override 040 protected void listChildren(List<Property> result) { 041 } 042 043 @Override 044 public String getIdBase() { 045 return null; 046 } 047 048 @Override 049 public void setIdBase(String value) { 050 } 051 052 public String getValue() { 053 return value; 054 } 055 056 @Override 057 public String primitiveValue() { 058 return value; 059 } 060 061 @Override 062 public Base copy() { 063 throw new Error("Not Implemented"); 064 } 065 066 } 067 068 public static class ClassTypeInfo extends Base { 069 private static final long serialVersionUID = 4909223114071029317L; 070 private Base instance; 071 072 public ClassTypeInfo(Base instance) { 073 super(); 074 this.instance = instance; 075 } 076 077 @Override 078 public String fhirType() { 079 return "ClassInfo"; 080 } 081 082 @Override 083 protected void listChildren(List<Property> result) { 084 } 085 086 @Override 087 public String getIdBase() { 088 return null; 089 } 090 091 @Override 092 public void setIdBase(String value) { 093 } 094 095 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 096 if (name.equals("name")) { 097 return new Base[] { new StringType(getName()) }; 098 } else if (name.equals("namespace")) { 099 return new Base[] { new StringType(getNamespace()) }; 100 } else { 101 return super.getProperty(hash, name, checkValid); 102 } 103 } 104 105 private String getNamespace() { 106 if ((instance instanceof Resource)) { 107 return "FHIR"; 108 } else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) { 109 return "System"; 110 } else { 111 return "FHIR"; 112 } 113 } 114 115 private String getName() { 116 if ((instance instanceof Resource)) { 117 return instance.fhirType(); 118 } else if (!(instance instanceof Element) || ((Element) instance).isDisallowExtensions()) { 119 return Utilities.capitalize(instance.fhirType()); 120 } else { 121 return instance.fhirType(); 122 } 123 } 124 125 @Override 126 public Base copy() { 127 throw new Error("Not Implemented"); 128 } 129 130 } 131 132 public static class TypedElementDefinition { 133 private ElementDefinition element; 134 private String type; 135 private StructureDefinition src; 136 137 public TypedElementDefinition(StructureDefinition src, ElementDefinition element, String type) { 138 super(); 139 this.element = element; 140 this.type = type; 141 this.src = src; 142 } 143 144 public TypedElementDefinition(ElementDefinition element) { 145 super(); 146 this.element = element; 147 } 148 149 public ElementDefinition getElement() { 150 return element; 151 } 152 153 public String getType() { 154 return type; 155 } 156 157 public List<TypeRefComponent> getTypes() { 158 List<TypeRefComponent> res = new ArrayList<ElementDefinition.TypeRefComponent>(); 159 for (TypeRefComponent tr : element.getType()) { 160 if (type == null || type.equals(tr.getCode())) { 161 res.add(tr); 162 } 163 } 164 return res; 165 } 166 167 public boolean hasType(String tn) { 168 if (type != null) { 169 return tn.equals(type); 170 } else { 171 for (TypeRefComponent t : element.getType()) { 172 if (tn.equals(t.getCode())) { 173 return true; 174 } 175 } 176 return false; 177 } 178 } 179 180 public StructureDefinition getSrc() { 181 return src; 182 } 183 } 184 185 public static class FunctionDetails { 186 private String description; 187 private int minParameters; 188 private int maxParameters; 189 190 public FunctionDetails(String description, int minParameters, int maxParameters) { 191 super(); 192 this.description = description; 193 this.minParameters = minParameters; 194 this.maxParameters = maxParameters; 195 } 196 197 public String getDescription() { 198 return description; 199 } 200 201 public int getMinParameters() { 202 return minParameters; 203 } 204 205 public int getMaxParameters() { 206 return maxParameters; 207 } 208 209 } 210}