Java Code Examples for org.hl7.fhir.dstu3.model.OperationOutcome

The following examples show how to use org.hl7.fhir.dstu3.model.OperationOutcome. These examples are extracted from open source projects. 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 Project: org.hl7.fhir.core   Source File: ValueSetExpansionCache.java    License: Apache License 2.0 6 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).composePlainText(oo.getText().getDiv()), TerminologyServiceErrorClass.UNKNOWN));
      } else {
        ValueSet vs = (ValueSet) r; 
        expansions.put(vs.getUrl(), new ValueSetExpansionOutcome(vs));
      }
      } finally {
        IOUtils.closeQuietly(is);
      }
    }
  }
}
 
Example 2
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam Observation observation, @IdParam IdType theId,@ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {
	resourcePermissionProvider.checkPermission("update");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();
    	
    method.setOperationOutcome(opOutcome);
    try {

        Observation newObservation = observationDao.save(ctx,observation,theId,theConditional);
        method.setId(newObservation.getIdElement());
        method.setResource(newObservation);
    } catch (BaseServerResponseException srv) {
        // HAPI Exceptions pass through
        throw srv;
    } catch(Exception ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }

    return method;
}
 
Example 3
Source Project: org.hl7.fhir.core   Source File: FHIRToolingClient.java    License: 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 4
Source Project: org.hl7.fhir.core   Source File: FHIRToolingClient.java    License: 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 5
Source Project: org.hl7.fhir.core   Source File: FHIRToolingClient.java    License: 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 6
@Update
public MethodOutcome updateSlot(HttpServletRequest theRequest, @ResourceParam Slot slot, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {

	resourcePermissionProvider.checkPermission("update");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
        Slot existingSlot = slotDao.create(ctx, slot, theId, theConditional);
        method.setId(existingSlot.getIdElement());
        method.setResource(existingSlot);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }


    return method;
}
 
Example 7
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam EpisodeOfCare episode) {

	resourcePermissionProvider.checkPermission("create");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
        EpisodeOfCare newEpisodeOfCare = episodeDao.create(ctx, episode, null, null);
        method.setId(newEpisodeOfCare.getIdElement());
        method.setResource(newEpisodeOfCare);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }


    return method;
}
 
Example 8
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());
    // also, populate the XPath variant
    StringType s = new StringType();
    s.setValue(Utilities.fhirPathToXPath(message.getLocation())+(message.getLine()>= 0 && message.getCol() >= 0 ? " (line "+Integer.toString(message.getLine())+", col"+Integer.toString(message.getCol())+")" : "") );
    issue.getLocation().add(s);
  }
  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 9
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam Questionnaire questionnaire) {

    resourcePermissionProvider.checkPermission("create");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);
    try {
        Questionnaire newQuestionnaire = questionnaireDao.create(ctx, questionnaire, null, null);
        method.setId(newQuestionnaire.getIdElement());
        method.setResource(newQuestionnaire);
    } catch (BaseServerResponseException srv) {
        // HAPI Exceptions pass through
        throw srv;
    } catch(Exception ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }

    return method;
}
 
Example 10
@Update()
public MethodOutcome update(HttpServletRequest theRequest,@ResourceParam GraphDefinition graph) {

	resourcePermissionProvider.checkPermission("update");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);


    try {
        GraphDefinition newGraphDefinition = graphDao.create(ctx, graph);
        method.setId(newGraphDefinition.getIdElement());
        method.setResource(newGraphDefinition);
    } catch (BaseServerResponseException srv) {
        // HAPI Exceptions pass through
        throw srv;
    } catch(Exception ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }


    return method;
}
 
Example 11
public static void main(String[] args) {
	
	// Create an incomplete encounter (status is required)
	Encounter enc = new Encounter();
	enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345");
	
	// Create a new validator
	FhirContext ctx = FhirContext.forDstu3();
	FhirValidator validator = ctx.newValidator();
	
	// Did we succeed?
	ValidationResult result = validator.validateWithResult(enc);
	System.out.println("Success: " + result.isSuccessful());
	
	// What was the result
	OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome();
	IParser parser = ctx.newXmlParser().setPrettyPrint(true);
	System.out.println(parser.encodeResourceToString(outcome));
}
 
