org.hl7.fhir.r4.model.Parameters Java Examples

The following examples show how to use org.hl7.fhir.r4.model.Parameters. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private ValueSet importValueSet(String value, List<ValueSetExpansionParameterComponent> params, Parameters expParams) throws ETooCostly, TerminologyServiceException, FileNotFoundException, IOException, FHIRFormatError {
  if (value == null)
    throw new TerminologyServiceException("unable to find value set with no identity");
  ValueSet vs = context.fetchResource(ValueSet.class, value);
  if (vs == null)
    throw new TerminologyServiceException("Unable to find imported value set " + value);
  ValueSetExpansionOutcome vso = new ValueSetExpanderSimple(context).expand(vs, expParams);
  if (vso.getError() != null)
    throw new TerminologyServiceException("Unable to expand imported value set: " + vso.getError());
  if (vs.hasVersion())
    if (!existsInParams(params, "version", new UriType(vs.getUrl() + "|" + vs.getVersion())))
      params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
  for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
    if (!existsInParams(params, p.getName(), p.getValue()))
      params.add(p);
  }
  canBeHeirarchy = false; // if we're importing a value set, we have to be combining, so we won't try for a heirarchy
  return vso.getValueset();
}
 
Example #2
Source File: FHIRToolingClient.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public ValueSet expandValueset(ValueSet source, Parameters expParams) {
  List<Header> headers = null;
  Parameters p = expParams == null ? new Parameters() : expParams.copy();
  p.addParameter().setName("valueSet").setResource(source);
  ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand"), 
      utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers);
  result.addErrorStatus(410);//gone
  result.addErrorStatus(404);//unknown
  result.addErrorStatus(405);
  result.addErrorStatus(422);//Unprocessable Entity
  result.addSuccessStatus(200);
  result.addSuccessStatus(201);
  if(result.isUnsuccessfulRequest()) {
    throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload());
  }
  return (ValueSet) result.getPayload();
}
 
Example #3
Source File: FHIRToolingClient.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public ValueSet expandValueset(ValueSet source, Parameters expParams, Map<String, String> params) {
  List<Header> headers = null;
  Parameters p = expParams == null ? new Parameters() : expParams.copy();
  p.addParameter().setName("valueSet").setResource(source);
  for (String n : params.keySet())
    p.addParameter().setName(n).setValue(new StringType(params.get(n)));
  ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand", params), 
      utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers);
  result.addErrorStatus(410);//gone
  result.addErrorStatus(404);//unknown
  result.addErrorStatus(405);
  result.addErrorStatus(422);//Unprocessable Entity
  result.addSuccessStatus(200);
  result.addSuccessStatus(201);
  if(result.isUnsuccessfulRequest()) {
    throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload());
  }
  return (ValueSet) result.getPayload();
}
 
Example #4
Source File: FHIRToolingClient.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public ConceptMap initializeClosure(String name) {
  Parameters params = new Parameters();
  params.addParameter().setName("name").setValue(new StringType(name));
  List<Header> headers = null;
  ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()),
      utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers);
  result.addErrorStatus(410);//gone
  result.addErrorStatus(404);//unknown
  result.addErrorStatus(405);
  result.addErrorStatus(422);//Unprocessable Entity
  result.addSuccessStatus(200);
  result.addSuccessStatus(201);
  if(result.isUnsuccessfulRequest()) {
    throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload());
  }
  return (ConceptMap) result.getPayload();
}
 
Example #5
Source File: FHIRToolingClient.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public ConceptMap updateClosure(String name, Coding coding) {
  Parameters params = new Parameters();
  params.addParameter().setName("name").setValue(new StringType(name));
  params.addParameter().setName("concept").setValue(coding);
  List<Header> headers = null;
  ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()),
      utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers);
  result.addErrorStatus(410);//gone
  result.addErrorStatus(404);//unknown
  result.addErrorStatus(405);
  result.addErrorStatus(422);//Unprocessable Entity
  result.addSuccessStatus(200);
  result.addSuccessStatus(201);
  if(result.isUnsuccessfulRequest()) {
    throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload());
  }
  return (ConceptMap) result.getPayload();
}
 
