Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,13 @@
import ca.uhn.fhir.util.IMetaTagSorter;
import ca.uhn.fhir.util.MetaTagSorterAlphabetical;
import ca.uhn.hapi.converters.canonical.VersionCanonicalizer;
import ca.uhn.fhir.jpa.model.entity.MbInstalledStructureDefinitionEntity;
import ca.uhn.fhir.jpa.dao.data.MbInstalledStructureDefinitionRepository;
import jakarta.annotation.Nullable;
import org.hl7.fhir.common.hapi.validation.support.UnknownCodeSystemWarningValidationSupport;
import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain;
import org.hl7.fhir.utilities.graphql.IGraphQLStorageServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand All @@ -216,7 +218,7 @@
@Configuration
// repositoryFactoryBeanClass: EnversRevisionRepositoryFactoryBean is needed primarily for unit testing
@EnableJpaRepositories(
basePackages = "ca.uhn.fhir.jpa.dao.data",
basePackages = {"ca.uhn.fhir.jpa.dao.data",},
repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class)
@Import({
BeanPostProcessorConfig.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ca.uhn.fhir.jpa.dao.data;

import ca.uhn.fhir.jpa.model.entity.MbInstalledStructureDefinitionEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface MbInstalledStructureDefinitionRepository
extends JpaRepository<MbInstalledStructureDefinitionEntity, Long> {

@Query("SELECT e FROM MbInstalledStructureDefinitionEntity e WHERE e.isValidatable = TRUE")
List<MbInstalledStructureDefinitionEntity> findAllValidatable();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
package ca.uhn.fhir.jpa.model.entity;

import jakarta.persistence.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.io.Serializable;
import java.util.Objects;

/**
* This table contains the list of StructureDefinitions currently installed in Matchbox.
*/
@Entity()
@Table(
name = "MB_INSTALLED_STRUCT_DEF",
indexes = {
@Index(name = "IDX_IS_VALIDATABLE", columnList = "IS_VALIDATABLE"),
})
public class MbInstalledStructureDefinitionEntity implements Serializable {

/**
* A primary key for the table.
*/
@Id
@SequenceGenerator(name = "SEQ_MB_INSTSTRUCTDEF", sequenceName = "SEQ_MB_INSTSTRUCTDEF")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_MB_INSTSTRUCTDEF")
@Column(name = "PID")
private Long id;

/**
* StructureDefinition.url
*/
@Column(name = "CANONICAL_URL", length = 200, nullable = false)
private String canonicalUrl;

/**
* StructureDefinition.title or StructureDefinition.name
*/
@Column(name = "TITLE", length = 200, nullable = false)
private String title;

/**
* ImplementationGuide.packageId
*/
@Column(name = "PACKAGE_ID", length = 200, nullable = false)
private String packageId;

/**
* ImplementationGuide.version
*/
@Column(name = "PACKAGE_VERSION", length = 200, nullable = false)
private String packageVersion;

/**
* StructureDefinition.type
*/
@Column(name = "TYPE", length = 100, nullable = false)
private String type;

/**
* StructureDefinition.kind: primitive-type | complex-type | resource | logical
*/
@Column(name = "KIND", length = 20, nullable = false)
private String kind;

/**
* Whether the package version is the current one (i.e. the most recent one) or not.
*/
@Column(name = "IS_CURRENT", nullable = false)
private Boolean isCurrent;

/**
* Whether that StructureDefinition can be used for validation or not.
*/
@Column(name = "IS_VALIDATABLE", nullable = false)
private Boolean isValidatable;

/**
* We keep a link to the original entity and cascade changes.
* Like that, if it gets removed, this entity will also be removed.
*/
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "NPM_PACKAGE_VER_RES_ID", referencedColumnName = "PID")
@OnDelete(action = OnDeleteAction.CASCADE)
private NpmPackageVersionResourceEntity npmPackageVersionResourceEntity;

public Long getId() {
return this.id;
}

public void setId(final Long id) {
this.id = id;
}

public String getCanonicalUrl() {
return this.canonicalUrl;
}

public void setCanonicalUrl(final String canonicalUrl) {
this.canonicalUrl = canonicalUrl;
}

public String getTitle() {
return this.title;
}

public void setTitle(final String title) {
this.title = title;
}

public String getPackageId() {
return this.packageId;
}

public void setPackageId(final String packageId) {
this.packageId = packageId;
}

public String getPackageVersion() {
return this.packageVersion;
}

public void setPackageVersion(final String packageVersion) {
this.packageVersion = packageVersion;
}

public String getType() {
return this.type;
}

public void setType(final String type) {
this.type = type;
}

public String getKind() {
return this.kind;
}

public void setKind(final String kind) {
this.kind = kind;
}

public Boolean isCurrent() {
return this.isCurrent;
}

public void setCurrent(final Boolean current) {
isCurrent = current;
}

public Boolean isValidatable() {
return this.isValidatable;
}

public void setValidatable(final Boolean validatable) {
isValidatable = validatable;
}

public void setNpmPackageVersionResourceEntity(final NpmPackageVersionResourceEntity npmPackageVersionResourceEntity) {
this.npmPackageVersionResourceEntity = npmPackageVersionResourceEntity;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof final MbInstalledStructureDefinitionEntity that)) return false;
return id.equals(that.id)
&& canonicalUrl.equals(that.canonicalUrl)
&& title.equals(that.title)
&& packageId.equals(that.packageId)
&& packageVersion.equals(that.packageVersion)
&& type.equals(that.type)
&& kind.equals(that.kind)
&& isCurrent.equals(that.isCurrent)
&& isValidatable.equals(that.isValidatable);
}

@Override
public int hashCode() {
return Objects.hash(id, canonicalUrl, title, packageId, packageVersion, type, kind, isCurrent, isValidatable);
}

@Override
public String toString() {
return "MbInstalledStructureDefinitionEntity{" +
"id=" + id +
", canonicalUrl='" + canonicalUrl + '\'' +
", title='" + title + '\'' +
", packageId='" + packageId + '\'' +
", packageVersion='" + packageVersion + '\'' +
", type='" + type + '\'' +
", kind='" + kind + '\'' +
", isCurrent=" + isCurrent +
", isValidatable=" + isValidatable +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public class JpaPackageCache extends BasePackageCacheManager implements IHapiPac

@Autowired(required = false) // It is possible that some implementers will not create such a bean.
private IBinaryStorageSvc myBinaryStorageSvc;

@Autowired
private MatchboxJpaPackageCache matchboxJpaPackageCache;

@Override
public void addPackageServer(@Nonnull PackageServer thePackageServer) {
Expand Down Expand Up @@ -416,7 +419,7 @@ private NpmPackage addPackageToCacheInternal(NpmPackageData thePackageData) {
resourceEntity.setCanonicalVersion(version);
}
// PATCH MATCHBOX: the next line is our customization hook: https://github.com/ahdis/matchbox/issues/341
MatchboxJpaPackageCache.customizeNpmPackageVersionResourceEntity(resourceEntity, resource);
matchboxJpaPackageCache.interceptEntityBeforeSaving(resourceEntity, resource);
myPackageVersionResourceDao.save(resourceEntity);

String resType = packageContext.getResourceType(resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Import;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import ca.uhn.fhir.jpa.config.JpaConfig;
import ch.ahdis.matchbox.CliContext;
import ch.ahdis.matchbox.interceptors.*;
import ch.ahdis.matchbox.packages.MatchboxJpaPackageCache;
import ca.uhn.fhir.jpa.dao.data.MbInstalledStructureDefinitionRepository;
import ch.ahdis.matchbox.mappinglanguage.StructureMapListProvider;
import ch.ahdis.matchbox.packages.*;
import ch.ahdis.matchbox.providers.*;
Expand Down Expand Up @@ -66,7 +68,6 @@
import ca.uhn.fhir.jpa.searchparam.MatchUrlService;
import ca.uhn.fhir.jpa.starter.AppProperties;
import ca.uhn.fhir.jpa.starter.common.StarterJpaConfig;
import ca.uhn.fhir.jpa.validation.JpaValidationSupportChain;
import ca.uhn.fhir.mdm.provider.MdmProviderLoader;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
Expand Down Expand Up @@ -166,6 +167,9 @@ public class MatchboxJpaConfig extends StarterJpaConfig {
@Autowired
private ValueSetCodeValidationProvider valueSetCodeValidationProvider;

@Autowired
private MbInstalledStructureDefinitionRepository installedStructureDefinitionRepository;

// removed GraphQlProvider
// removed IVAldiationSupport

Expand Down Expand Up @@ -246,7 +250,11 @@ public RestfulServer restfulServer(IFhirSystemDao<?, ?> fhirSystemDao, AppProper
"implementationGuideResourceProvider");
}

fhirServer.setServerConformanceProvider(new MatchboxCapabilityStatementProvider(this.myFhirContext,fhirServer, structureDefinitionProvider, getCliContext()));
fhirServer.setServerConformanceProvider(new MatchboxCapabilityStatementProvider(this.myFhirContext,
fhirServer,
this.structureDefinitionProvider,
getCliContext(),
this.installedStructureDefinitionRepository));

return fhirServer;
}
Expand Down Expand Up @@ -421,4 +429,9 @@ public IJobPersistence batch2JobInstancePersister(
public InstallNpmPackageProvider installNpmPackageOperationProvider(final MatchboxPackageInstallerImpl packageInstallerSvc) {
return new InstallNpmPackageProvider(packageInstallerSvc);
}

@Bean
public MatchboxJpaPackageCache matchboxJpaPackageCache(final MbInstalledStructureDefinitionRepository installedStructureDefinitionRepository) {
return new MatchboxJpaPackageCache(installedStructureDefinitionRepository);
}
}
Loading