Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Me/dpc 4324 hapi jpa eval #2339

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
db:
ports:
Expand All @@ -12,9 +10,6 @@ services:
aggregation:
ports:
- "5006:5005"
attribution:
ports:
- "5007:5005"
consent:
ports:
- "5008:5005"
40 changes: 21 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
image: postgres:14
command: postgres -c 'max_connections=250'
environment:
- POSTGRES_MULTIPLE_DATABASES=dpc_attribution,dpc_queue,dpc_auth,dpc_consent,dpc-website_development,bcda,dpc-portal_development
- POSTGRES_MULTIPLE_DATABASES=dpc_queue,dpc_auth,dpc_consent,dpc-website_development,bcda,dpc-portal_development,hapi
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=dpc-safe
volumes:
Expand Down Expand Up @@ -33,20 +33,6 @@ services:
- export-volume:/app/data
- ./jacocoReport/dpc-aggregation:/jacoco-report

attribution:
image: ${ECR_HOST:-755619740999.dkr.ecr.us-east-1.amazonaws.com/dpc-attribution}:latest
depends_on:
- db
environment:
- ENV=local
- JACOCO=${REPORT_COVERAGE}
- DEBUG_MODE=${DEBUG_MODE:-false}
ports:
- "3500:8080"
- "9902:9902"
volumes:
- ./jacocoReport/dpc-attribution:/jacoco-report

api:
image: ${ECR_HOST:-755619740999.dkr.ecr.us-east-1.amazonaws.com/dpc-api}:latest
ports:
Expand All @@ -58,10 +44,11 @@ services:
- ENV=local
- JACOCO=${REPORT_COVERAGE}
- EXPORT_PATH=/app/data
- AUTH_DISABLED=${AUTH_DISABLED:-false}
#- AUTH_DISABLED=${AUTH_DISABLED:-false}
- AUTH_DISABLED=true
- DEBUG_MODE=${DEBUG_MODE:-false}
depends_on:
- attribution
- fhir
volumes:
- export-volume:/app/data
- ./jacocoReport/dpc-api:/jacoco-report
Expand Down Expand Up @@ -89,9 +76,10 @@ services:
start_api_dependencies:
image: dadarek/wait-for-dependencies
depends_on:
- attribution
#- attribution
- fhir
- aggregation
command: attribution:8080 aggregation:9901
command: fhir:8080 aggregation:9901

start_api:
image: dadarek/wait-for-dependencies
Expand All @@ -116,6 +104,20 @@ services:
command: sh -c "mvn test -Pintegration-tests -am -ntp"
network_mode: host

fhir:
image: "hapiproject/hapi:latest"
ports:
- "8080:8080"
configs:
- source: hapi
target: /app/config/application.yaml
depends_on:
- db

configs:
hapi:
file: ./hapi.application.yaml

volumes:
pgdata14:
export-volume:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import gov.cms.dpc.aggregation.service.*;
import gov.cms.dpc.common.annotations.ExportPath;
import gov.cms.dpc.common.annotations.JobTimeout;
import gov.cms.dpc.common.hibernate.attribution.DPCManagedSessionFactory;
import gov.cms.dpc.fhir.configuration.FHIRClientConfiguration;
import gov.cms.dpc.fhir.hapi.ContextUtils;
import gov.cms.dpc.queue.models.JobQueueBatch;
Expand Down Expand Up @@ -114,7 +113,7 @@ public int provideJobTimeoutInSeconds() {
}

