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

The following examples show how to use org.hl7.fhir.r4.model.OperationOutcome. 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: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static String getErrorDescription(OperationOutcome error) {  
if (error.hasText() && error.getText().hasDiv())
	return new XhtmlComposer(XhtmlComposer.XML).composePlainText(error.getText().getDiv());

StringBuilder b = new StringBuilder();
for (OperationOutcomeIssueComponent t : error.getIssue())
	if (t.getSeverity() == IssueSeverity.ERROR)
		b.append("Error:" +t.getDetails()+"\r\n");
	else if (t.getSeverity() == IssueSeverity.FATAL)
		b.append("Fatal:" +t.getDetails()+"\r\n");
	else if (t.getSeverity() == IssueSeverity.WARNING)
		b.append("Warning:" +t.getDetails()+"\r\n");
	else if (t.getSeverity() == IssueSeverity.INFORMATION)
		b.append("Information:" +t.getDetails()+"\r\n");
return b.toString();
}
 
Example #2
Source File: OperationOutcomeUtilities.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static OperationOutcomeIssueComponent convertToIssue(ValidationMessage message, OperationOutcome op) {
  OperationOutcomeIssueComponent issue = new OperationOutcome.OperationOutcomeIssueComponent();
  issue.setCode(convert(message.getType()));
  
  if (message.getLocation() != null) {
    // message location has a fhirPath in it. We need to populate the expression
    issue.addExpression(message.getLocation());
  }
  // pass through line/col if they're present
  if (message.getLine() != 0)
    issue.addExtension().setUrl(ToolingExtensions.EXT_ISSUE_LINE).setValue(new IntegerType(message.getLine()));
  if (message.getCol() != 0)
    issue.addExtension().setUrl(ToolingExtensions.EXT_ISSUE_COL).setValue(new IntegerType(message.getCol()));
  issue.setSeverity(convert(message.getLevel()));
  CodeableConcept c = new CodeableConcept();
  c.setText(message.getMessage());
  issue.setDetails(c);
  if (message.getSource() != null) {
    issue.getExtension().add(ToolingExtensions.makeIssueSource(message.getSource()));
  }
  return issue;
}
 
Example #3
Source File: ObservationDefinitionProvider.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam ObservationDefinition observationDefinition)

{
    log.info("create method is called");
    resourcePermissionProvider.checkPermission("create");
    MethodOutcome method = new MethodOutcome();

    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
        ObservationDefinition newObservationDefinition = observationDefinitionDao.create(ctx,observationDefinition, null);
        method.setCreated(true);
        method.setId(newObservationDefinition.getIdElement());
        method.setResource(newObservationDefinition);
    } catch (Exception ex) {
        log.info(ex.getMessage());
        ProviderResponseLibrary.handleException(method,ex);
    }
    return method;
}
 
Example #4
Source File: FHIRToolingClient.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public <T extends Resource> T vread(Class<T> resourceClass, String id, String version) {
	ResourceRequest<T> result = null;
	try {
		result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndIdAndVersion(resourceClass, id, version), getPreferredResourceFormat());
		result.addErrorStatus(410);//gone
		result.addErrorStatus(404);//unknown
		result.addErrorStatus(405);//unknown
		result.addSuccessStatus(200);//Only one for now
		if(result.isUnsuccessfulRequest()) {
			throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload());
		}
	} catch (Exception e) {
		handleException("An error has occurred while trying to read this version of the resource", e);
	}
	return 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 <T extends Resource> T getCanonical(Class<T> resourceClass, String canonicalURL) {
  ResourceRequest<T> result = null;
  try {
    result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndCanonical(resourceClass, canonicalURL), getPreferredResourceFormat());
    result.addErrorStatus(410);//gone
    result.addErrorStatus(404);//unknown
    result.addErrorStatus(405);//unknown
    result.addSuccessStatus(200);//Only one for now
    if(result.isUnsuccessfulRequest()) {
      throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload());
    }
  } catch (Exception e) {
    handleException("An error has occurred while trying to read this version of the resource", e);
  }
  Bundle bnd = (Bundle) result.getPayload();
  if (bnd.getEntry().size() == 0)
    throw new EFhirClientException("No matching resource found for canonical URL '"+canonicalURL+"'");
  if (bnd.getEntry().size() > 1)
    throw new EFhirClientException("Multiple matching resources found for canonical URL '"+canonicalURL+"'");
  return (T) bnd.getEntry().get(0).getResource();
}
 
