Search in sources :

Example 51 with Endpoint

use of org.hl7.fhir.r4.model.Endpoint in project dpc-app by CMSgov.

the class EndpointResourceTest method testUpdateEndpoint.

@Test
void testUpdateEndpoint() {
    Organization organization = OrganizationHelpers.createOrganization(ctx, client, "1211111111", false);
    String endpointId = FHIRExtractors.getEntityUUID(organization.getEndpointFirstRep().getReference()).toString();
    Endpoint endpoint = client.read().resource(Endpoint.class).withId(endpointId).execute();
    endpoint.setName("New Endpoint Name");
    MethodOutcome outcome = client.update().resource(endpoint).withId(endpoint.getId()).execute();
    Endpoint updatedEndpoint = (Endpoint) outcome.getResource();
    assertTrue(updatedEndpoint.equalsDeep(endpoint));
}
Also used : Organization(org.hl7.fhir.dstu3.model.Organization) Endpoint(org.hl7.fhir.dstu3.model.Endpoint) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) AbstractAttributionTest(gov.cms.dpc.attribution.AbstractAttributionTest) Test(org.junit.jupiter.api.Test) IntegrationTest(gov.cms.dpc.testing.IntegrationTest)

Example 52 with Endpoint

use of org.hl7.fhir.r4.model.Endpoint in project dpc-app by CMSgov.

the class EndpointResource method searchEndpoints.

@FHIR
@GET
@Timed
@ExceptionMetered
@UnitOfWork
@Override
public List<Endpoint> searchEndpoints(@NotNull @QueryParam("organization") String organizationID, @QueryParam("_id") String resourceId) {
    final UUID orgUUID = FHIRExtractors.getEntityUUID(organizationID);
    UUID endpointUUID = null;
    if (resourceId != null) {
        endpointUUID = FHIRExtractors.getEntityUUID(resourceId);
    }
    final List<EndpointEntity> endpointList = this.endpointDAO.endpointSearch(orgUUID, endpointUUID);
    return endpointList.stream().map(e -> converter.toFHIR(Endpoint.class, e)).collect(Collectors.toList());
}
Also used : FHIREntityConverter(gov.cms.dpc.fhir.converters.FHIREntityConverter) FHIR(gov.cms.dpc.fhir.annotations.FHIR) EndpointDAO(gov.cms.dpc.attribution.jdbi.EndpointDAO) OrganizationDAO(gov.cms.dpc.attribution.jdbi.OrganizationDAO) OrganizationEntity(gov.cms.dpc.common.entities.OrganizationEntity) UUID(java.util.UUID) NotNull(javax.validation.constraints.NotNull) AbstractEndpointResource(gov.cms.dpc.attribution.resources.AbstractEndpointResource) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) Endpoint(org.hl7.fhir.dstu3.model.Endpoint) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered) HttpStatus(org.eclipse.jetty.http.HttpStatus) FHIRExtractors(gov.cms.dpc.fhir.FHIRExtractors) EndpointEntity(gov.cms.dpc.common.entities.EndpointEntity) UUID(java.util.UUID) EndpointEntity(gov.cms.dpc.common.entities.EndpointEntity) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) Timed(com.codahale.metrics.annotation.Timed) FHIR(gov.cms.dpc.fhir.annotations.FHIR) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 53 with Endpoint

use of org.hl7.fhir.r4.model.Endpoint in project dpc-app by CMSgov.

the class OrganizationResourceTest method testMissingOrganization.

@Test
void testMissingOrganization() throws IOException {
    // Generate a golden macaroon
    final String goldenMacaroon = APIAuthHelpers.createGoldenMacaroon();
    final IGenericClient client = APIAuthHelpers.buildAdminClient(ctx, getBaseURL(), goldenMacaroon, false);
    final Endpoint endpoint = OrganizationFactory.createFakeEndpoint();
    final Bundle bundle = new Bundle();
    bundle.addEntry().setResource(endpoint);
    final Parameters parameters = new Parameters();
    parameters.addParameter().setName("resource").setResource(bundle);
    final IOperationUntypedWithInput<Organization> operation = client.operation().onType(Organization.class).named("submit").withParameters(parameters).returnResourceType(Organization.class).encodedJson();
    assertThrows(InvalidRequestException.class, operation::execute, "Should be unprocessable");
}
Also used : Parameters(org.hl7.fhir.dstu3.model.Parameters) Organization(org.hl7.fhir.dstu3.model.Organization) Endpoint(org.hl7.fhir.dstu3.model.Endpoint) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Bundle(org.hl7.fhir.dstu3.model.Bundle) Test(org.junit.jupiter.api.Test) AbstractSecureApplicationTest(gov.cms.dpc.api.AbstractSecureApplicationTest)

