Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/rev_include' also closes #73
Browse files Browse the repository at this point in the history
  • Loading branch information
hhund committed Feb 10, 2020
2 parents 80be84b + 4fd7fc8 commit 9e6b659
Show file tree
Hide file tree
Showing 39 changed files with 724 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.highmed.dsf.fhir.search.SearchQuery;
import org.highmed.dsf.fhir.search.SearchQuery.SearchQueryBuilder;
import org.highmed.dsf.fhir.search.SearchQueryParameter;
import org.highmed.dsf.fhir.search.SearchQueryRevIncludeParameterFactory;
import org.highmed.dsf.fhir.search.parameters.ResourceId;
import org.highmed.dsf.fhir.search.parameters.ResourceLastUpdated;
import org.hl7.fhir.instance.model.api.IBaseResource;
Expand Down Expand Up @@ -106,33 +107,40 @@ public Resource getResource()
private final String resourceColumn;
private final String resourceIdColumn;

private final List<Supplier<SearchQueryParameter<R>>> searchParameterFactories;
private final List<Supplier<SearchQueryParameter<R>>> searchParameterFactories = new ArrayList<>();
private final List<Supplier<SearchQueryRevIncludeParameterFactory>> searchRevIncludeParameterFactories = new ArrayList<>();

private final PreparedStatementFactory<R> preparedStatementFactory;

@SafeVarargs
protected static <T> List<T> with(T... t)
{
return Arrays.asList(t);
}

/*
* Using a suppliers for SearchParameters, implementations are not thread safe and because of that they need to be
* created on a request basis
*/
@SafeVarargs
AbstractResourceDaoJdbc(DataSource dataSource, FhirContext fhirContext, Class<R> resourceType, String resourceTable,
String resourceColumn, String resourceIdColumn,
Supplier<SearchQueryParameter<R>>... searchParameterFactories)
List<Supplier<SearchQueryParameter<R>>> searchParameterFactories,
List<Supplier<SearchQueryRevIncludeParameterFactory>> searchRevIncludeParameterFactories)
{
this(dataSource, fhirContext, resourceType, resourceTable, resourceColumn, resourceIdColumn,
new PreparedStatementFactoryDefault<>(fhirContext, resourceType, resourceTable, resourceIdColumn,
resourceColumn),
searchParameterFactories);
searchParameterFactories, searchRevIncludeParameterFactories);
}

/*
* Using a suppliers for SearchParameters, implementations are not thread safe and because of that they need to be
* created on a request basis
*/
@SafeVarargs
AbstractResourceDaoJdbc(DataSource dataSource, FhirContext fhirContext, Class<R> resourceType, String resourceTable,
String resourceColumn, String resourceIdColumn, PreparedStatementFactory<R> preparedStatementFactory,
Supplier<SearchQueryParameter<R>>... searchParameterFactories)
List<Supplier<SearchQueryParameter<R>>> searchParameterFactories,
List<Supplier<SearchQueryRevIncludeParameterFactory>> searchRevIncludeParameterFactories)
{
this.dataSource = dataSource;
this.fhirContext = fhirContext;
Expand All @@ -145,7 +153,10 @@ public Resource getResource()

this.preparedStatementFactory = preparedStatementFactory;

this.searchParameterFactories = Arrays.asList(searchParameterFactories);
if (searchParameterFactories != null)
this.searchParameterFactories.addAll(searchParameterFactories);
if (searchRevIncludeParameterFactories != null)
this.searchRevIncludeParameterFactories.addAll(searchRevIncludeParameterFactories);
}