Example #6
Source File: FHIRToolingClient.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")

public <T extends Resource> OperationOutcome validate(Class<T> resourceClass, T resource, String id) {
	ResourceRequest<T> result = null;
	try {
		result = utils.issuePostRequest(resourceAddress.resolveValidateUri(resourceClass, id), utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat());
		result.addErrorStatus(400);//gone
		result.addErrorStatus(422);//Unprocessable Entity
		result.addSuccessStatus(200);//OK
		if(result.isUnsuccessfulRequest()) {
			throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload());
		}
	} catch(Exception e) {
		handleException("An error has occurred while trying to validate this resource", e);
	}
	return (OperationOutcome)result.getPayload();
}
 
Example #7
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 #8
Source File: CodeSystemUpdateProvider.java    From cqf-ruler with Apache License 2.0 6 votes vote down vote up
/***
 * Update existing CodeSystems with the codes in all ValueSet resources.
 * System level CodeSystem update operation
 *
 * @return FHIR OperationOutcome detailing the success or failure of the operation
 */
@Operation(name = "$updateCodeSystems", idempotent = true)
public OperationOutcome updateCodeSystems()
{
    IBundleProvider valuesets = this.valueSetDao.search(new SearchParameterMap());
    OperationOutcome response = new OperationOutcome();

    OperationOutcome outcome;
    for (IBaseResource valueSet : valuesets.getResources(0, valuesets.size()))
    {
        outcome = this.performCodeSystemUpdate((ValueSet) valueSet);
        if (outcome.hasIssue())
        {
            for (OperationOutcome.OperationOutcomeIssueComponent issue : outcome.getIssue())
            {
                response.addIssue(issue);
            }
        }
    }

    return response;
}
 
Example #9
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 #10
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 #11
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 #12
Source File: ObservationDefinitionProvider.java    From careconnect-reference-implementation with Apache License 2.0 6 votes vote down vote up
@Delete
public MethodOutcome delete
        (@IdParam IdType internalId) {
    resourcePermissionProvider.checkPermission("delete");
    MethodOutcome method = new MethodOutcome();

    try {
        OperationOutcome outcome = observationDefinitionDao.delete(ctx,internalId);
        method.setCreated(false);

        method.setResource(outcome);
    } catch (Exception ex) {
        log.info(ex.getMessage());
        ProviderResponseLibrary.handleException(method,ex);
    }

    return method;
}
 
Example #13
Source File: ObservationDefinitionProvider.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Read
public ObservationDefinition get
        (@IdParam IdType internalId) {
    resourcePermissionProvider.checkPermission("read");
    ObservationDefinition observationDefinition = observationDefinitionDao.read( ctx, internalId);

    if ( observationDefinition == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(
                new ResourceNotFoundException("No ObservationDefinition/" + internalId.getIdPart()),
                 OperationOutcome.IssueType.NOTFOUND);
    }

    return observationDefinition;
}
 
Example #14
Source File: ResourceUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static boolean isAnError(OperationOutcome error) {
	for (OperationOutcomeIssueComponent t : error.getIssue())
		if (t.getSeverity() == IssueSeverity.ERROR)
			return true;
		else if (t.getSeverity() == IssueSeverity.FATAL)
			return true;
	return false;
}
 
Example #15
Source File: ObservationDefinitionDao.java    From careconnect-reference-implementation with Apache License 2.0 5 votes vote down vote up
@Override
public OperationOutcome delete(FhirContext ctx, IdType theId) {
    log.trace("Delete OperationDefinition = " + theId.getValue());

    ObservationDefinitionEntity observationDefinitionEntity = readEntity(ctx, theId);

    if (observationDefinitionEntity == null) return null;

    for (ObservationDefinitionIdentifier identifier : observationDefinitionEntity.getIdentifiers()) {
        em.remove(identifier);
    }
    em.remove(observationDefinitionEntity);
    return new OperationOutcome();

}
 