@Provides
LookBackService provideLookBackService(DPCManagedSessionFactory sessionFactory, OperationsConfig operationsConfig) {
LookBackService provideLookBackService(OperationsConfig operationsConfig) {
//Configuring to skip look back when look back months is less than 0
if (operationsConfig.getLookBackMonths() < 0) {
return new EveryoneGetsDataLookBackServiceImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import gov.cms.dpc.bluebutton.config.BBClientConfiguration;
import gov.cms.dpc.bluebutton.config.BlueButtonBundleConfiguration;
import gov.cms.dpc.common.hibernate.attribution.IDPCDatabase;
import gov.cms.dpc.common.hibernate.queue.IDPCQueueDatabase;
import gov.cms.dpc.fhir.configuration.FHIRClientConfiguration;
import gov.cms.dpc.queue.config.DPCAwsQueueConfiguration;
Expand All @@ -20,13 +19,7 @@
import java.time.ZoneId;
import java.util.List;

public class DPCAggregationConfiguration extends Configuration implements BlueButtonBundleConfiguration, IDPCDatabase, IDPCQueueDatabase, DPCQueueConfig {

@Valid
@NotNull
@JsonProperty("database")
private final DataSourceFactory database = new DataSourceFactory();

public class DPCAggregationConfiguration extends Configuration implements BlueButtonBundleConfiguration, IDPCQueueDatabase, DPCQueueConfig {
@Valid
@NotNull
@JsonProperty("queuedb")
Expand Down Expand Up @@ -81,11 +74,6 @@ public class DPCAggregationConfiguration extends Configuration implements BlueBu
@NotNull
private final YearMonth lookBackDate = YearMonth.now(ZoneId.systemDefault());

@Override
public DataSourceFactory getDatabase() {
return this.database;
}

@Override
public DataSourceFactory getQueueDatabase() {
return queueDatabase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.squarespace.jersey2.guice.JerseyGuiceUtils;
import gov.cms.dpc.bluebutton.BlueButtonClientModule;
import gov.cms.dpc.common.hibernate.attribution.DPCHibernateBundle;
import gov.cms.dpc.common.hibernate.attribution.DPCHibernateModule;
import gov.cms.dpc.common.hibernate.queue.DPCQueueHibernateBundle;
import gov.cms.dpc.common.hibernate.queue.DPCQueueHibernateModule;
import gov.cms.dpc.common.utils.EnvironmentParser;
Expand All @@ -21,7 +19,6 @@
public class DPCAggregationService extends Application<DPCAggregationConfiguration> {

private final DPCQueueHibernateBundle<DPCAggregationConfiguration> queueHibernateBundle = new DPCQueueHibernateBundle<>();
private final DPCHibernateBundle<DPCAggregationConfiguration> hibernateBundle = new DPCHibernateBundle<>();

public static void main(final String[] args) throws Exception {
new DPCAggregationService().run(args);
Expand All @@ -45,7 +42,7 @@ public void initialize(Bootstrap<DPCAggregationConfiguration> bootstrap) {
GuiceBundle guiceBundle = GuiceBundle.builder()
.modules(new AggregationAppModule(),
new DPCQueueHibernateModule<>(queueHibernateBundle),
new DPCHibernateModule<>(hibernateBundle),
//new DPCHibernateModule<>(hibernateBundle),
new JobQueueModule<DPCAggregationConfiguration>(),
new BlueButtonClientModule<DPCAggregationConfiguration>())
.build();
Expand All @@ -54,7 +51,6 @@ public void initialize(Bootstrap<DPCAggregationConfiguration> bootstrap) {
// The Hibernate Guice module requires an initialized SessionFactory,
// so Dropwizard needs to initialize the HibernateBundle first to create the SessionFactory.
bootstrap.addBundle(queueHibernateBundle);
bootstrap.addBundle(hibernateBundle);

bootstrap.addBundle(guiceBundle);
bootstrap.addBundle(new MigrationsBundle<>() {
Expand Down
12 changes: 0 additions & 12 deletions dpc-aggregation/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
database:
driverClass: org.postgresql.Driver
url: ${DATABASE_URL:-"jdbc:postgresql://db:5432/dpc_attribution"}
user: "${ATTRIBUTION_DB_USER:-postgres}"
password: "${ATTRIBUTION_DB_PASS:-dpc-safe}"
initialSize: 5
minSize: 5
maxSize: 10
properties:
charSet: UTF-8
hibernate.dialect: org.hibernate.dialect.PostgreSQL10Dialect

queuedb:
driverClass: org.postgresql.Driver
url: ${QUEUE_DB_URL:-"jdbc:postgresql://db:5432/dpc_queue"}
Expand Down
13 changes: 3 additions & 10 deletions dpc-api/src/main/java/gov/cms/dpc/api/APIHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,14 @@ public static <T extends BaseResource> Bundle bulkResourceClient(Class<T> clazz,
.getEntry()
.stream()
.filter(Bundle.BundleEntryComponent::hasResource)
.map(component -> component.setRequest(new Bundle.BundleEntryRequestComponent().setMethod(Bundle.HTTPVerb.POST)))
.map(Bundle.BundleEntryComponent::getResource)
.filter(resource -> resource.getClass().equals(clazz))
.map(clazz::cast)
.forEach(entryConsumer);
resourceBundle.setType(Bundle.BundleType.TRANSACTION);

final Parameters params = new Parameters();
params.addParameter().setResource(resourceBundle);
return client
.operation()
.onType(clazz)
.named("submit")
.withParameters(params)
.returnResourceType(Bundle.class)
.encodedJson()
.execute();
return client.transaction().withBundle(resourceBundle).execute();
}

public static String formatValidationMessages(List<SingleValidationMessage> messages) {
Expand Down
4 changes: 3 additions & 1 deletion dpc-api/src/main/java/gov/cms/dpc/api/DPCAPIModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ SessionFactory provideSessionFactory(DPCAuthManagedSessionFactory factory) {
@Singleton
@Named("fhirContextAttributionSTU3")
public FhirContext provideAttributionSTU3Context() {
return FhirContext.forDstu3();
FhirContext ctx = FhirContext.forDstu3();
ctx.getParserOptions().setOverrideResourceIdWithBundleEntryFullUrl(false);
return ctx;
}

@Provides
Expand Down
3 changes: 2 additions & 1 deletion dpc-api/src/main/java/gov/cms/dpc/api/DPCAPIService.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public void run(final DPCAPIConfiguration configuration,
environment.healthChecks().register("api-self-check",
new HttpHealthCheck(UrlGenerator.generateVersionUrl(configuration.getServicePort(), configuration.getAppContextPath()))
);
environment.healthChecks().register("dpc-attribution", new HttpHealthCheck(configuration.getAttributionHealthCheckURL()));
// TODO: Turned off for PoC since I don't want to create a healthcheck for the new FHIR server
//environment.healthChecks().register("dpc-attribution", new HttpHealthCheck(configuration.getAttributionHealthCheckURL()));
}

private GuiceBundle setupGuiceBundle() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,23 @@ public Optional<OrganizationPrincipal> authenticate(DPCAuthCredentials credentia
logger.debug("Looking up resource {} in path authorizer. With value: {}", credentials.getPathAuthorizer().type(), credentials.getPathAuthorizer().pathParam());
Map<String, List<String>> searchParams = new HashMap<>();
searchParams.put("_id", Collections.singletonList(credentials.getPathValue()));
searchParams.put("organization", Collections.singletonList(credentials.getOrganization().getId()));

// Special handling of Group resources, which use tags instead of resource properties.
// TODO: Remove with DPC-552
if (credentials.getPathAuthorizer().type() == DPCResourceType.Group) {
searchParams.put("_tag", Collections.singletonList(String.format("%s|%s", DPCIdentifierSystem.DPC.getSystem(), credentials.getOrganization().getId())));
var query = this.client
.search()
.forResource(credentials.getPathAuthorizer().type().toString())
.returnBundle(Bundle.class)
.encodedJson();

if ( List.of(DPCResourceType.Group, DPCResourceType.Practitioner).contains(credentials.getPathAuthorizer().type()) ) {
query.withTag(DPCIdentifierSystem.DPC.getSystem(), credentials.getOrganization().getIdPart());
} else {
searchParams.put("organization", Collections.singletonList(credentials.getOrganization().getId()));
}
final Bundle bundle = this.client
.search()
.forResource(credentials.getPathAuthorizer().type().toString())
.whereMap(searchParams)
.returnBundle(Bundle.class)
.encodedJson()
.execute();
final Bundle bundle = query.whereMap(searchParams).execute();

if (bundle.getTotal() == 0) {
return Optional.empty();
}

return Optional.of(principal);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package gov.cms.dpc.api.cli.organizations;

import ca.uhn.fhir.rest.api.CacheControlDirective;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.util.BundleBuilder;
import gov.cms.dpc.api.cli.AbstractAttributionCommand;
import io.dropwizard.core.setup.Bootstrap;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Endpoint;
import org.hl7.fhir.dstu3.model.IdType;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static gov.cms.dpc.fhir.helpers.FHIRHelpers.getPages;

public class OrganizationDelete extends AbstractAttributionCommand {

public OrganizationDelete() {
Expand All @@ -33,11 +44,27 @@ public void run(Bootstrap<?> bootstrap, Namespace namespace) {

final IGenericClient client = ctx.newRestfulGenericClient(attributionService);

client
.delete()
.resourceById(new IdType(orgReference))
.encodedJson()
.execute();
// The org and its endpoints must be deleted together since they reference each other
Map<String, List<String>> searchParams = new HashMap<>();
searchParams.put("organization", Collections.singletonList(orgReference));

Bundle endpointBundle = client
.search()
.forResource(Endpoint.class)
.encodedJson()
.returnBundle(Bundle.class)
.whereMap(searchParams)
.cacheControl(CacheControlDirective.noCache())
.execute();
endpointBundle = getPages(client, endpointBundle);

// Build a transaction for all of our deletes
BundleBuilder bundleBuilder = new BundleBuilder(client.getFhirContext());
bundleBuilder.addTransactionDeleteEntry(new IdType("Organization", orgReference));
endpointBundle.getEntry().stream()
.map(entry -> (Endpoint) entry.getResource())
.forEach(bundleBuilder::addTransactionDeleteEntry);
client.transaction().withBundle(bundleBuilder.getBundle()).execute();

System.out.println("Successfully deleted Organization");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package gov.cms.dpc.api.cli.organizations;

import ca.uhn.fhir.rest.api.CacheControlDirective;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import com.jakewharton.fliptables.FlipTable;
import gov.cms.dpc.api.cli.AbstractAttributionCommand;
import gov.cms.dpc.fhir.helpers.FHIRHelpers;
import io.dropwizard.core.setup.Bootstrap;
import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser;
Expand Down Expand Up @@ -36,7 +38,9 @@ public void run(Bootstrap<?> bootstrap, Namespace namespace) {
.forResource(Organization.class)
.encodedJson()
.returnBundle(Bundle.class)
.cacheControl(CacheControlDirective.noCache())
.execute();
FHIRHelpers.getPages(client, organizations);

// Generate the table
final String[] headers = {"ID", "NPI", "NAME"};
Expand Down
Loading
Loading