@Override
Expand Down Expand Up @@ -789,7 +800,7 @@ public PartialResult<R> searchWithTransaction(Connection connection, DbSearchQue

List<R> partialResult = new ArrayList<>();
List<Resource> includes = new ArrayList<>();

if (!query.isCountOnly(overallCount)) // TODO ask db if count 0
{
try (PreparedStatement statement = connection.prepareStatement(query.getSearchSql()))
Expand Down Expand Up @@ -868,6 +879,8 @@ public final SearchQuery<R> createSearchQuery(int page, int count)
return SearchQueryBuilder.create(resourceType, getResourceTable(), getResourceColumn(), page, count)
.with(new ResourceId(getResourceIdColumn()), new ResourceLastUpdated(getResourceColumn()))
.with(searchParameterFactories.stream().map(Supplier::get).toArray(SearchQueryParameter[]::new))
.withRevInclude(searchRevIncludeParameterFactories.stream().map(Supplier::get)
.toArray(SearchQueryRevIncludeParameterFactory[]::new))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public AbstractStructureDefinitionDaoJdbc(BasicDataSource dataSource, FhirContex
String resourceColumn, String resourceIdColumn)
{
super(dataSource, fhirContext, StructureDefinition.class, resourceTable, resourceColumn, resourceIdColumn,
() -> new StructureDefinitionIdentifier(resourceColumn),
() -> new StructureDefinitionUrl(resourceColumn), () -> new StructureDefinitionVersion(resourceColumn));
with(() -> new StructureDefinitionIdentifier(resourceColumn),
() -> new StructureDefinitionUrl(resourceColumn),
() -> new StructureDefinitionVersion(resourceColumn)),
with());

readByUrl = new ReadByUrlDaoJdbc<StructureDefinition>(this::getDataSource, this::getResource, resourceTable,
resourceColumn, resourceIdColumn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BinaryDaoJdbc extends AbstractResourceDaoJdbc<Binary> implements Bi
public BinaryDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, Binary.class, "binaries", "binary_json", "binary_id",
new PreparedStatementFactoryBinary(fhirContext), BinaryContentType::new);
new PreparedStatementFactoryBinary(fhirContext), with(BinaryContentType::new), with());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class BundleDaoJdbc extends AbstractResourceDaoJdbc<Bundle> implements Bu
{
public BundleDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, Bundle.class, "bundles", "bundle", "bundle_id", BundleIdentifier::new);
super(dataSource, fhirContext, Bundle.class, "bundles", "bundle", "bundle_id", with(BundleIdentifier::new),
with());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class CodeSystemDaoJdbc extends AbstractResourceDaoJdbc<CodeSystem> imple
public CodeSystemDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, CodeSystem.class, "code_systems", "code_system", "code_system_id",
CodeSystemUrl::new, CodeSystemVersion::new, CodeSystemIdentifier::new);
with(CodeSystemUrl::new, CodeSystemVersion::new, CodeSystemIdentifier::new), with());

readByUrl = new ReadByUrlDaoJdbc<>(this::getDataSource, this::getResource, getResourceTable(), getResourceColumn(),
getResourceIdColumn());
readByUrl = new ReadByUrlDaoJdbc<>(this::getDataSource, this::getResource, getResourceTable(),
getResourceColumn(), getResourceIdColumn());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.highmed.dsf.fhir.search.parameters.EndpointName;
import org.highmed.dsf.fhir.search.parameters.EndpointOrganization;
import org.highmed.dsf.fhir.search.parameters.EndpointStatus;
import org.highmed.dsf.fhir.search.parameters.rev.include.OrganizationEndpointRevInclude;
import org.hl7.fhir.r4.model.Endpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -24,7 +25,8 @@ public class EndpointDaoJdbc extends AbstractResourceDaoJdbc<Endpoint> implement
public EndpointDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, Endpoint.class, "endpoints", "endpoint", "endpoint_id",
EndpointOrganization::new, EndpointIdentifier::new, EndpointName::new, EndpointStatus::new);
with(EndpointOrganization::new, EndpointIdentifier::new, EndpointName::new, EndpointStatus::new),
with(OrganizationEndpointRevInclude::new));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.apache.commons.dbcp2.BasicDataSource;
import org.highmed.dsf.fhir.dao.GroupDao;
import org.highmed.dsf.fhir.search.parameters.rev.include.ResearchStudyEnrollmentRevInclude;
import org.hl7.fhir.r4.model.Group;

import ca.uhn.fhir.context.FhirContext;
Expand All @@ -10,7 +11,8 @@ public class GroupDaoJdbc extends AbstractResourceDaoJdbc<Group> implements Grou
{
public GroupDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, Group.class, "groups", "group_json", "group_id");
super(dataSource, fhirContext, Group.class, "groups", "group_json", "group_id", with(),
with(ResearchStudyEnrollmentRevInclude::new));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

import ca.uhn.fhir.context.FhirContext;

public class HealthcareServiceDaoJdbc extends AbstractResourceDaoJdbc<HealthcareService>
implements HealthcareServiceDao
public class HealthcareServiceDaoJdbc extends AbstractResourceDaoJdbc<HealthcareService> implements HealthcareServiceDao
{
public HealthcareServiceDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, HealthcareService.class, "healthcare_services", "healthcare_service",
"healthcare_service_id", HealthcareServiceIdentifier::new, HealthcareServiceActive::new);
"healthcare_service_id", with(HealthcareServiceIdentifier::new, HealthcareServiceActive::new), with());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class LocationDaoJdbc extends AbstractResourceDaoJdbc<Location> implement
{
public LocationDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, Location.class, "locations", "location", "location_id", LocationIdentifier::new);
super(dataSource, fhirContext, Location.class, "locations", "location", "location_id",
with(LocationIdentifier::new), with());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class NamingSystemDaoJdbc extends AbstractResourceDaoJdbc<NamingSystem> i
public NamingSystemDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, NamingSystem.class, "naming_systems", "naming_system", "naming_system_id",
NamingSystemName::new);
with(NamingSystemName::new), with());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.highmed.dsf.fhir.search.parameters.OrganizationIdentifier;
import org.highmed.dsf.fhir.search.parameters.OrganizationName;
import org.highmed.dsf.fhir.search.parameters.OrganizationType;
import org.highmed.dsf.fhir.search.parameters.rev.include.EndpointOrganizationRevInclude;
import org.hl7.fhir.r4.model.Organization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -26,7 +27,9 @@ public class OrganizationDaoJdbc extends AbstractResourceDaoJdbc<Organization> i
public OrganizationDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, Organization.class, "organizations", "organization", "organization_id",
OrganizationName::new, OrganizationEndpoint::new, OrganizationIdentifier::new, OrganizationActive::new, OrganizationType::new);
with(OrganizationName::new, OrganizationEndpoint::new, OrganizationIdentifier::new,
OrganizationActive::new, OrganizationType::new),
with(EndpointOrganizationRevInclude::new));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class PatientDaoJdbc extends AbstractResourceDaoJdbc<Patient> implements
{
public PatientDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, Patient.class, "patients", "patient", "patient_id", PatientIdentifier::new,
PatientActive::new);
super(dataSource, fhirContext, Patient.class, "patients", "patient", "patient_id",
with(PatientIdentifier::new, PatientActive::new), with());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PractitionerDaoJdbc extends AbstractResourceDaoJdbc<Practitioner> i
public PractitionerDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, Practitioner.class, "practitioners", "practitioner", "practitioner_id",
PractitionerIdentifier::new, PractitionerActive::new);
with(PractitionerIdentifier::new, PractitionerActive::new), with());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

