Search in sources :

Example 81 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project org.hl7.fhir.core by hapifhir.

the class ToolsHelper method generateSnapshots.

private void generateSnapshots(String[] args) throws IOException, FHIRException {
    if (args.length == 1) {
        System.out.println("tools.jar snapshot-maker [source] -defn [definitions]");
        System.out.println("");
        System.out.println("Generates a snapshot from a differential. The nominated profile must have a single struture that has a differential");
        System.out.println("");
        System.out.println("source - the profile to generate the snapshot for. Maybe a file name, or a URL reference to a server running FHIR RESTful API");
        System.out.println("definitions - filename for local copy of the validation.zip file");
    }
    String address = args[1];
    String definitions = args[3];
    SimpleWorkerContext context = SimpleWorkerContext.fromDefinitions(getDefinitions(definitions));
    // } else {
    throw new NotImplementedException("generating snapshots not done yet (address = " + address + ")");
// }
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) SimpleWorkerContext(org.hl7.fhir.dstu2.utils.SimpleWorkerContext)

Example 82 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method supportsSystem.

@Override
public boolean supportsSystem(String system) throws TerminologyServiceException {
    if (codeSystems.containsKey(system)) {
        return true;
    } else if (nonSupportedCodeSystems.contains(system)) {
        return false;
    } else if (system.startsWith("http://example.org") || system.startsWith("http://acme.com") || system.startsWith("http://hl7.org/fhir/valueset-") || system.startsWith("urn:oid:")) {
        return false;
    } else {
        if (noTerminologyServer) {
            return false;
        }
        if (bndCodeSystems == null) {
            try {
                tlog("Terminology server: Check for supported code systems for " + system);
                bndCodeSystems = txServer.fetchFeed(txServer.getAddress() + "/CodeSystem?content-mode=not-present&_summary=true&_count=1000");
            } catch (Exception e) {
                if (canRunWithoutTerminology) {
                    noTerminologyServer = true;
                    log("==============!! Running without terminology server !!============== (" + e.getMessage() + ")");
                    return false;
                } else {
                    throw new TerminologyServiceException(e);
                }
            }
        }
        if (bndCodeSystems != null) {
            for (BundleEntryComponent be : bndCodeSystems.getEntry()) {
                CodeSystem cs = (CodeSystem) be.getResource();
                if (!codeSystems.containsKey(cs.getUrl())) {
                    codeSystems.put(cs.getUrl(), null);
                }
            }
        }
        if (codeSystems.containsKey(system)) {
            return true;
        }
    }
    nonSupportedCodeSystems.add(system);
    return false;
}
Also used : BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 83 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project org.hl7.fhir.core by hapifhir.

the class ToolsHelper method generateSnapshots.

private void generateSnapshots(String[] args) throws IOException, FHIRException {
    if (args.length == 1) {
        System.out.println("tools.jar snapshot-maker [source] -defn [definitions]");
        System.out.println("");
        System.out.println("Generates a snapshot from a differential. The nominated profile must have a single struture that has a differential");
        System.out.println("");
        System.out.println("source - the profile to generate the snapshot for. Maybe a file name, or a URL reference to a server running FHIR RESTful API");
        System.out.println("definitions - filename for local copy of the validation.zip file");
    }
    String address = args[1];
    String definitions = args[3];
    SimpleWorkerContext context = SimpleWorkerContext.fromDefinitions(getDefinitions(definitions));
    // } else {
    throw new NotImplementedException("generating snapshots not done yet (address = " + address + ")");
// }
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) SimpleWorkerContext(org.hl7.fhir.dstu2016may.utils.SimpleWorkerContext)

Example 84 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project org.hl7.fhir.core by hapifhir.

the class ClientUtils method unmarshalFeed.

/**
 * Unmarshals Bundle from response stream.
 *
 * @param response
 * @return
 */
protected Bundle unmarshalFeed(HttpResponse response, String format) {
    Bundle feed = null;
    byte[] cnt = log(response);
    String contentType = response.getHeaders("Content-Type")[0].getValue();
    OperationOutcome error = null;
    try {
        if (cnt != null) {
            if (contentType.contains(ResourceFormat.RESOURCE_XML.getHeader()) || contentType.contains("text/xml+fhir")) {
                Resource rf = getParser(format).parse(cnt);
                if (rf instanceof Bundle)
                    feed = (Bundle) rf;
                else if (rf instanceof OperationOutcome && hasError((OperationOutcome) rf)) {
                    error = (OperationOutcome) rf;
                } else {
                    throw new EFhirClientException("Error reading server response: a resource was returned instead");
                }
            }
        }
    } catch (IOException ioe) {
        throw new EFhirClientException("Error reading Http Response", ioe);
    } catch (Exception e) {
        throw new EFhirClientException("Error parsing response message", e);
    }
    if (error != null) {
        throw new EFhirClientException("Error from server: " + ResourceUtilities.getErrorDescription(error), error);
    }
    return feed;
}
Also used : Bundle(org.hl7.fhir.dstu2.model.Bundle) OperationOutcome(org.hl7.fhir.dstu2.model.OperationOutcome) Resource(org.hl7.fhir.dstu2.model.Resource) IOException(java.io.IOException) ParseException(java.text.ParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 85 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server 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

Test (org.junit.Test)107 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)100 IOException (java.io.IOException)47 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)42 FHIRException (org.hl7.fhir.exceptions.FHIRException)39 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)38 ArrayList (java.util.ArrayList)25 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)24 FileNotFoundException (java.io.FileNotFoundException)21 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)19 Date (java.util.Date)18 Bundle (org.hl7.fhir.r4.model.Bundle)17 URISyntaxException (java.net.URISyntaxException)16 HashMap (java.util.HashMap)16 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 FhirContext (ca.uhn.fhir.context.FhirContext)14 LocalDate (java.time.LocalDate)14 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)13 File (java.io.File)12 Header (org.apache.http.Header)11