Example #16
Source File: Helper.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
public static OperationOutcome createErrorOutcome(String display) {
    Coding code = new Coding().setDisplay(display);
    return new OperationOutcome().addIssue(
            new OperationOutcome.OperationOutcomeIssueComponent()
                    .setSeverity(OperationOutcome.IssueSeverity.ERROR)
                    .setCode(OperationOutcome.IssueType.PROCESSING)
                    .setDetails(new CodeableConcept().addCoding(code))
    );
}
 
Example #17
Source File: CodeSystemUpdateProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
/***
 * Update existing CodeSystems with the codes in the specified ValueSet.
 *
 * This is for development environment purposes to enable ValueSet expansion and validation
 * without complete CodeSystems.
 *
 * @param theId the id of the ValueSet
 * @return FHIR OperationOutcome detailing the success or failure of the operation
 */
@Operation(name = "$updateCodeSystems", idempotent = true, type = ValueSet.class)
public OperationOutcome updateCodeSystems(@IdParam IdType theId)
{
    ValueSet vs = this.valueSetDao.read(theId);

    OperationOutcomeBuilder responseBuilder = new OperationOutcomeBuilder();
    if (vs == null)
    {
        return responseBuilder.buildIssue("error", "notfound", "Unable to find Resource: " + theId.getId()).build();
    }

    return performCodeSystemUpdate(vs);
}
 
Example #18
Source File: CodeSystemUpdateProvider.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
public OperationOutcome performCodeSystemUpdate(ValueSet vs)
{
    OperationOutcomeBuilder responseBuilder = new OperationOutcomeBuilder();

    List<String> codeSystems = new ArrayList<>();
    if (vs.hasCompose() && vs.getCompose().hasInclude())
    {
        CodeSystem codeSystem;
        for (ValueSet.ConceptSetComponent csc : vs.getCompose().getInclude())
        {
            if (!csc.hasSystem()) continue;

            codeSystem = getCodeSystemByUrl(csc.getSystem());

            if (!csc.hasConcept()) continue;

            updateCodeSystem(
                    codeSystem.setUrl(csc.getSystem()),
                    getUnionDistinctCodes(csc, codeSystem)
            );

            codeSystems.add(codeSystem.getUrl());
        }
    }

    return responseBuilder.buildIssue(
            "information",
            "informational",
            "Successfully updated the following CodeSystems: " + String.join(", ", codeSystems)
    ).build();
}
 
Example #19
Source File: OperationOutcomeBuilder.java    From cqf-ruler with Apache License 2.0 5 votes vote down vote up
public OperationOutcomeBuilder buildIssue(String severity, String code, String details)
{
    complexProperty.addIssue(
            new OperationOutcome.OperationOutcomeIssueComponent()
                    .setSeverity(OperationOutcome.IssueSeverity.fromCode(severity))
                    .setCode(OperationOutcome.IssueType.fromCode(code))
                    .setDetails(new CodeableConcept().setText(details))
    );

    return this;
}
 
Example #20
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 #21
Source File: FHIRToolingClient.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public <T extends Resource> T read(Class<T> resourceClass, String id) {//TODO Change this to AddressableResource
	ResourceRequest<T> result = null;
	try {
		result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), getPreferredResourceFormat());
		result.addErrorStatus(410);//gone
		result.addErrorStatus(404);//unknown
		result.addSuccessStatus(200);//Only one for now
		if(result.isUnsuccessfulRequest()) {
			throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome)result.getPayload());
		}
	} catch (Exception e) {
		handleException("An error has occurred while trying to read this resource", e);
	}
	return result.getPayload();
}
 