import ca.uhn.fhir.context.FhirContext;

public class PractitionerRoleDaoJdbc extends AbstractResourceDaoJdbc<PractitionerRole>
implements PractitionerRoleDao
public class PractitionerRoleDaoJdbc extends AbstractResourceDaoJdbc<PractitionerRole> implements PractitionerRoleDao
{
public PractitionerRoleDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, PractitionerRole.class, "practitioner_roles", "practitioner_role",
"practitioner_role_id", PractitionerRoleIdentifier::new, PractitionerRoleActive::new);
"practitioner_role_id", with(PractitionerRoleIdentifier::new, PractitionerRoleActive::new), with());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ProvenanceDaoJdbc extends AbstractResourceDaoJdbc<Provenance> imple
{
public ProvenanceDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, Provenance.class, "provenances", "provenance", "provenance_id");
super(dataSource, fhirContext, Provenance.class, "provenances", "provenance", "provenance_id", with(), with());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ResearchStudyDaoJdbc extends AbstractResourceDaoJdbc<ResearchStudy>
public ResearchStudyDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, ResearchStudy.class, "research_studies", "research_study", "research_study_id",
ResearchStudyIdentifier::new, ResearchStudyEnrollment::new);
with(ResearchStudyIdentifier::new, ResearchStudyEnrollment::new), with());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public class SubscriptionDaoJdbc extends AbstractResourceDaoJdbc<Subscription> i
public SubscriptionDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, Subscription.class, "subscriptions", "subscription", "subscription_id",
SubscriptionCriteria::new, SubscriptionStatus::new, SubscriptionChannelType::new,
SubscriptionChannelPayload::new);
with(SubscriptionCriteria::new, SubscriptionStatus::new, SubscriptionChannelType::new,
SubscriptionChannelPayload::new),
with());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class TaskDaoJdbc extends AbstractResourceDaoJdbc<Task> implements TaskDa
{
public TaskDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, Task.class, "tasks", "task", "task_id", TaskIdentifier::new, TaskRequester::new,
TaskStatus::new);
super(dataSource, fhirContext, Task.class, "tasks", "task", "task_id",
with(TaskIdentifier::new, TaskRequester::new, TaskStatus::new), with());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class ValueSetDaoJdbc extends AbstractResourceDaoJdbc<ValueSet> implement
public ValueSetDaoJdbc(BasicDataSource dataSource, FhirContext fhirContext)
{
super(dataSource, fhirContext, ValueSet.class, "value_sets", "value_set", "value_set_id",
ValueSetIdentifier::new, ValueSetUrl::new, ValueSetVersion::new);
with(ValueSetIdentifier::new, ValueSetUrl::new, ValueSetVersion::new), with());

readByUrl = new ReadByUrlDaoJdbc<>(this::getDataSource, this::getResource, getResourceTable(), getResourceColumn(),
getResourceIdColumn());
readByUrl = new ReadByUrlDaoJdbc<>(this::getDataSource, this::getResource, getResourceTable(),
getResourceColumn(), getResourceIdColumn());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.highmed.dsf.fhir.function;

import java.sql.SQLException;
import java.util.Objects;

@FunctionalInterface
public interface BiConsumerWithSqlException<T, U>
{
void accept(T t, U u) throws SQLException;

default BiConsumerWithSqlException<T, U> andThen(BiConsumerWithSqlException<? super T, ? super U> after)
{
Objects.requireNonNull(after);
return (T t, U u) ->
{
SQLException suppressed = null;
try
{
accept(t, u);
}
catch (SQLException e)
{
suppressed = e;
}
finally
{
try
{
after.accept(t, u);
}
catch (SQLException e)
{
if (suppressed != null)
e.addSuppressed(suppressed);
throw e;
}
}
};
}
}
Loading

0 comments on commit 9e6b659

Please sign in to comment.