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(); }
private static FhirContext getContextForVersion(FhirContext theContext, FhirVersionEnum theForVersion) { FhirContext context = theContext; if (context.getVersion().getVersion() != theForVersion) { context = myFhirContextMap.get(theForVersion); if (context == null) { context = theForVersion.newContext(); myFhirContextMap.put(theForVersion, context); } } return context; }
public BaseIgPackParser(FhirContext theCtx) { FhirVersionEnum expectedVersion = provideExpectedVersion(); Validate.isTrue(theCtx.getVersion().getVersion() == expectedVersion, "theCtx is not for the correct version, expecting " + expectedVersion); myCtx = theCtx; }
@Override public final void encodeResourceToWriter(IBaseResource theResource, Writer theWriter) throws IOException, DataFormatException { Validate.notNull(theResource, "theResource can not be null"); Validate.notNull(theWriter, "theWriter can not be null"); if (theResource.getStructureFhirVersionEnum() != myContext.getVersion().getVersion()) { throw new IllegalArgumentException( "This parser is for FHIR version " + myContext.getVersion().getVersion() + " - Can not encode a structure for version " + theResource.getStructureFhirVersionEnum()); } doEncodeResourceToWriter(theResource, theWriter); }
@Override public void encodeResourceToJsonLikeWriter(IBaseResource theResource, JsonLikeWriter theJsonLikeWriter) throws IOException, DataFormatException { Validate.notNull(theResource, "theResource can not be null"); Validate.notNull(theJsonLikeWriter, "theJsonLikeWriter can not be null"); if (theResource.getStructureFhirVersionEnum() != myContext.getVersion().getVersion()) { throw new IllegalArgumentException( "This parser is for FHIR version " + myContext.getVersion().getVersion() + " - Can not encode a structure for version " + theResource.getStructureFhirVersionEnum()); } doEncodeResourceToJsonLikeWriter(theResource, theJsonLikeWriter); }
private String getSubsettedCodeSystem() { if (myContext.getVersion().getVersion().isEqualOrNewerThan(FhirVersionEnum.R4)) { return Constants.TAG_SUBSETTED_SYSTEM_R4; } else { return Constants.TAG_SUBSETTED_SYSTEM_DSTU3; } }
static FhirContext getHl7OrgDstu2Ctx(FhirContext theCtx) { if (theCtx.getVersion().getVersion() == FhirVersionEnum.DSTU2_HL7ORG) { return theCtx; } FhirContext retVal = ourHl7OrgCtx; if (retVal == null) { retVal = FhirContext.forDstu2Hl7Org(); ourHl7OrgCtx = retVal; } return retVal; }
private static FhirContext massage(FhirContext theCtx) { if (theCtx.getVersion().getVersion() == FhirVersionEnum.DSTU2) { return FhirContext.forDstu2Hl7Org(); } else { return theCtx; } }
protected List<String> createPoweredByAttributes() { return Lists.newArrayList("FHIR Server", "FHIR " + myFhirContext.getVersion().getVersion().getFhirVersionString() + "/" + myFhirContext.getVersion().getVersion().name()); }
@Override public String getVersion() { return myCtx.getVersion().getVersion().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; }
@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"); } }
public CanonicalSubscription canonicalize(S theSubscription) { switch (myFhirContext.getVersion().getVersion()) { case DSTU2: return canonicalizeDstu2(theSubscription); case DSTU3: return canonicalizeDstu3(theSubscription); case R4: return canonicalizeR4(theSubscription); default: throw new ConfigurationException("Subscription not supported for version: " + myFhirContext.getVersion().getVersion()); } }
private IBaseBundle getBundleFromFile(Integer theLimit, File theSuppliedFile, FhirContext theCtx) throws ParseException, IOException { switch (theCtx.getVersion().getVersion()) { case DSTU2: return getBundleFromFileDstu2(theLimit, theSuppliedFile, theCtx); case DSTU3: return getBundleFromFileDstu3(theLimit, theSuppliedFile, theCtx); case R4: return getBundleFromFileR4(theLimit, theSuppliedFile, theCtx); default: throw new ParseException("Invalid spec version for this command: " + theCtx.getVersion().getVersion()); } }
public String getCriteria(IBaseResource theSubscription) { switch (myFhirContext.getVersion().getVersion()) { case DSTU2: return ((ca.uhn.fhir.model.dstu2.resource.Subscription)theSubscription).getCriteria(); case DSTU3: return ((org.hl7.fhir.dstu3.model.Subscription)theSubscription).getCriteria(); case R4: return ((org.hl7.fhir.r4.model.Subscription)theSubscription).getCriteria(); default: throw new ConfigurationException("Subscription not supported for version: " + myFhirContext.getVersion().getVersion()); } }
private void processBundle(FhirContext ctx, IBaseBundle bundle) { switch (ctx.getVersion().getVersion()) { case DSTU2: processBundleDstu2(ctx, (Bundle) bundle); break; case DSTU3: processBundleDstu3(ctx, (org.hl7.fhir.dstu3.model.Bundle) bundle); break; case R4: processBundleR4(ctx, (org.hl7.fhir.r4.model.Bundle) bundle); break; default: throw new IllegalStateException(); } }
public static IPrimitiveType<?> createString(FhirContext theContext, String theValue) { IPrimitiveType<?> value; if (theContext.getVersion().getVersion().isRi()) { value = (IPrimitiveType<?>) theContext.getElementDefinition("string").newInstance(theValue); } else { value = new StringDt(theValue); } return value; }
private String getContentType(EncodingEnum encoding) { if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { // application/xml+fhir return encoding.getResourceContentType(); } else { // application/fhir+xml return encoding.getResourceContentTypeNonLegacy(); } }
@Override public Response returnResponse(ParseAction<?> outcome, int operationStatus, boolean allowPrefer, MethodOutcome response, String resourceName) throws IOException { StringWriter writer = new StringWriter(); if (outcome != null) { FhirContext fhirContext = getRequestDetails().getServer().getFhirContext(); IParser parser = RestfulServerUtils.getNewParser(fhirContext, fhirContext.getVersion().getVersion(), getRequestDetails()); outcome.execute(parser, writer); } return sendWriterResponse(operationStatus, getParserType(), null, writer); }
@Override protected void validateResourceIdAndUrlIdForNonConditionalOperation(IBaseResource theResource, String theResourceId, String theUrlId, String theMatchUrl) { if (isNotBlank(theUrlId)) { String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "idInUrlForCreate", theUrlId); throw new InvalidRequestException(msg); } if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) { if (isNotBlank(theResourceId)) { String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "idInBodyForCreate", theResourceId); throw new InvalidRequestException(msg); } } else { theResource.setId((IIdType)null); } }