Search in sources :

Example 81 with Parameters

use of org.hl7.fhir.r5.model.Parameters in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method describeValidationParameters.

@SuppressWarnings("rawtypes")
private String describeValidationParameters(Parameters pin) {
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    for (ParametersParameterComponent p : pin.getParameter()) {
        if (p.hasValue() && p.getValue() instanceof PrimitiveType) {
            b.append(p.getName() + "=" + ((PrimitiveType) p.getValue()).asStringValue());
        } else if (p.hasValue() && p.getValue() instanceof Coding) {
            b.append("system=" + ((Coding) p.getValue()).getSystem());
            b.append("code=" + ((Coding) p.getValue()).getCode());
            b.append("display=" + ((Coding) p.getValue()).getDisplay());
        } else if (p.hasValue() && p.getValue() instanceof CodeableConcept) {
            if (((CodeableConcept) p.getValue()).hasCoding()) {
                Coding c = ((CodeableConcept) p.getValue()).getCodingFirstRep();
                b.append("system=" + c.getSystem());
                b.append("code=" + c.getCode());
                b.append("display=" + c.getDisplay());
            } else if (((CodeableConcept) p.getValue()).hasText()) {
                b.append("text=" + ((CodeableConcept) p.getValue()).getText());
            }
        } else if (p.hasResource() && (p.getResource() instanceof ValueSet)) {
            b.append("valueset=" + getVSSummary((ValueSet) p.getResource()));
        }
    }
    return b.toString();
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) PrimitiveType(org.hl7.fhir.dstu3.model.PrimitiveType) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 82 with Parameters

use of org.hl7.fhir.r5.model.Parameters in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method verifyCodeExternal.

private ValidationResult verifyCodeExternal(ValueSet vs, Coding coding, boolean tryCache) throws Exception {
    ValidationResult res = vs == null ? null : handleByCache(vs, coding, tryCache);
    if (res != null) {
        return res;
    }
    Parameters pin = new Parameters();
    pin.addParameter().setName("coding").setValue(coding);
    if (vs != null) {
        pin.addParameter().setName("valueSet").setResource(vs);
    }
    res = serverValidateCode(pin, vs == null);
    if (vs != null) {
        Map<String, ValidationResult> cache = validationCache.get(vs.getUrl());
        cache.put(cacheId(coding), res);
    }
    return res;
}
Also used : Parameters(org.hl7.fhir.dstu3.model.Parameters)

Example 83 with Parameters

use of org.hl7.fhir.r5.model.Parameters in project org.hl7.fhir.core by hapifhir.

the class JavaResourceGenerator method generate.