Example #6
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void doServerIncludeCodes(ConceptSetComponent inc, boolean heirarchical, List<ValueSetExpansionParameterComponent> params, List<ValueSet> imports, Parameters expParams) throws FHIRException {
  ValueSetExpansionOutcome vso = context.expandVS(inc, heirarchical);
  if (vso.getError() != null)
    throw new TerminologyServiceException("Unable to expand imported value set: " + vso.getError());
  ValueSet vs = vso.getValueset();
  if (vs.hasVersion())
    if (!existsInParams(params, "version", new UriType(vs.getUrl() + "|" + vs.getVersion())))
      params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "|" + vs.getVersion())));
  for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
    if (!existsInParams(params, p.getName(), p.getValue()))
      params.add(p);
  }
  for (ValueSetExpansionContainsComponent cc : vs.getExpansion().getContains()) {
    addCodeAndDescendents(cc, null, expParams, imports);
  }
}
 
Example #7
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params, Parameters expParams, boolean heirarchical) throws ETooCostly, FileNotFoundException, IOException, FHIRException {
  inc.checkNoModifiers("Compose.include", "expanding");
  List<ValueSet> imports = new ArrayList<ValueSet>();
  for (UriType imp : inc.getValueSet()) {
    imports.add(importValueSet(imp.getValue(), params, expParams));
  }

  if (!inc.hasSystem()) {
    if (imports.isEmpty()) // though this is not supposed to be the case
      return;
    ValueSet base = imports.get(0);
    imports.remove(0);
    base.checkNoModifiers("Imported ValueSet", "expanding");
    copyImportContains(base.getExpansion().getContains(), null, expParams, imports);
  } else {
    CodeSystem cs = context.fetchCodeSystem(inc.getSystem());
    if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE)) {
      doServerIncludeCodes(inc, heirarchical, params, imports, expParams);
    } else {
      doInternalIncludeCodes(inc, params, expParams, imports, cs);
    }
  }
}
 
Example #8
Source File: MultitenantServerR4IT.java    From hapi-fhir-jpaserver-starter with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateAndReadInTenantA() {
  ourLog.info("Base URL is: " + HapiProperties.getServerAddress());

  // Create tenant A
  ourClientTenantInterceptor.setTenantId("DEFAULT");
  ourClient
    .operation()
    .onServer()
    .named(ProviderConstants.PARTITION_MANAGEMENT_CREATE_PARTITION)
    .withParameter(Parameters.class, ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID, new IntegerType(1))
    .andParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME, new CodeType("TENANT-A"))
    .execute();


  ourClientTenantInterceptor.setTenantId("TENANT-A");
  Patient pt = new Patient();
  pt.addName().setFamily("Family A");
  ourClient.create().resource(pt).execute().getId();

  Bundle searchResult = ourClient.search().forResource(Patient.class).returnBundle(Bundle.class).cacheControl(new CacheControlDirective().setNoCache(true)).execute();
  assertEquals(1, searchResult.getEntry().size());
  Patient pt2 = (Patient) searchResult.getEntry().get(0).getResource();
  assertEquals("Family A", pt2.getName().get(0).getFamily());
}
 
Example #9
Source File: MultitenantServerR4IT.java    From hapi-fhir-jpaserver-starter with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateAndReadInTenantB() {
  ourLog.info("Base URL is: " + HapiProperties.getServerAddress());

  // Create tenant A
  ourClientTenantInterceptor.setTenantId("DEFAULT");
  ourClient
    .operation()
    .onServer()
    .named(ProviderConstants.PARTITION_MANAGEMENT_CREATE_PARTITION)
    .withParameter(Parameters.class, ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID, new IntegerType(2))
    .andParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME, new CodeType("TENANT-B"))
    .execute();


  ourClientTenantInterceptor.setTenantId("TENANT-B");
  Patient pt = new Patient();
  pt.addName().setFamily("Family B");
  ourClient.create().resource(pt).execute().getId();

  Bundle searchResult = ourClient.search().forResource(Patient.class).returnBundle(Bundle.class).cacheControl(new CacheControlDirective().setNoCache(true)).execute();
  assertEquals(1, searchResult.getEntry().size());
  Patient pt2 = (Patient) searchResult.getEntry().get(0).getResource();
  assertEquals("Family B", pt2.getName().get(0).getFamily());
}
 
