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));
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations