Search in sources :

Example 46 with Endpoint

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

the class EndpointResourceUnitTest method testCreateEndpointWithManagingOrganizationMismatch.

@Test
public void testCreateEndpointWithManagingOrganizationMismatch() {
    UUID orgId = UUID.randomUUID();
    Organization organization = new Organization();
    organization.setId(orgId.toString());
    OrganizationPrincipal organizationPrincipal = new OrganizationPrincipal(organization);
    Endpoint endpoint = new Endpoint();
    endpoint.setManagingOrganization(new Reference("Organization/" + UUID.randomUUID()));
    assertThrows(WebApplicationException.class, () -> resource.createEndpoint(organizationPrincipal, endpoint));
}
Also used : OrganizationPrincipal(gov.cms.dpc.api.auth.OrganizationPrincipal) Organization(org.hl7.fhir.dstu3.model.Organization) Endpoint(org.hl7.fhir.dstu3.model.Endpoint) Reference(org.hl7.fhir.dstu3.model.Reference) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 47 with Endpoint

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

the class SeedCommand method seedOrganizationBundle.

private void seedOrganizationBundle(FHIREntityConverter converter, DSLContext context, IParser parser) throws IOException {
    try (final InputStream orgBundleStream = SeedCommand.class.getClassLoader().getResourceAsStream(ORGANIZATION_BUNDLE)) {
        if (orgBundleStream == null) {
            throw new MissingResourceException("Can not find seeds file", this.getClass().getName(), CSV);
        }
        final Bundle bundle = parser.parseResource(Bundle.class, orgBundleStream);
        final List<EndpointEntity> endpointEntities = BundleParser.parse(Endpoint.class, bundle, (endpoint) -> converter.fromFHIR(EndpointEntity.class, endpoint), ORGANIZATION_ID);
        final List<OrganizationEntity> organizationEntities = BundleParser.parse(Organization.class, bundle, (org) -> converter.fromFHIR(OrganizationEntity.class, org), ORGANIZATION_ID);
        organizationEntities.stream().map(entity -> organizationEntityToRecord(context, entity)).forEach(context::executeInsert);
        endpointEntities.stream().map(entity -> endpointsEntityToRecord(context, entity)).forEach(context::executeInsert);
    }
}
Also used : FHIREntityConverter(gov.cms.dpc.fhir.converters.FHIREntityConverter) java.util(java.util) RosterUtils(gov.cms.dpc.attribution.jdbi.RosterUtils) DSL(org.jooq.impl.DSL) Connection(java.sql.Connection) LoggerFactory(org.slf4j.LoggerFactory) PatientsRecord(gov.cms.dpc.attribution.dao.tables.records.PatientsRecord) FhirContext(ca.uhn.fhir.context.FhirContext) Namespace(net.sourceforge.argparse4j.inf.Namespace) org.hl7.fhir.dstu3.model(org.hl7.fhir.dstu3.model) DSLContext(org.jooq.DSLContext) ProvidersRecord(gov.cms.dpc.attribution.dao.tables.records.ProvidersRecord) ZoneOffset(java.time.ZoneOffset) OrganizationEndpoints(gov.cms.dpc.attribution.dao.tables.OrganizationEndpoints) DPCAttributionConfiguration(gov.cms.dpc.attribution.DPCAttributionConfiguration) IParser(ca.uhn.fhir.parser.IParser) Environment(io.dropwizard.setup.Environment) OrganizationEndpointsRecord(gov.cms.dpc.attribution.dao.tables.records.OrganizationEndpointsRecord) Application(io.dropwizard.Application) EnvironmentCommand(io.dropwizard.cli.EnvironmentCommand) Logger(org.slf4j.Logger) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Subparser(net.sourceforge.argparse4j.inf.Subparser) Settings(org.jooq.conf.Settings) IOException(java.io.IOException) Patients(gov.cms.dpc.attribution.dao.tables.Patients) PooledDataSourceFactory(io.dropwizard.db.PooledDataSourceFactory) RenderQuotedNames(org.jooq.conf.RenderQuotedNames) Providers(gov.cms.dpc.attribution.dao.tables.Providers) OffsetDateTime(java.time.OffsetDateTime) Organizations(gov.cms.dpc.attribution.dao.tables.Organizations) OrganizationsRecord(gov.cms.dpc.attribution.dao.tables.records.OrganizationsRecord) gov.cms.dpc.common.entities(gov.cms.dpc.common.entities) DBUtils(gov.cms.dpc.attribution.utils.DBUtils) SeedProcessor(gov.cms.dpc.common.utils.SeedProcessor) InputStream(java.io.InputStream) InputStream(java.io.InputStream)

Example 48 with Endpoint

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

the class EndpointResource method createEndpoint.

@POST
@FHIR
@Timed
@ExceptionMetered
@Authorizer
@ApiOperation(value = "Create an Endpoint", notes = "Create an Endpoint resource for an Organization")
@ApiResponses(value = { @ApiResponse(code = 204, message = "Endpoint created"), @ApiResponse(code = 400, message = "Bad request"), @ApiResponse(code = 422, message = "Endpoint not valid") })
@Override
public Response createEndpoint(@ApiParam(hidden = true) @Auth OrganizationPrincipal organizationPrincipal, @ApiParam @Valid @Profiled(profile = EndpointProfile.PROFILE_URI) Endpoint endpoint) {
    Reference organizationPrincipalRef = new Reference(new IdType("Organization", organizationPrincipal.getID().toString()));
    if (endpoint.hasManagingOrganization() && !endpoint.getManagingOrganization().getReference().equals(organizationPrincipalRef.getReference())) {
        throw new WebApplicationException("An Endpoint cannot be created for a different Organization", HttpStatus.UNPROCESSABLE_ENTITY_422);
    }
    endpoint.setManagingOrganization(new Reference(new IdType("Organization", organizationPrincipal.getID().toString())));
    MethodOutcome outcome = this.client.create().resource(endpoint).encodedJson().execute();
    return FHIRHelpers.handleMethodOutcome(outcome);
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) IdType(org.hl7.fhir.dstu3.model.IdType) Timed(com.codahale.metrics.annotation.Timed) PathAuthorizer(gov.cms.dpc.api.auth.annotations.PathAuthorizer) Authorizer(gov.cms.dpc.api.auth.annotations.Authorizer) FHIR(gov.cms.dpc.fhir.annotations.FHIR) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 49 with Endpoint

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

the class EndpointResourceTest method testFetchEndpoint.

@Test
void testFetchEndpoint() {
    Organization organization = OrganizationHelpers.createOrganization(ctx, client, "1111111310", false);
    String endpointId = FHIRExtractors.getEntityUUID(organization.getEndpointFirstRep().getReference()).toString();
    Endpoint result = client.read().resource(Endpoint.class).withId(endpointId).execute();
    assertNotNull(result);
}
Also used : Organization(org.hl7.fhir.dstu3.model.Organization) Endpoint(org.hl7.fhir.dstu3.model.Endpoint) AbstractAttributionTest(gov.cms.dpc.attribution.AbstractAttributionTest) Test(org.junit.jupiter.api.Test) IntegrationTest(gov.cms.dpc.testing.IntegrationTest)

Example 50 with Endpoint

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

the class EndpointResourceTest method testDeleteEndpoint.

@Test
void testDeleteEndpoint() {
    Organization organization = OrganizationHelpers.createOrganization(ctx, client, "1112111111", false);
    String endpointId = FHIRExtractors.getEntityUUID(organization.getEndpointFirstRep().getReference()).toString();
    // Add another endpoint to organization
    client.create().resource(OrganizationFactory.createValidFakeEndpoint(organization.getId())).execute();
    // Delete original endpoint
    client.delete().resourceById("Endpoint", endpointId).execute();
    IReadExecutable readExec = client.read().resource(Endpoint.class).withId(endpointId);
    assertThrows(ResourceNotFoundException.class, readExec::execute);
}
Also used : IReadExecutable(ca.uhn.fhir.rest.gclient.IReadExecutable) Organization(org.hl7.fhir.dstu3.model.Organization) Endpoint(org.hl7.fhir.dstu3.model.Endpoint) AbstractAttributionTest(gov.cms.dpc.attribution.AbstractAttributionTest) Test(org.junit.jupiter.api.Test) IntegrationTest(gov.cms.dpc.testing.IntegrationTest)

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