Example #10
Source File: LibraryOperationsProvider.java    From cqf-ruler with Apache License 2.0 6 votes vote down vote up
@Operation(name = "$get-elm", idempotent = true, type = Library.class)
public Parameters getElm(@IdParam IdType theId, @OptionalParam(name="format") String format) {
    Library theResource = this.libraryResourceProvider.getDao().read(theId);
    // this.formatCql(theResource);

    ModelManager modelManager = this.getModelManager();
    LibraryManager libraryManager = this.getLibraryManager(modelManager);

    String elm = "";
    CqlTranslator translator = this.dataRequirementsProvider.getTranslator(theResource, libraryManager, modelManager);
    if (translator != null) {
        if (format.equals("json")) {
            elm = translator.toJson();
        }
        else {
            elm = translator.toXml();
        }
    }
    Parameters p = new Parameters();
    p.addParameter().setValue(new StringType(elm));
    return p;
}
 
Example #11
Source File: MeasureOperationsProvider.java    From cqf-ruler with Apache License 2.0 6 votes vote down vote up
private void addEvaluatedResourcesToParameters(Bundle contained, Parameters parameters) {
    Map<String, Resource> resourceMap = new HashMap<>();
    if (contained.hasEntry()) {
        for (Bundle.BundleEntryComponent entry : contained.getEntry()) {
            if (entry.hasResource() && !(entry.getResource() instanceof ListResource)) {
                if (!resourceMap.containsKey(entry.getResource().getIdElement().getValue())) {
                    parameters.addParameter(new Parameters.ParametersParameterComponent().setName("resource")
                            .setResource(entry.getResource()));

                    resourceMap.put(entry.getResource().getIdElement().getValue(), entry.getResource());

                    resolveReferences(entry.getResource(), parameters, resourceMap);
                }
            }
        }
    }
}
 
Example #12
Source File: MeasureOperationsProvider.java    From cqf-ruler with Apache License 2.0 6 votes vote down vote up
private void resolveReferences(Resource resource, Parameters parameters, Map<String, Resource> resourceMap) {
    List<IBase> values;
    for (BaseRuntimeChildDefinition child : this.measureResourceProvider.getContext().getResourceDefinition(resource).getChildren()) {
        values = child.getAccessor().getValues(resource);
        if (values == null || values.isEmpty()) {
            continue;
        }

        else if (values.get(0) instanceof Reference
                && ((Reference) values.get(0)).getReferenceElement().hasResourceType()
                && ((Reference) values.get(0)).getReferenceElement().hasIdPart()) {
            Resource fetchedResource = (Resource) registry
                    .getResourceDao(((Reference) values.get(0)).getReferenceElement().getResourceType())
                    .read(new IdType(((Reference) values.get(0)).getReferenceElement().getIdPart()));

            if (!resourceMap.containsKey(fetchedResource.getIdElement().getValue())) {
                parameters.addParameter(new Parameters.ParametersParameterComponent().setName("resource")
                        .setResource(fetchedResource));

                resourceMap.put(fetchedResource.getIdElement().getValue(), fetchedResource);
            }
        }
    }
}
 
Example #13
Source File: ValueSetExpansionCache.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
@Override
public ValueSetExpansionOutcome expand(ValueSet source, Parameters expParams) throws ETooCostly, IOException {
  String cacheKey = makeCacheKey(source, expParams);
	if (expansions.containsKey(cacheKey))
		return expansions.get(cacheKey);
	ValueSetExpander vse = new ValueSetExpanderSimple(context);
	ValueSetExpansionOutcome vso = vse.expand(source, expParams);
	if (vso.getError() != null) {
	  // well, we'll see if the designated server can expand it, and if it can, we'll cache it locally
		vso = context.expandVS(source, false, expParams == null || !expParams.getParameterBool("excludeNested"));
		if (cacheFolder != null) {
		  FileOutputStream s = new FileOutputStream(Utilities.path(cacheFolder, makeFileName(source.getUrl())));
		  context.newXmlParser().setOutputStyle(OutputStyle.PRETTY).compose(s, vso.getValueset());
		  s.close();
		}
	}
	if (vso.getValueset() != null)
	  expansions.put(cacheKey, vso);
	return vso;
}
 
