public static String createUserAgentString(FhirContext theContext, String theClientType) { StringBuilder b = new StringBuilder(); b.append("HAPI-FHIR/"); b.append(VersionUtil.getVersion()); b.append(" (FHIR Client; FHIR "); b.append(theContext.getVersion().getVersion().getFhirVersionString()); b.append('/'); b.append(theContext.getVersion().getVersion().name()); b.append("; "); b.append(theClientType); b.append(")"); return b.toString(); }
@SuppressWarnings("unchecked") @Override public void initializeTypes(Method theMethod, Class<? extends Collection<?>> theOuterCollectionType, Class<? extends Collection<?>> theInnerCollectionType, Class<?> theParameterType) { if (getContext().getVersion().getVersion().isRi()) { if (IDatatype.class.isAssignableFrom(theParameterType)) { throw new ConfigurationException("Incorrect use of type " + theParameterType.getSimpleName() + " as parameter type for method when context is for version " + getContext().getVersion().getVersion().name() + " in method: " + theMethod.toString());
try { String capabilityStatementResourceName = "CapabilityStatement"; if (myContext.getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { capabilityStatementResourceName = "Conformance"; implementingClass = myContext.getResourceDefinition(capabilityStatementResourceName).getImplementingClass(); } catch (DataFormatException e) { if (!myContext.getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { capabilityStatementResourceName = "Conformance"; implementingClass = myContext.getResourceDefinition(capabilityStatementResourceName).getImplementingClass(); conformance = (IBaseResource) client.fetchConformance().ofType(implementingClass).execute(); } catch (FhirClientConnectionException e) { if (!myContext.getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3) && e.getCause() instanceof DataFormatException) { capabilityStatementResourceName = "CapabilityStatement"; implementingClass = myContext.getResourceDefinition(capabilityStatementResourceName).getImplementingClass(); if (serverFhirVersionString.equals(FhirVersionEnum.DSTU2.getFhirVersionString())) { serverFhirVersionEnum = FhirVersionEnum.DSTU2; } else if (serverFhirVersionString.equals(FhirVersionEnum.DSTU2_1.getFhirVersionString())) { serverFhirVersionEnum = FhirVersionEnum.DSTU2_1; } else if (serverFhirVersionString.equals(FhirVersionEnum.DSTU3.getFhirVersionString())) { serverFhirVersionEnum = FhirVersionEnum.DSTU3; } else if (serverFhirVersionString.equals(FhirVersionEnum.R4.getFhirVersionString())) { serverFhirVersionEnum = FhirVersionEnum.R4; } else { if (!contextFhirVersion.isEquivalentTo(serverFhirVersionEnum)) { throw new FhirClientInappropriateForServerException(myContext.getLocalizer().getMessage(RestfulClientFactory.class, "wrongVersionInConformance",
/** * Returns the {@link FhirVersionEnum} which corresponds to a specific version of * FHIR. Partial version strings (e.g. "3.0") are acceptable. * * @return Returns null if no version exists matching the given string */ public static FhirVersionEnum forVersionString(String theVersionString) { for (FhirVersionEnum next : values()) { if (next.getFhirVersionString().startsWith(theVersionString)) { return next; } } return null; }
public IFhirVersion getVersionImplementation() { if (!isPresentOnClasspath()) { throw new IllegalStateException("Version " + name() + " is not present on classpath"); } if (myVersionImplementation == null) { try { myVersionImplementation = (IFhirVersion) Class.forName(myVersionClass).newInstance(); } catch (Exception e) { throw new InternalErrorException("Failed to instantiate FHIR version " + name(), e); } } return myVersionImplementation; }
@Override protected void addFhirVersionOption(Options theOptions) { String versions = Arrays.stream(FhirVersionEnum.values()) .filter(t -> t != FhirVersionEnum.DSTU2_1 && t != FhirVersionEnum.DSTU2_HL7ORG && t != FhirVersionEnum.DSTU2) .map(t -> t.name().toLowerCase()) .sorted() .collect(Collectors.joining(", ")); addRequiredOption(theOptions, FHIR_VERSION_PARAM, FHIR_VERSION_PARAM_LONGOPT, FHIR_VERSION_PARAM_NAME, FHIR_VERSION_PARAM_DESC + versions); }
@Override public String getVersion() { return myCtx.getVersion().getVersion().getFhirVersionString(); }
public String getResourcePackage() { if (BaseStructureSpreadsheetParser.determineVersionEnum(version).isRi()) { return "org.hl7.fhir." + version + ".model"; } return "ca.uhn.fhir.model." + version + ".resource"; }
@Initialize public void initialize(RestfulServer theServer) { ourLog.trace("Initializing GraphQL provider"); if (theServer.getFhirContext().getVersion().getVersion() != FhirVersionEnum.R4) { throw new ConfigurationException("Can not use " + getClass().getName() + " provider on server with FHIR " + theServer.getFhirContext().getVersion().getVersion().name() + " context"); } }
private void scanBlock(Class<? extends IBase> theClass) { ourLog.debug("Scanning resource block class: {}", theClass.getName()); String resourceName = theClass.getCanonicalName(); if (isBlank(resourceName)) { throw new ConfigurationException("Block type @" + Block.class.getSimpleName() + " annotation contains no name: " + theClass.getCanonicalName()); } // Just in case someone messes up when upgrading from DSTU2 if (myContext.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.DSTU3)) { if (BaseIdentifiableElement.class.isAssignableFrom(theClass)) { throw new ConfigurationException("@Block class for version " + myContext.getVersion().getVersion().name() + " should not extend " + BaseIdentifiableElement.class.getSimpleName() + ": " + theClass.getName()); } } RuntimeResourceBlockDefinition blockDef = new RuntimeResourceBlockDefinition(resourceName, theClass, isStandardType(theClass), myContext, myClassToElementDefinitions); blockDef.populateScanAlso(myScanAlso); myClassToElementDefinitions.put(theClass, blockDef); }
if (myContext.getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { if (myContext.getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) {
if (!theVersion.isPresentOnClasspath()) { throw new IllegalStateException(getLocalizer().getMessage(FhirContext.class, "noStructuresForSpecifiedVersion", theVersion.name())); myVersion = theVersion.getVersionImplementation(); } else if (FhirVersionEnum.DSTU2.isPresentOnClasspath()) { myVersion = FhirVersionEnum.DSTU2.getVersionImplementation(); } else if (FhirVersionEnum.DSTU2_HL7ORG.isPresentOnClasspath()) { myVersion = FhirVersionEnum.DSTU2_HL7ORG.getVersionImplementation(); } else if (FhirVersionEnum.DSTU2_1.isPresentOnClasspath()) { myVersion = FhirVersionEnum.DSTU2_1.getVersionImplementation(); } else if (FhirVersionEnum.DSTU3.isPresentOnClasspath()) { myVersion = FhirVersionEnum.DSTU3.getVersionImplementation(); } else if (FhirVersionEnum.R4.isPresentOnClasspath()) { myVersion = FhirVersionEnum.R4.getVersionImplementation(); } else { throw new IllegalStateException(getLocalizer().getMessage(FhirContext.class, "noStructures")); myVersion.getVersion().name()); } else { ourLog.info("Creating new FHIR context for FHIR version [{}]", myVersion.getVersion().name());
public ResponseEncoding(FhirContext theCtx, EncodingEnum theEncoding, String theContentType) { super(); myEncoding = theEncoding; myContentType = theContentType; if (theContentType != null) { FhirVersionEnum ctxtEnum = theCtx.getVersion().getVersion(); if (theContentType.equals(EncodingEnum.JSON_PLAIN_STRING) || theContentType.equals(EncodingEnum.XML_PLAIN_STRING)) { myNonLegacy = ctxtEnum.isNewerThan(FhirVersionEnum.DSTU2_1); } else { myNonLegacy = ctxtEnum.isNewerThan(FhirVersionEnum.DSTU2_1) && !EncodingEnum.isLegacy(theContentType); } } else { FhirVersionEnum ctxtEnum = theCtx.getVersion().getVersion(); if (ctxtEnum.isOlderThan(FhirVersionEnum.DSTU3)) { myNonLegacy = null; } else { myNonLegacy = Boolean.TRUE; } } }
SortSpec ss = (SortSpec) theSourceClientArgument; if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU2)) { String string = createSortStringDstu3(ss); if (string.length() > 0) {
private String getSubsettedCodeSystem() { if (myContext.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.R4)) { return Constants.TAG_SUBSETTED_SYSTEM_R4; } else { return Constants.TAG_SUBSETTED_SYSTEM_DSTU3; } }
protected void parseFhirContext(CommandLine theCommandLine) throws ParseException { String version = theCommandLine.getOptionValue(FHIR_VERSION_PARAM); if (isBlank(version)) { throw new ParseException("Missing required option: -" + FHIR_VERSION_PARAM); } try { FhirVersionEnum versionEnum = FhirVersionEnum.valueOf(version.toUpperCase()); myFhirCtx = versionEnum.newContext(); } catch (Exception e) { throw new ParseException("Invalid FHIR version string: " + version); } }
public void setFhirVersion(String fhirVersion) { this.fhirVersion = FhirVersionEnum.valueOf(fhirVersion); }
retVal.setFhirVersion(Enumerations.FHIRVersion.fromCode(FhirVersionEnum.R4.getFhirVersionString()));
public static Integer findIdParameterIndex(Method theMethod, FhirContext theContext) { Integer index = findParamAnnotationIndex(theMethod, IdParam.class); if (index != null) { Class<?> paramType = theMethod.getParameterTypes()[index]; if (IIdType.class.equals(paramType)) { return index; } boolean isRi = theContext.getVersion().getVersion().isRi(); boolean usesHapiId = IdDt.class.equals(paramType); if (isRi == usesHapiId) { throw new ConfigurationException("Method uses the wrong Id datatype (IdDt / IdType) for the given context FHIR version: " + theMethod.toString()); } } return index; }
context.setVariable("fhirVersion", myContext.getVersion().getVersion().name()); context.setVariable("resource", value);