Example 54 with Endpoint

use of org.hl7.fhir.r4.model.Endpoint in project dpc-app by CMSgov.

the class OrganizationResourceTest method testUpdateOrganization.

@Test
void testUpdateOrganization() throws IOException, URISyntaxException, GeneralSecurityException {
    final String orgID = UUID.randomUUID().toString();
    final IParser parser = ctx.newJsonParser();
    final IGenericClient attrClient = APITestHelpers.buildAttributionClient(ctx);
    final String macaroon = FHIRHelpers.registerOrganization(attrClient, parser, orgID, "1111121111", getAdminURL());
    final Pair<UUID, PrivateKey> uuidPrivateKeyPair = APIAuthHelpers.generateAndUploadKey("org-update-key", orgID, GOLDEN_MACAROON, getBaseURL());
    final IGenericClient client = APIAuthHelpers.buildAuthenticatedClient(ctx, getBaseURL(), macaroon, uuidPrivateKeyPair.getLeft(), uuidPrivateKeyPair.getRight());
    Organization organization = client.read().resource(Organization.class).withId(orgID).encodedJson().execute();
    assertNotNull(organization);
    organization.setName("New Org Name");
    organization.setContact(Lists.emptyList());
    MethodOutcome outcome = client.update().resource(organization).execute();
    Organization result = (Organization) outcome.getResource();
    assertEquals("1111121111", result.getIdentifierFirstRep().getValue());
    assertEquals(organization.getName(), result.getName(), "Name should be updated");
    assertTrue(organization.getContact().isEmpty(), "Contact list should be updated");
    assertEquals(1, result.getEndpoint().size(), "Endpoint list should be unchanged");
    // Try to update when authenticated as different organization
    final String org2ID = UUID.randomUUID().toString();
    final String org2Macaroon = FHIRHelpers.registerOrganization(attrClient, parser, org2ID, "4321234211", getAdminURL());
    final Pair<UUID, PrivateKey> org2UUIDPrivateKeyPair = APIAuthHelpers.generateAndUploadKey("org2-update-key", org2ID, GOLDEN_MACAROON, getBaseURL());
    final IGenericClient org2Client = APIAuthHelpers.buildAuthenticatedClient(ctx, getBaseURL(), org2Macaroon, org2UUIDPrivateKeyPair.getLeft(), org2UUIDPrivateKeyPair.getRight());
    IUpdateTyped update = org2Client.update().resource(organization);
    assertThrows(AuthenticationException.class, update::execute);
}
Also used : PrivateKey(java.security.PrivateKey) Organization(org.hl7.fhir.dstu3.model.Organization) IUpdateTyped(ca.uhn.fhir.rest.gclient.IUpdateTyped) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) UUID(java.util.UUID) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) IParser(ca.uhn.fhir.parser.IParser) Test(org.junit.jupiter.api.Test) AbstractSecureApplicationTest(gov.cms.dpc.api.AbstractSecureApplicationTest)

Example 55 with Endpoint

use of org.hl7.fhir.r4.model.Endpoint in project dpc-app by CMSgov.

the class EndpointResourceTest method testGetEndpoints.

@Test
void testGetEndpoints() {
    Bundle result = client.search().forResource(Endpoint.class).returnBundle(Bundle.class).execute();
    assertTrue(result.getTotal() > 0);
    for (Bundle.BundleEntryComponent component : result.getEntry()) {
        Resource resource = component.getResource();
        assertEquals(DPCResourceType.Endpoint.getPath(), resource.getResourceType().getPath());
        Endpoint endpoint = (Endpoint) resource;
        assertEquals(APITestHelpers.ORGANIZATION_ID, FHIRExtractors.getEntityUUID(endpoint.getManagingOrganization().getReference()).toString());
    }
}
Also used : IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) AbstractSecureApplicationTest(gov.cms.dpc.api.AbstractSecureApplicationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)36 Endpoint (org.hl7.fhir.dstu3.model.Endpoint)21 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 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)15 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 Bundle (org.hl7.fhir.r4.model.Bundle)12 Organization (org.hl7.fhir.dstu3.model.Organization)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 List (java.util.List)7 Bundle (org.hl7.fhir.dstu3.model.Bundle)7 Description (ca.uhn.fhir.model.api.annotation.Description)6 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)6 ArrayList (java.util.ArrayList)6