Example 12
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam QuestionnaireResponse form) {

    resourcePermissionProvider.checkPermission("create");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);
    try {

        QuestionnaireResponse newForm = formDao.create(ctx, form, null, null);
        method.setId(newForm.getIdElement());
        method.setResource(newForm);
    } catch (BaseServerResponseException srv) {
        // HAPI Exceptions pass through
        throw srv;
    } catch(Exception ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }

    return method;
}
 
Example 13
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam MedicationDispense dispense, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {

	resourcePermissionProvider.checkPermission("update");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
    MedicationDispense newMedicationDispense = dispenseDao.create(ctx,dispense, theId, theConditional);
    method.setId(newMedicationDispense.getIdElement());
    method.setResource(newMedicationDispense);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }



    return method;
}
 
Example 14
Source Project: cqf-ruler   Source File: CodeSystemUpdateProvider.java    License: 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 15
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam Patient patient, @IdParam IdType theId,@ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {

    log.debug("Update Patient Provider called");
    
    resourcePermissionProvider.checkPermission("update");

    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);
    Patient newPatient = null;
    try {
        newPatient = patientDao.update(ctx, patient, theId, theConditional);
    } catch (OperationOutcomeException ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }
    method.setId(newPatient.getIdElement());
    method.setResource(newPatient);


    log.debug("called update Patient method");

    return method;
}
 
Example 16
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam Condition condition, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {
	resourcePermissionProvider.checkPermission("update");

    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
        Condition newCondition = conditionDao.create(ctx, condition, theId, theConditional);
        method.setId(newCondition.getIdElement());
        method.setResource(newCondition);
    } catch (BaseServerResponseException srv) {
        // HAPI Exceptions pass through
        throw srv;
    } catch(Exception ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }


    return method;
}
 
Example 17
public static void convertToException (OperationOutcome outcome ) {
    for (OperationOutcome.OperationOutcomeIssueComponent issue : outcome.getIssue()) {


        String text = null;
        String diagnostics = "";
        if (issue.getDiagnostics() != null ) diagnostics = issue.getDiagnostics();
        if (issue.getDetails() != null) text =issue.getDetails().getText();

        if (text ==null && issue.getDiagnostics() !=null) text = issue.getDiagnostics();

        if (text==null) text = "Unknown Reason";

        processCode(outcome, issue, text, diagnostics);
    }
    // Catch all
    throw new UnprocessableEntityException("Unknown Error", outcome);
}
 
Example 18
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam DocumentReference documentReference, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {
	resourcePermissionProvider.checkPermission("update");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();
    method.setOperationOutcome(opOutcome);
    try {
    DocumentReference newDocumentReference = documentReferenceDao.create(ctx,documentReference, theId, theConditional);
    method.setId(newDocumentReference.getIdElement());
    method.setResource(newDocumentReference);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }


    return method;
}
 
Example 19
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam MedicationAdministration administration, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {

	resourcePermissionProvider.checkPermission("update");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
    MedicationAdministration newMedicationAdministration = administrationDao.create(ctx,administration, theId, theConditional);
    method.setId(newMedicationAdministration.getIdElement());
    method.setResource(newMedicationAdministration);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }



    return method;
}
 
Example 20
@Update
public MethodOutcome updateList(HttpServletRequest theRequest, @ResourceParam ListResource list, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {

	resourcePermissionProvider.checkPermission("update");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

try {
    log.info(theId.getId());
    ListResource newList = listDao.create(ctx, list, theId, theConditional);
    method.setId(newList.getIdElement());
    method.setResource(newList);

} catch (Exception ex) {

    ProviderResponseLibrary.handleException(method,ex);
}


    return method;
}
 
Example 21
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam Condition condition) {

	resourcePermissionProvider.checkPermission("create");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
    Condition newCondition = conditionDao.create(ctx,condition, null,null);
    method.setId(newCondition.getIdElement());
    method.setResource(newCondition);
    } catch (BaseServerResponseException srv) {
        // HAPI Exceptions pass through
        throw srv;
    } catch(Exception ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }

    return method;
}
 
