Search in sources :

Example 21 with Endpoint

use of org.hl7.fhir.dstu3.model.Endpoint in project Gravity-SDOH-Exchange-RI by FHIR.

the class AuthorizationClient method getTokenResponse.

/**
 * Extract token endpoint url from the Authorization Server metadata endpoint and return token response after
 * successful authentication.
 *
 * @param authServerUrl Authorization Server Base URL
 * @param clientId      OAuth2 Client ID
 * @param secret        OAuth2 Client Secret
 * @param scope         OAuth2 Client Scope
 * @return {@link TokenResponse} entity
 * @throws AuthClientException will be thrown if token retrieval fails
 */
public TokenResponse getTokenResponse(URI authServerUrl, String clientId, String secret, String scope) throws AuthClientException {
    HttpEntity<MultiValueMap<String, String>> entity = createRequestEntity(clientId, secret, scope);
    String tokenEndpoint = getTokenEndpoint(authServerUrl);
    try {
        return restTemplate.exchange(tokenEndpoint, HttpMethod.POST, entity, TokenResponse.class).getBody();
    } catch (RestClientException e) {
        throw new AuthClientException(e.getMessage(), e);
    }
}
Also used : AuthClientException(org.hl7.gravity.refimpl.sdohexchange.exception.AuthClientException) RestClientException(org.springframework.web.client.RestClientException) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 22 with Endpoint

use of org.hl7.fhir.dstu3.model.Endpoint in project Gravity-SDOH-Exchange-RI by FHIR.

the class CpService method create.

public void create(final Task ehrTask, final Endpoint endpoint) throws CpClientException {
    Task cpTask = externalizeResource(ehrTask.copy(), identifierSystem);
    // TODO: Remove this after Logica bug response
    cpTask.setMeta(null);
    cpTask.addIdentifier().setSystem(identifierSystem).setValue(ehrTask.getIdElement().getIdPart());
    try {
        cpClient(endpoint).create().resource(cpTask).execute();
    } catch (BaseServerResponseException exc) {
        throw new CpClientException(String.format("Could not create a Task with identifier '%s' in CP at '%s'. Reason: %s.", identifierSystem + "|" + ehrTask.getIdElement().getIdPart(), endpoint.getAddress(), exc.getMessage()), exc);
    }
}
Also used : Task(org.hl7.fhir.r4.model.Task) BaseServerResponseException(ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException)

Example 23 with Endpoint

use of org.hl7.fhir.dstu3.model.Endpoint in project Gravity-SDOH-Exchange-RI by FHIR.

the class CpService method read.

public TaskInfoHolder read(final String id, final Endpoint endpoint) throws CpClientException {
    try {
        Bundle taskBundle = cpClient(endpoint).search().forResource(Task.class).where(Task.IDENTIFIER.exactly().systemAndValues(identifierSystem, id)).include(Task.INCLUDE_FOCUS).returnBundle(Bundle.class).execute();
        // Additional validation
        int tasksSize = FhirUtil.getFromBundle(taskBundle, Task.class).size();
        if (tasksSize == 0) {
            throw new CpClientException(String.format("No Task is present at '%s' for identifier '%s'.", endpoint.getAddress(), identifierSystem + "|" + id));
        } else if (tasksSize > 1) {
            throw new CpClientException(String.format("More than one Task is present at '%s' for identifier '%s'.", endpoint.getAddress(), identifierSystem + "|" + id));
        }
        return new TaskInfoBundleExtractor().extract(taskBundle).stream().findFirst().get();
    } catch (BaseServerResponseException exc) {
        throw new CpClientException(String.format("Task retrieval failed for identifier '%s' at CP location '%s'. Reason: %s.", identifierSystem + "|" + id, endpoint.getAddress(), exc.getMessage()), exc);
    }
}
Also used : Task(org.hl7.fhir.r4.model.Task) Bundle(org.hl7.fhir.r4.model.Bundle) TaskInfoBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.TaskInfoBundleExtractor) BaseServerResponseException(ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException) Endpoint(org.hl7.fhir.r4.model.Endpoint)

Example 24 with Endpoint

use of org.hl7.fhir.dstu3.model.Endpoint in project integration-adaptor-111 by nhsconnect.

the class MessageHeaderServiceTest method shouldCreateMessageHeader.

@Test
public void shouldCreateMessageHeader() {
    ItkReportHeader itkReportHeader = new ItkReportHeader();
    itkReportHeader.setSpecKey(SPECIFICATION_KEY);
    itkReportHeader.setSpecVal(SPECIFICATION_VALUE);
    itkReportHeader.setAddressList(Arrays.asList(ADDRESS));
    MessageHeader messageHeader = messageHeaderService.createMessageHeader(itkReportHeader, MESSAGEID, EFFECTIVE_TIME);
    assertThat(messageHeader.getId()).isEqualTo(MESSAGEID);
    Coding event = messageHeader.getEvent();
    assertThat(event.getSystem()).isEqualTo(MessageHeaderEvent.SYSTEM);
    assertThat(event.getCode()).isEqualTo(DISCHARGE_DETAILS.getCode());
    assertThat(event.getDisplay()).isEqualTo(DISCHARGE_DETAILS.getDisplay());
    MessageSourceComponent source = messageHeader.getSource();
    assertThat(source.getName()).isEqualTo(MESSAGE_SOURCE_NAME);
    assertThat(source.getEndpoint()).isEqualTo(ENDPOINT);
    assertThat(messageHeader.getReason().getCodingFirstRep().getSystem()).isEqualTo(SPECIFICATION_KEY);
    assertThat(messageHeader.getReason().getCodingFirstRep().getCode()).isEqualTo(SPECIFICATION_VALUE);
    assertThat(messageHeader.getDestinationFirstRep().getEndpoint()).isEqualTo(ADDRESS);
    assertThat(messageHeader.getTimestampElement()).isEqualToComparingFieldByField(DateUtil.parseToInstantType(EFFECTIVE_TIME));
}
Also used : Coding(org.hl7.fhir.dstu3.model.Coding) ItkReportHeader(uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader) MessageSourceComponent(org.hl7.fhir.dstu3.model.MessageHeader.MessageSourceComponent) MessageHeader(org.hl7.fhir.dstu3.model.MessageHeader) Test(org.junit.jupiter.api.Test)

Example 25 with Endpoint

use of org.hl7.fhir.dstu3.model.Endpoint in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeConformanceConformanceMessagingEndpointComponent.

protected void composeConformanceConformanceMessagingEndpointComponent(Complex parent, String parentType, String name, Conformance.ConformanceMessagingEndpointComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "endpoint", name, element, index);
    if (element.hasProtocol())
        composeCoding(t, "Conformance", "protocol", element.getProtocol(), -1);
    if (element.hasAddressElement())
        composeUri(t, "Conformance", "address", element.getAddressElement(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Aggregations

Test (org.junit.jupiter.api.Test)26 RequestDetails (ca.uhn.fhir.rest.api.server.RequestDetails)18 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)16 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)16 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 Endpoint (org.hl7.fhir.r4.model.Endpoint)15 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)14 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)14 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)12 Bundle (org.hl7.fhir.r4.model.Bundle)12 Endpoint (org.hl7.fhir.dstu3.model.Endpoint)11 Resource (org.hl7.fhir.r4.model.Resource)10 Resource (org.hl7.fhir.dstu3.model.Resource)9 Operation (ca.uhn.fhir.rest.annotation.Operation)7 Description (ca.uhn.fhir.model.api.annotation.Description)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 HashMap (java.util.HashMap)5 Task (org.hl7.fhir.r4.model.Task)5 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)4