Example #14
Source File: ValueSetExpansionCache.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private String makeCacheKey(ValueSet source, Parameters expParams) throws IOException {
  if (expParams == null)
    return source.getUrl();
  JsonParser p = new JsonParser();
  String r = p.composeString(expParams);
  return source.getUrl() + " " + r.hashCode(); 
}
 
Example #15
Source File: LibraryOperationsProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
@Operation(name = "$get-narrative", idempotent = true, type = Library.class)
public Parameters getNarrative(@IdParam IdType theId) {
    Library theResource = this.libraryResourceProvider.getDao().read(theId);
    Narrative n = this.narrativeProvider.getNarrative(this.libraryResourceProvider.getContext(), theResource);
    Parameters p = new Parameters();
    p.addParameter().setValue(new StringType(n.getDivAsString()));
    return p;
}
 
Example #16
Source File: MeasureOperationsProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
@Operation(name = "$get-narrative", idempotent = true, type = Measure.class)
public Parameters getNarrative(@IdParam IdType theId) {
    Measure theResource = this.measureResourceProvider.getDao().read(theId);
    CqfMeasure cqfMeasure = this.dataRequirementsProvider.createCqfMeasure(theResource, this.libraryResolutionProvider);
    Narrative n = this.narrativeProvider.getNarrative(this.measureResourceProvider.getContext(), cqfMeasure);
    Parameters p = new Parameters();
    p.addParameter().setValue(new StringType(n.getDivAsString()));
    return p;
}
 
Example #17
Source File: TestingUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static IWorkerContext context() {
  if (fcontext == null) {
    FilesystemPackageCacheManager pcm;
    try {
      pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
      fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.0"));
      fcontext.setUcumService(new UcumEssenceService(TestingUtilities.resourceNameToFile("ucum", "ucum-essence.xml")));
      fcontext.setExpansionProfile(new Parameters());
    } catch (Exception e) {
      throw new Error(e);
    }

  }
  return fcontext;
}
 
Example #18
Source File: MeasureOperationsProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
@Operation(name = "$collect-data", idempotent = true, type = Measure.class)
public Parameters collectData(@IdParam IdType theId, @RequiredParam(name = "periodStart") String periodStart,
        @RequiredParam(name = "periodEnd") String periodEnd, @OptionalParam(name = "patient") String patientRef,
        @OptionalParam(name = "practitioner") String practitionerRef,
        @OptionalParam(name = "lastReceivedOn") String lastReceivedOn) throws FHIRException {
    // TODO: Spec says that the periods are not required, but I am not sure what to
    // do when they aren't supplied so I made them required
    MeasureReport report = evaluateMeasure(theId, periodStart, periodEnd, null, null, patientRef, null,
            practitionerRef, lastReceivedOn, null, null, null);
    report.setGroup(null);

    Parameters parameters = new Parameters();

    parameters.addParameter(
            new Parameters.ParametersParameterComponent().setName("measurereport").setResource(report));

    if (report.hasContained()) {
        for (Resource contained : report.getContained()) {
            if (contained instanceof Bundle) {
                addEvaluatedResourcesToParameters((Bundle) contained, parameters);
            }
        }
    }

    // TODO: need a way to resolve referenced resources within the evaluated
    // resources
    // Should be able to use _include search with * wildcard, but HAPI doesn't
    // support that

    return parameters;
}
 