Example 22
@Create
public MethodOutcome createEndpoint(HttpServletRequest theRequest, @ResourceParam Endpoint endpoint) {

	resourcePermissionProvider.checkPermission("create");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);
    try {
        Endpoint newEndpoint = endpointDao.create(ctx, endpoint,null,null);
        method.setId(newEndpoint.getIdElement());
        method.setResource(newEndpoint);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }

    return method;
}
 
Example 23
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam Composition composition, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {
	resourcePermissionProvider.checkPermission("update");
	
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();
    method.setOperationOutcome(opOutcome);
    try {
        Composition newComposition = compositionDao.create(ctx,composition, theId, theConditional);
        method.setId(newComposition.getIdElement());
        method.setResource(newComposition);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }


    return method;
}
 
Example 24
@Create
public MethodOutcome createLocation(HttpServletRequest theRequest, @ResourceParam Location location) {

	resourcePermissionProvider.checkPermission("create");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);
    try {
    Location newLocation = locationDao.create(ctx, location,null,null);
    method.setId(newLocation.getIdElement());
    method.setResource(newLocation);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }

    return method;
}
 
Example 25
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam Encounter encounter, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {

	resourcePermissionProvider.checkPermission("update");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
        Encounter newEncounter = encounterDao.create(ctx, encounter, theId, theConditional);
        method.setId(newEncounter.getIdElement());
        method.setResource(newEncounter);
    } catch (Exception ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }


    return method;
}
 
Example 26
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam Encounter encounter) {

	resourcePermissionProvider.checkPermission("create");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
        Encounter newEncounter = encounterDao.create(ctx, encounter, null, null);
        method.setId(newEncounter.getIdElement());
        method.setResource(newEncounter);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }


    return method;
}
 
Example 27
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam Immunization immunisation, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {
	resourcePermissionProvider.checkPermission("update");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();
    method.setOperationOutcome(opOutcome);
    try {
        Immunization newImmunisation = immunisationDao.create(ctx,immunisation, theId, theConditional);
        method.setId(newImmunisation.getIdElement());
        method.setResource(newImmunisation);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }


    return method;
}
 
Example 28
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam Consent consent) {

	resourcePermissionProvider.checkPermission("create");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {

        Consent newConsent = consentDao.create(ctx,consent, null,null);
        method.setId(newConsent.getIdElement());
        method.setResource(newConsent);
    } catch (Exception ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }


    return method;
}
 
Example 29
@Update
public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam MedicationRequest prescription, @IdParam IdType theId, @ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {

	resourcePermissionProvider.checkPermission("update");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
    MedicationRequest newMedicationRequest = prescriptionDao.create(ctx,prescription, theId, theConditional);
    method.setId(newMedicationRequest.getIdElement());
    method.setResource(newMedicationRequest);
    } catch (Exception ex) {

        ProviderResponseLibrary.handleException(method,ex);
    }



    return method;
}
 
Example 30
@Create
public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam RiskAssessment riskAssessment) {

	resourcePermissionProvider.checkPermission("create");
    MethodOutcome method = new MethodOutcome();
    method.setCreated(true);
    OperationOutcome opOutcome = new OperationOutcome();

    method.setOperationOutcome(opOutcome);

    try {
        RiskAssessment newRiskAssessment = riskAssessmentDao.create(ctx,riskAssessment, null,null);
        method.setId(newRiskAssessment.getIdElement());
        method.setResource(newRiskAssessment);
    } catch (Exception ex) {
        ProviderResponseLibrary.handleException(method,ex);
    }


    return method;
}