// public void generate(ElementDefinition root, String name, JavaGenClass clss, ProfiledType cd, Date genDate, String version, boolean isAbstract, Map<String, SearchParameterDefn> nameToSearchParamDef, ElementDefinition template) throws Exception {
public void generate(Analysis analysis) throws Exception {
    if (analysis.getStructure().getKind() == StructureDefinitionKind.RESOURCE) {
        clss = JavaGenClass.Resource;
    } else {
        clss = JavaGenClass.Type;
    }
    write("package org.hl7.fhir." + jid + ".model;\r\n");
    startMark(version, genDate);
    // hasList(root);
    boolean hl = true;
    boolean hh = hasXhtml(analysis.getStructure().getSnapshot().getElement());
    boolean hd = hasDecimal(analysis.getStructure().getSnapshot().getElement());
    boolean hs = hasString(analysis.getStructure().getSnapshot().getElement());
    boolean he = hasSharedEnums(analysis.getStructure().getSnapshot().getElement());
    boolean hn = hasNestedTypes(analysis.getStructure().getSnapshot().getElement());
    if (hl || hh || hd || he) {
        if (hl) {
            write("import java.util.ArrayList;\r\n");
            write("import java.util.Date;\r\n");
            write("import java.util.List;\r\n");
        } else {
            write("import java.util.Date;\r\n");
        }
        if (hh) {
            write("import org.hl7.fhir.utilities.xhtml.NodeType;\r\n");
            write("import org.hl7.fhir.utilities.xhtml.XhtmlNode;\r\n");
        }
        if (hd)
            write("import java.math.*;\r\n");
        if (hs)
            write("import org.hl7.fhir.utilities.Utilities;\r\n");
        if (he)
            write("import org.hl7.fhir." + jid + ".model.Enumerations.*;\r\n");
    }
    if (hn) {
        if (clss == JavaGenClass.Resource) {
            write("import org.hl7.fhir.instance.model.api.IBaseBackboneElement;\r\n");
        } else {
            write("import org.hl7.fhir.instance.model.api.IBaseDatatypeElement;\r\n");
        }
    }
    write("import org.hl7.fhir.exceptions.FHIRException;\r\n");
    write("import org.hl7.fhir.instance.model.api.ICompositeType;\r\n");
    if (clss == JavaGenClass.Resource) {
        write("import ca.uhn.fhir.model.api.annotation.ResourceDef;\r\n");
        write("import ca.uhn.fhir.model.api.annotation.SearchParamDefinition;\r\n");
    }
    if (clss == JavaGenClass.Resource || "BackboneElement".equals(analysis.getName()) || "BackboneType".equals(analysis.getName())) {
        write("import org.hl7.fhir.instance.model.api.IBaseBackboneElement;\r\n");
    }
    write("import ca.uhn.fhir.model.api.annotation.Child;\r\n");
    write("import ca.uhn.fhir.model.api.annotation.ChildOrder;\r\n");
    if (clss != JavaGenClass.Resource) {
        write("import ca.uhn.fhir.model.api.annotation.DatatypeDef;\r\n");
    }
    write("import ca.uhn.fhir.model.api.annotation.Description;\r\n");
    write("import ca.uhn.fhir.model.api.annotation.Block;\r\n");
    write("\r\n");
    if (config.getIni().hasProperty("imports", analysis.getName())) {
        for (String imp : config.getIni().getStringProperty("imports", analysis.getName()).split("\\,")) {
            write("import " + imp.replace("{{jid}}", jid) + ";\r\n");
        }
    }
    jdoc("", replaceTitle(analysis.getName(), analysis.getStructure().getDescription()));
    TypeInfo ti = analysis.getRootType();
    boolean hasChildren = ti.getChildren().size() > 0;
    String superName = analysis.getAncestor() == null ? null : analysis.getAncestor().getName();
    if (VersionUtilities.isR4BVer(version) && !Utilities.noString(config.getIni().getStringProperty("R4B.CanonicalResources", analysis.getName()))) {
        superName = "CanonicalResource";
    }
    String hierarchy = analysis.getAncestor() != null ? "extends " + superName : "";
    if (clss == JavaGenClass.Resource) {
        if (!analysis.isAbstract()) {
            write("@ResourceDef(name=\"" + upFirst(analysis.getName()).replace("ListResource", "List") + "\", profile=\"http://hl7.org/fhir/StructureDefinition/" + upFirst(analysis.getName()) + "\")\r\n");
        }
    } else {
        write("@DatatypeDef(name=\"" + upFirst(analysis.getName()) + "\")\r\n");
        hierarchy = hierarchy + " implements ICompositeType";
    }
    if (config.getIni().hasProperty("hierarchy", analysis.getName())) {
        String h = config.getIni().getStringProperty("hierarchy", analysis.getName());
        if (analysis.getAncestor() != null) {
            h = h.replace("{{super}}", superName);
        }
        hierarchy = h;
    }
    write("public " + (analysis.isAbstract() ? "abstract " : "") + "class " + analysis.getClassName() + " " + hierarchy.trim() + " {\r\n");
    write("\r\n");
    for (String s : sorted(analysis.getEnums().keySet())) {
        EnumInfo e = analysis.getEnums().get(s);
        generateEnum(e);
    }
    for (TypeInfo t : analysis.getTypeList()) {
        generateType(analysis, t);
    }
    allfields = "";
    int i = 0;
    for (ElementDefinition e : ti.getChildren()) {
        if (!analysis.isInterface()) {
            generateField(analysis, ti, e, "    ", i++);
        }
    }
    write("    private static final long serialVersionUID = " + Long.toString(allfields.hashCode()) + "L;\r\n\r\n");
    hashSum = hashSum + allfields.hashCode();
    List<ElementDefinition> mandatory = new ArrayList<ElementDefinition>();
    generateConstructor(analysis.getClassName(), mandatory, "  ");
    if (hasChildren) {
        for (ElementDefinition e : ti.getChildren()) {
            if (e.getMin() > 0)
                mandatory.add(e);
        }
        if (mandatory.size() > 0)
            generateConstructor(analysis.getClassName(), mandatory, "  ");
        generateTypeSpecificConstructors(analysis.getClassName());
        for (ElementDefinition e : ti.getChildren()) {
            if (analysis.isInterface()) {
                generateAbstractAccessors(analysis, ti, e, "    ");
            } else {
                generateAccessors(analysis, ti, e, "    ", matchingInheritedElement(ti.getInheritedChildren(), e, analysis.getName()));
            }
        }
        if (!analysis.isInterface() && ti.getInheritedChildren() != null) {
            for (ElementDefinition e : filterInherited(ti.getInheritedChildren(), ti.getChildren())) {
                generateUnimplementedAccessors(analysis, ti, e, "    ");
            }
        }
        generateChildrenRegister(analysis, ti, "    ");
        generatePropertyGetterId(analysis, ti, "    ");
        generatePropertySetterId(analysis, ti, "    ");
        generatePropertySetterName(analysis, ti, "    ");
        generatePropertyMaker(analysis, ti, "    ");
        generatePropertyTypeGetter(analysis, ti, "    ");
        generateChildAdder(analysis, ti, "    ");
    }
    generateFhirType(analysis.getName());
    // // check for mappings
    // for (String map : root.getMappings().keySet()) {
    // if ("http://hl7.org/fhir/workflow".equals(map)) {
    // String namenn = root.getMapping(map);
    // if (patterns.containsKey(namenn)) {
    // generateImpl(namenn, patterns.get(namenn), upFirst(name), root, version, genDate);
    // }
    // }
    // }
    generateCopy(analysis, ti, false);
    if (hasChildren) {
        generateEquals(analysis, ti, false);
        generateIsEmpty(analysis, ti, false);
    }
    if (clss == JavaGenClass.Resource && !analysis.isAbstract()) {
        write("  @Override\r\n");
        write("  public ResourceType getResourceType() {\r\n");
        write("    return ResourceType." + analysis.getName() + ";\r\n");
        write("   }\r\n");
        write("\r\n");
    } else if (analysis.isAbstract() && analysis.getAncestor() != null && Utilities.noString(superName)) {
        write("\r\n");
        write("  @Override\r\n");
        write("  public String getIdBase() {\r\n");
        write("    return getId();\r\n");
        write("  }\r\n");
        write("  \r\n");
        write("  @Override\r\n");
        write("  public void setIdBase(String value) {\r\n");
        write("    setId(value);\r\n");
        write("  }\r\n");
        write("  public abstract ResourceType getResourceType();\r\n");
    } else if (analysis.isAbstract() && analysis.getAncestor() != null && Utilities.noString(superName)) {
        write("  @Override\r\n");
        write("  public String getIdBase() {\r\n");
        write("    return getId();\r\n");
        write("  }\r\n");
        write("  \r\n");
        write("  @Override\r\n");
        write("  public void setIdBase(String value) {\r\n");
        write("    setId(value);\r\n");
        write("  }\r\n");
    }
    // Write resource fields which can be used as constants in client code
    // to refer to standard search params
    Set<String> spcodes = new HashSet<>();
    for (SearchParameter sp : analysis.getSearchParams()) {
        String code = sp.getCode();
        if (!spcodes.contains(code)) {
            spcodes.add(code);
            /* 
		     * For composite codes we want to find the two param this is a composite
		     * of. We generate search parameter constants which reference the 
		     * component parts of the composite.  
		     */
            if (sp.getType() == SearchParamType.COMPOSITE) {
                if (code.endsWith("-[x]")) {
                    // partialCode will have "value" in this example
                    String partialCode = code.substring(0, code.length() - 4);
                    partialCode = partialCode.substring(partialCode.lastIndexOf('-') + 1);
                    // rootCode will have "component-code"
                    String rootCode = code.substring(0, code.indexOf("-" + partialCode));
                    /*
		         * If the composite has the form "foo-bar[x]" we expand this to create 
		         * a constant for each of the possible [x] values, so that client have
		         * static binding to the individual possibilities. AFAIK this is only
		         * used right now in Observation (e.g. for code-value-[x]) 
		         */
                    for (SearchParameter nextCandidate : analysis.getSearchParams()) {
                        if (nextCandidate.getCode().startsWith(partialCode)) {
                            String nextCompositeCode = rootCode + "-" + nextCandidate.getCode();
                            String[] compositeOf = new String[] { rootCode, nextCandidate.getCode() };
                            writeSearchParameterField(analysis.getName(), clss, analysis.isAbstract(), sp, nextCompositeCode, compositeOf, analysis.getSearchParams(), analysis.getName());
                        }
                    }
                } else {
                    SearchParameter comp0 = definitions.getSearchParams().get(sp.getComponent().get(0).getDefinition());
                    SearchParameter comp1 = definitions.getSearchParams().get(sp.getComponent().get(1).getDefinition());
                    if (comp0 != null && comp1 != null) {
                        String[] compositeOf = new String[] { comp0.getCode(), comp1.getCode() };
                        writeSearchParameterField(analysis.getName(), clss, analysis.isAbstract(), sp, sp.getCode(), compositeOf, analysis.getSearchParams(), analysis.getName());
                    }
                }
            } else if (code.contains("[x]")) {
                /*
		       * We only know how to handle search parameters with [x] in the name
		       * where it's a composite, and the [x] comes last. Are there other possibilities?
		       */
                throw new Exception("Unable to generate constant for search parameter: " + code);
            } else {
                writeSearchParameterField(analysis.getName(), clss, analysis.isAbstract(), sp, code, null, analysis.getSearchParams(), analysis.getName());
            }
        }
    }
    if (VersionUtilities.isR4BVer(version)) {
        String extras = config.getIni().getStringProperty("R4B.NullImplementation", analysis.getName());
        if (!Utilities.noString(extras)) {
            for (String n : extras.split("\\,")) {
                String t = n.substring(n.indexOf(":") + 1);
                n = n.substring(0, n.indexOf(":"));
                if (n.endsWith("[]")) {
                    n = Utilities.capitalize(n.substring(0, n.length() - 2));
                    write("      @Override\r\n");
                    write("      public List<" + t + "> get" + n + "() {\r\n");
                    write("        return new ArrayList<>();\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public CanonicalResource set" + n + "(List<" + t + "> the" + n + ") {\r\n");
                    write("        return this;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public boolean has" + n + "() {\r\n");
                    write("        return false;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public " + t + " add" + n + "() {\r\n");
                    write("	        return null;\r\n");
                    write("	      }\r\n");
                    write("	      \r\n");
                    write("      @Override\r\n");
                    write("      public CanonicalResource add" + n + "(" + t + " t) {\r\n");
                    write("        return null;\r\n");
                    write("	      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public " + t + " get" + n + "FirstRep() {\r\n");
                    write("        return new " + t + "();\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                } else if (t.contains("|")) {
                    n = Utilities.capitalize(n);
                    String t1 = t.substring(0, t.indexOf("|"));
                    String t2 = t.substring(t.indexOf("|") + 1);
                    write("      @Override\r\n");
                    write("      public " + t1 + " get" + n + "() {\r\n");
                    if ("boolean".equals(t1)) {
                        write("        return false;\r\n");
                    } else {
                        write("        return new " + t1 + "();\r\n");
                    }
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public " + t2 + " get" + n + "Element() {\r\n");
                    write("        return new " + t2 + "();\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public CanonicalResource set" + n + "(" + t1 + " the" + n + ") {\r\n");
                    write("        return this;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public CanonicalResource set" + n + "Element(" + t2 + " the" + n + ") {\r\n");
                    write("        return this;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public boolean has" + n + "() {\r\n");
                    write("        return false;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public boolean has" + n + "Element() {\r\n");
                    write("        return false;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      \r\n");
                } else {
                    n = Utilities.capitalize(n);
                    write("      @Override\r\n");
                    write("      public " + t + " get" + n + "() {\r\n");
                    write("        return new " + t + "();\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public CanonicalResource set" + n + "(" + t + " the" + n + ") {\r\n");
                    write("        return this;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public boolean has" + n + "() {\r\n");
                    write("        return false;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      @Override\r\n");
                    write("      public boolean has" + n + "Element() {\r\n");
                    write("        return false;\r\n");
                    write("      }\r\n");
                    write("      \r\n");
                    write("      \r\n");
                }
            }
        }
    }
    if (config.getAdornments().containsKey(analysis.getClassName())) {
        write("// Manual code (from Configuration.txt):\r\n");
        write(config.getAdornments().get(analysis.getClassName()) + "\r\n");
        write("// end addition\r\n");
    }
    write("\r\n");
    write("}\r\n");
    write("\r\n");
    flush();
}
Also used : EnumInfo(org.hl7.fhir.core.generator.analysis.EnumInfo) ArrayList(java.util.ArrayList) TypeInfo(org.hl7.fhir.core.generator.analysis.TypeInfo) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) HashSet(java.util.HashSet)

Example 84 with Parameters

use of org.hl7.fhir.r5.model.Parameters in project org.hl7.fhir.core by hapifhir.

the class ClientUtils method encodeFormSubmission.

private byte[] encodeFormSubmission(Map<String, String> parameters, String resourceName, Resource resource, String boundary) throws IOException {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    OutputStreamWriter w = new OutputStreamWriter(b, "UTF-8");
    for (String name : parameters.keySet()) {
        w.write("--");
        w.write(boundary);
        w.write("\r\nContent-Disposition: form-data; name=\"" + name + "\"\r\n\r\n");
        w.write(parameters.get(name) + "\r\n");
    }
    w.write("--");
    w.write(boundary);
    w.write("\r\nContent-Disposition: form-data; name=\"" + resourceName + "\"\r\n\r\n");
    w.close();
    JsonParser json = new JsonParser();
    json.setOutputStyle(OutputStyle.NORMAL);
    json.compose(b, resource);
    b.close();
    w = new OutputStreamWriter(b, "UTF-8");
    w.write("\r\n--");
    w.write(boundary);
    w.write("--");
    w.close();
    return b.toByteArray();
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Example 85 with Parameters

use of org.hl7.fhir.r5.model.Parameters in project org.hl7.fhir.core by hapifhir.

the class FHIRToolingClient method operateType.

// 
// public <T extends Resource> boolean delete(Class<T> resourceClass, String id) {
// try {
// return utils.issueDeleteRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), proxy);
// } catch(Exception e) {
// throw new EFhirClientException("An error has occurred while trying to delete this resource", e);
// }
// 
// }
// 
// public <T extends Resource> OperationOutcome create(Class<T> resourceClass, T resource) {
// ResourceRequest<T> resourceRequest = null;
// try {
// List<Header> headers = null;
// resourceRequest = utils.issuePostRequest(resourceAddress.resolveGetUriFromResourceClass(resourceClass),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, proxy);
// resourceRequest.addSuccessStatus(201);
// if(resourceRequest.isUnsuccessfulRequest()) {
// throw new EFhirClientException("Server responded with HTTP error code " + resourceRequest.getHttpStatus(), (OperationOutcome)resourceRequest.getPayload());
// }
// } catch(Exception e) {
// handleException("An error has occurred while trying to create this resource", e);
// }
// OperationOutcome operationOutcome = null;;
// try {
// operationOutcome = (OperationOutcome)resourceRequest.getPayload();
// ResourceAddress.ResourceVersionedIdentifier resVersionedIdentifier =
// ResourceAddress.parseCreateLocation(resourceRequest.getLocation());
// OperationOutcomeIssueComponent issue = operationOutcome.addIssue();
// issue.setSeverity(IssueSeverity.INFORMATION);
// issue.setUserData(ResourceAddress.ResourceVersionedIdentifier.class.toString(),
// resVersionedIdentifier);
// return operationOutcome;
// } catch(ClassCastException e) {
// // some server (e.g. grahams) returns the resource directly
// operationOutcome = new OperationOutcome();
// OperationOutcomeIssueComponent issue = operationOutcome.addIssue();
// issue.setSeverity(IssueSeverity.INFORMATION);
// issue.setUserData(ResourceRequest.class.toString(),
// resourceRequest.getPayload());
// return operationOutcome;
// }
// }
// 
// public <T extends Resource> Bundle history(Calendar lastUpdate, Class<T> resourceClass, String id) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForResourceId(resourceClass, id, lastUpdate, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history information for this resource", e);
// }
// return history;
// }
// 
// public <T extends Resource> Bundle history(Date lastUpdate, Class<T> resourceClass, String id) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForResourceId(resourceClass, id, lastUpdate, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history information for this resource", e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history(Calendar lastUpdate, Class<T> resourceClass) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForResourceType(resourceClass, lastUpdate, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history information for this resource type", e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history(Date lastUpdate, Class<T> resourceClass) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForResourceType(resourceClass, lastUpdate, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history information for this resource type", e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history(Class<T> resourceClass) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForResourceType(resourceClass, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history information for this resource type", e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history(Class<T> resourceClass, String id) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForResourceId(resourceClass, id, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history information for this resource", e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history(Date lastUpdate) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForAllResources(lastUpdate, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history since last update",e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history(Calendar lastUpdate) {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForAllResources(lastUpdate, maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history since last update",e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle history() {
// Bundle history = null;
// try {
// history = utils.issueGetFeedRequest(resourceAddress.resolveGetHistoryForAllResources(maxResultSetSize), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("An error has occurred while trying to retrieve history since last update",e);
// }
// return history;
// }
// 
// 
// public <T extends Resource> Bundle search(Class<T> resourceClass, Map<String, String> parameters) {
// Bundle searchResults = null;
// try {
// searchResults = utils.issueGetFeedRequest(resourceAddress.resolveSearchUri(resourceClass, parameters), getPreferredResourceFormat(), proxy);
// } catch (Exception e) {
// handleException("Error performing search with parameters " + parameters, e);
// }
// return searchResults;
// }
// 
// 
// public <T extends Resource> Bundle searchPost(Class<T> resourceClass, T resource, Map<String, String> parameters) {
// Bundle searchResults = null;
// try {
// searchResults = utils.issuePostFeedRequest(resourceAddress.resolveSearchUri(resourceClass, new HashMap<String, String>()), parameters, "src", resource, getPreferredResourceFormat());
// } catch (Exception e) {
// handleException("Error performing search with parameters " + parameters, e);
// }
// return searchResults;
// }
public <T extends Resource> Parameters operateType(Class<T> resourceClass, String name, Parameters params) {
    boolean complex = false;
    for (ParametersParameterComponent p : params.getParameter()) complex = complex || !(p.getValue() instanceof PrimitiveType);
    Parameters searchResults = null;
    String ps = "";
    try {
        if (!complex)
            for (ParametersParameterComponent p : params.getParameter()) if (p.getValue() instanceof PrimitiveType)
                ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue()) + "&";
        ResourceRequest<T> result;
        if (complex)
            result = utils.issuePostRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), TIMEOUT_OPERATION_LONG);
        else
            result = utils.issueGetResourceRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), getPreferredResourceFormat(), TIMEOUT_OPERATION_LONG);
        // gone
        result.addErrorStatus(410);
        // unknown
        result.addErrorStatus(404);
        // Only one for now
        result.addSuccessStatus(200);
        if (result.isUnsuccessfulRequest())
            throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload());
        if (result.getPayload() instanceof Parameters)
            return (Parameters) result.getPayload();
        else {
            Parameters p_out = new Parameters();
            p_out.addParameter().setName("return").setResource(result.getPayload());
            return p_out;
        }
    } catch (Exception e) {
        handleException("Error performing tx2 operation '" + name + ": " + e.getMessage() + "' (parameters = \"" + ps + "\")", e);
    }
    return null;
}
Also used : Parameters(org.hl7.fhir.dstu2.model.Parameters) OperationOutcome(org.hl7.fhir.dstu2.model.OperationOutcome) PrimitiveType(org.hl7.fhir.dstu2.model.PrimitiveType) URISyntaxException(java.net.URISyntaxException) ParametersParameterComponent(org.hl7.fhir.dstu2.model.Parameters.ParametersParameterComponent)

Aggregations

Parameters (org.hl7.fhir.r4.model.Parameters)105 Test (org.junit.jupiter.api.Test)96 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)71 StringType (org.hl7.fhir.r4.model.StringType)68 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)61 HashMap (java.util.HashMap)58 ArrayList (java.util.ArrayList)53 FHIRException (org.hl7.fhir.exceptions.FHIRException)48 IOException (java.io.IOException)44 Parameters (org.hl7.fhir.dstu3.model.Parameters)41 Bundle (org.hl7.fhir.r4.model.Bundle)34 Measure (org.hl7.fhir.r4.model.Measure)31 Path (javax.ws.rs.Path)25 Produces (javax.ws.rs.Produces)25 Patient (org.hl7.fhir.r4.model.Patient)25 FileNotFoundException (java.io.FileNotFoundException)24 List (java.util.List)24 JsonObject (javax.json.JsonObject)23 GET (javax.ws.rs.GET)23 ExtraParameters (org.apache.camel.component.fhir.api.ExtraParameters)23