Example #19
Source File: FHIRToolingClient.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public Parameters lookupCode(Map<String, String> params) {
  ResourceRequest<Resource> result = utils.issueGetResourceRequest(resourceAddress.resolveOperationUri(CodeSystem.class, "lookup", params), getPreferredResourceFormat());
  result.addErrorStatus(410);//gone
  result.addErrorStatus(404);//unknown
  result.addErrorStatus(405);
  result.addErrorStatus(422);//Unprocessable Entity
  result.addSuccessStatus(200);
  result.addSuccessStatus(201);
  if(result.isUnsuccessfulRequest()) {
    throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload());
  }
  return (Parameters) result.getPayload();
}
 
Example #20
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void copyImportContains(List<ValueSetExpansionContainsComponent> list, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filter) throws FHIRException {
  for (ValueSetExpansionContainsComponent c : list) {
    c.checkNoModifiers("Imported Expansion in Code System", "expanding");
    ValueSetExpansionContainsComponent np = addCode(c.getSystem(), c.getCode(), c.getDisplay(), parent, null, expParams, c.getAbstract(), c.getInactive(), filter);
    copyImportContains(c.getContains(), np, expParams, filter);
  }
}
 
Example #21
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void addCodes(ValueSetExpansionComponent expand, List<ValueSetExpansionParameterComponent> params, Parameters expParams, List<ValueSet> filters) throws ETooCostly, FHIRException {
  if (expand != null) {
    if (expand.getContains().size() > maxExpansionSize)
      throw new ETooCostly("Too many codes to display (>" + Integer.toString(expand.getContains().size()) + ")");
    for (ValueSetExpansionParameterComponent p : expand.getParameter()) {
      if (!existsInParams(params, p.getName(), p.getValue()))
        params.add(p);
    }

    copyImportContains(expand.getContains(), null, expParams, filters);
  }
}
 
Example #22
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void addCodeAndDescendents(ValueSetExpansionContainsComponent focus, ValueSetExpansionContainsComponent parent, Parameters expParams, List<ValueSet> filters)  throws FHIRException {
  focus.checkNoModifiers("Expansion.contains", "expanding");
  ValueSetExpansionContainsComponent np = addCode(focus.getSystem(), focus.getCode(), focus.getDisplay(), parent, 
       convert(focus.getDesignation()), expParams, focus.getAbstract(), focus.getInactive(), filters);
  for (ValueSetExpansionContainsComponent c : focus.getContains())
    addCodeAndDescendents(focus, np, expParams, filters);
}
 
Example #23
Source File: ValueSetExpanderSimple.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private Parameters makeDefaultExpansion() {
  Parameters res = new Parameters();
  res.addParameter("excludeNested", true);
  res.addParameter("includeDesignations", false);
  return res;
}
 
Example #24
Source File: TerminologyClientR4.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
@Override
public Parameters lookupCode(Map<String, String> params) {
  return client.lookupCode(params);
}
 
Example #25
Source File: TerminologyClientR4.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
@Override
public Parameters validateVS(Parameters pin) {
  return client.operateType(ValueSet.class, "validate-code", pin);
}
 
Example #26
Source File: TerminologyClientR4.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
@Override
public Parameters validateCS(Parameters pin) {
  return client.operateType(CodeSystem.class, "validate-code", pin);
}
 
Example #27
Source File: TerminologyClientR4.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
@Override
public ValueSet expandValueset(ValueSet vs, Parameters p, Map<String, String> params) {
  return client.expandValueset(vs, p, params);
}
 
Example #28
Source File: ValueSetExpander.java    From org.hl7.fhir.core with Apache License 2.0 2 votes vote down vote up
/**
* 
* @param source the value set definition to expand
* @param profile a profile affecting the outcome. If you don't supply a profile, the default internal expansion profile will be used.
*  
* @return
* @throws ETooCostly
* @throws FileNotFoundException
* @throws IOException
*/
 public ValueSetExpansionOutcome expand(ValueSet source, Parameters parameters) throws ETooCostly, FileNotFoundException, IOException;
 
Example #29
Source File: TerminologyClient.java    From org.hl7.fhir.core with Apache License 2.0 votes vote down vote up
public Parameters lookupCode(Map<String, String> params) throws FHIRException; 
Example #30
Source File: TerminologyClient.java    From org.hl7.fhir.core with Apache License 2.0 votes vote down vote up
public Parameters validateVS(Parameters pin) throws FHIRException;