Example #22
Source File: ValueSetExpansionCache.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
private void loadCache() throws FHIRFormatError, IOException {
  File[] files = new File(cacheFolder).listFiles();
  for (File f : files) {
    if (f.getName().endsWith(".xml")) {
      final FileInputStream is = new FileInputStream(f);
      try {	   
        Resource r = context.newXmlParser().setOutputStyle(OutputStyle.PRETTY).parse(is);
        if (r instanceof OperationOutcome) {
          OperationOutcome oo = (OperationOutcome) r;
          expansions.put(ToolingExtensions.getExtension(oo,VS_ID_EXT).getValue().toString(),
              new ValueSetExpansionOutcome(new XhtmlComposer(XhtmlComposer.XML, false).composePlainText(oo.getText().getDiv()), TerminologyServiceErrorClass.UNKNOWN));
        } else if (r instanceof ValueSet) {
          ValueSet vs = (ValueSet) r;
          if (vs.hasExpansion())
            expansions.put(vs.getUrl(), new ValueSetExpansionOutcome(vs));
          else {
            canonicals.put(vs.getUrl(), vs);
            if (vs.hasVersion())
              canonicals.put(vs.getUrl()+"|"+vs.getVersion(), vs);
          }
        } else if (r instanceof MetadataResource) {
          MetadataResource md = (MetadataResource) r;
          canonicals.put(md.getUrl(), md);
          if (md.hasVersion())
            canonicals.put(md.getUrl()+"|"+md.getVersion(), md);
        }
      } finally {
        IOUtils.closeQuietly(is);
      }
    }
  }
}
 
Example #23
Source File: EOperationOutcome.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public OperationOutcome getOutcome() {
  return outcome;
}
 
Example #24
Source File: EOperationOutcome.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public EOperationOutcome(OperationOutcome outcome) {
  super();
  this.outcome = outcome;
}
 
Example #25
Source File: EFhirClientException.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
public EFhirClientException(String message, List<OperationOutcome> serverErrors) {
	super(message);
	if(serverErrors != null && serverErrors.size() > 0) {
		errors.addAll(serverErrors);
	}
}
 
Example #26
Source File: ClientUtils.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private boolean hasError(OperationOutcome oo) {
  for (OperationOutcomeIssueComponent t : oo.getIssue())
    if (t.getSeverity() == IssueSeverity.ERROR || t.getSeverity() == IssueSeverity.FATAL)
      return true;
  return false;
}
 
Example #27
Source File: OperationOutcomeBuilder.java    From cqf-ruler with Apache License 2.0 4 votes vote down vote up
public OperationOutcomeBuilder()
{
    super(new OperationOutcome());
}
 
Example #28
Source File: EFhirClientException.java    From org.hl7.fhir.core with Apache License 2.0 3 votes vote down vote up
/**
 * Generate EFhirClientException indicating the cause of the exception
 * along with any OperationOutcome server error the server may have generated.
 * 
 * A default message of "One or more server side errors have occurred during this operation. Refer to e.getServerErrors() for additional details."
 * will be returned to users.
 * 
 * @param message
 * @param serverError
 */
public EFhirClientException(OperationOutcome serverError) {
	super("Error on the server: "+serverError.getText().getDiv().allText()+". Refer to e.getServerErrors() for additional details.");
	if(serverError != null) {
		errors.add(serverError);
	}
}
 
Example #29
Source File: EFhirClientException.java    From org.hl7.fhir.core with Apache License 2.0 3 votes vote down vote up
/**
 * Generate EFhirClientException which include a message indicating the cause of the exception
 * along with any OperationOutcome server error that may have resulted.
 * 
 * @param message
 * @param serverError
 */
public EFhirClientException(String message, OperationOutcome serverError) {
	super(message);
	if(serverError != null) {
		errors.add(serverError);
	}
}
 
Example #30
Source File: EFhirClientException.java    From org.hl7.fhir.core with Apache License 2.0 2 votes vote down vote up
/**
 * Method returns all OperationOutcome server errors that are 
 * associated with this exception.
 * 
 * @return
 */
public List<OperationOutcome> getServerErrors() {
	return errors;
}