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

Temporal annual distribution functionality and temporal FeatureExtraction capability enablement #2388

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6dee88d
ATL-10 Robust characterization analysis module (Table and Listings)
wivern Feb 21, 2024
ce6d286
Fixes NPE
Apr 12, 2024
04cb846
To avoid NullPointerException when executing a Cohort Characterization
alex-odysseus Apr 15, 2024
25b8fdc
Merge branch 'ATL-10' of https://bitbucket.org/Odysseus/webapi into A…
alex-odysseus Apr 15, 2024
2029e69
Fixes characterization import
Apr 17, 2024
f131aeb
Fixes characterization create and copy
Apr 24, 2024
caa4628
Fixes potential NPE
Apr 27, 2024
43a72f1
Adds i18n for supports annual prevalence column
Apr 27, 2024
3d1fe59
Fixes FeAnalysis converter
May 3, 2024
1c3f040
Enables tempoeral CC results
May 28, 2024
abe7b7f
[ATL-10] Added an option to exclude creating comparative items for th…
Jul 11, 2024
d7c8d71
Merged in ATL-10-bugfixes (pull request #31)
Jul 18, 2024
d03fbd8
Fixing NullPointerException for the temporal Feature Analysis flag li…
alex-odysseus Jul 23, 2024
dfa53c1
Merge remote-tracking branch 'remotes/origin/ATL-10'
alex-odysseus Aug 28, 2024
674c03a
Referencing FeatureExtraction 3.7.0-SNAPSHOT where the temporal annua…
alex-odysseus Aug 28, 2024
9b64699
[ATL-10] Added an option to exclude creating comparative items for th…
oleg-odysseus Jul 11, 2024
6ddaaa6
Merged in ATL-10-bugfixes (pull request #31)
Jul 18, 2024
accf315
Fixing NullPointerException for the temporal Feature Analysis flag li…
alex-odysseus Jul 23, 2024
7f7f196
Fixed NullPointerException during saving of a cohort characterization…
oleg-odysseus Jul 23, 2024
b669f55
Merged in fixNPECharacterization (pull request #40)
Sep 4, 2024
cc39b3d
Merge remote-tracking branch 'remotes/origin/ATL-10' into temporal-an…
alex-odysseus Sep 6, 2024
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<shiro.version>1.12.0</shiro.version>
<dom4j.version>2.1.3</dom4j.version>
<hydra.version>0.4.0</hydra.version>
<featureExtraction.version>3.2.0</featureExtraction.version>
<featureExtraction.version>3.7.0-SNAPSHOT</featureExtraction.version>
<tomcat.embed.version>8.5.87</tomcat.embed.version>

<commons-fileupload.version>1.5</commons-fileupload.version>
Expand Down Expand Up @@ -1122,7 +1122,7 @@
<dependency>
<groupId>org.ohdsi</groupId>
<artifactId>SkeletonCohortCharacterization</artifactId>
<version>1.2.1</version>
<version>2.0.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.ohdsi</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.ohdsi.webapi.cohortcharacterization.dto.CcPrevalenceStat;
import org.ohdsi.webapi.cohortcharacterization.dto.CcResult;
import org.ohdsi.webapi.cohortcharacterization.dto.CcShortDTO;
import org.ohdsi.webapi.cohortcharacterization.dto.CcTemporalResult;
import org.ohdsi.webapi.cohortcharacterization.dto.CcVersionFullDTO;
import org.ohdsi.webapi.cohortcharacterization.dto.CohortCharacterizationDTO;
import org.ohdsi.webapi.cohortcharacterization.dto.ExportExecutionResultRequest;
Expand Down Expand Up @@ -257,7 +258,7 @@ public CohortCharacterizationDTO update(@PathParam("id") final Long id, final Co
final CohortCharacterizationEntity entity = conversionService.convert(dto, CohortCharacterizationEntity.class);
entity.setId(id);
final CohortCharacterizationEntity updatedEntity = service.updateCc(entity);
return conversionService.convert(updatedEntity, CohortCharacterizationDTO.class);
return convertCcToDto(updatedEntity);
}

/**
Expand Down Expand Up @@ -445,6 +446,14 @@ public List<CcResult> getGenerationsResults(
return service.findResultAsList(generationId, thresholdLevel);
}

@GET
@Path("/generation/{generationId}/temporalresult")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public List<CcTemporalResult> getGenerationTemporalResults(@PathParam("generationId") final Long generationId) {
return service.findTemporalResultAsList(generationId);
}

@POST
@Path("/generation/{generationId}/result")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.ohdsi.webapi.cohortcharacterization.dto.CcPrevalenceStat;
import org.ohdsi.webapi.cohortcharacterization.dto.CcResult;
import org.ohdsi.webapi.cohortcharacterization.dto.CcShortDTO;
import org.ohdsi.webapi.cohortcharacterization.dto.CcTemporalResult;
import org.ohdsi.webapi.cohortcharacterization.dto.CcVersionFullDTO;
import org.ohdsi.webapi.cohortcharacterization.dto.CohortCharacterizationDTO;
import org.ohdsi.webapi.cohortcharacterization.dto.ExecutionResultRequest;
Expand All @@ -15,6 +16,8 @@
import org.ohdsi.webapi.cohortdefinition.event.CohortDefinitionChangedEvent;
import org.ohdsi.webapi.feanalysis.event.FeAnalysisChangedEvent;
import org.ohdsi.webapi.job.JobExecutionResource;
import org.ohdsi.webapi.shiro.annotations.CcGenerationId;
import org.ohdsi.webapi.shiro.annotations.DataSourceAccess;
import org.ohdsi.webapi.tag.domain.HasTags;
import org.ohdsi.webapi.tag.dto.TagNameListRequestDTO;
import org.ohdsi.webapi.versioning.domain.CharacterizationVersion;
Expand Down Expand Up @@ -64,6 +67,9 @@ public interface CcService extends HasTags<Long> {

List<CcGenerationEntity> findGenerationsByCcIdAndSource(Long id, String sourceKey);

@DataSourceAccess
List<CcTemporalResult> findTemporalResultAsList(@CcGenerationId Long generationId);

GenerationResults findResult(Long generationId, ExecutionResultRequest params);

List<CcResult> findResultAsList(Long generationId, float thresholdLevel);
Expand Down
236 changes: 221 additions & 15 deletions src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.ohdsi.sql.SqlSplit;
import org.ohdsi.sql.SqlTranslate;
import org.ohdsi.webapi.cohortcharacterization.converter.SerializedCcToCcConverter;
import org.ohdsi.webapi.cohortcharacterization.domain.CcFeAnalysisEntity;
import org.ohdsi.webapi.cohortcharacterization.domain.CohortCharacterizationEntity;
import org.ohdsi.webapi.cohortcharacterization.repository.AnalysisGenerationInfoEntityRepository;
import org.ohdsi.webapi.common.generation.AnalysisTasklet;
Expand All @@ -37,6 +38,7 @@

import java.sql.SQLException;
import java.util.Map;
import java.util.Optional;

import static org.ohdsi.webapi.Constants.Params.*;

Expand Down Expand Up @@ -75,9 +77,13 @@ protected String[] prepareQueries(ChunkContext chunkContext, CancelableJdbcTempl
final String cohortTable = jobParams.get(TARGET_TABLE).toString();
final String sessionId = jobParams.get(SESSION_ID).toString();
final String tempSchema = SourceUtils.getTempQualifier(source);
boolean includeAnnual = cohortCharacterization.getCcFeatureAnalyses().stream()
.anyMatch(fe -> Optional.ofNullable(fe.getIncludeAnnual()).orElse(false));
boolean includeTemporal = cohortCharacterization.getCcFeatureAnalyses().stream()
.anyMatch(fe -> Optional.ofNullable(fe.getIncludeTemporal()).orElse(false));
CCQueryBuilder ccQueryBuilder = new CCQueryBuilder(cohortCharacterization, cohortTable, sessionId,
SourceUtils.getCdmQualifier(source), SourceUtils.getResultsQualifier(source),
SourceUtils.getVocabularyQualifier(source), tempSchema, jobId);
SourceUtils.getVocabularyQualifier(source), tempSchema, jobId, includeAnnual, includeTemporal);
String sql = ccQueryBuilder.build();

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.ohdsi.analysis.CohortMetadata;
import org.ohdsi.analysis.Utils;
import org.ohdsi.analysis.cohortcharacterization.design.CcResultType;
import org.ohdsi.webapi.cohortcharacterization.domain.CcFeAnalysisEntity;
import org.ohdsi.webapi.cohortcharacterization.domain.CcStrataConceptSetEntity;
import org.ohdsi.webapi.cohortcharacterization.domain.CcParamEntity;
import org.ohdsi.webapi.cohortcharacterization.domain.CcStrataEntity;
Expand Down Expand Up @@ -51,7 +52,16 @@ public CohortCharacterizationEntity convert(T source) {
fa.setStatType(CcResultType.PREVALENCE);
}
});
cohortCharacterization.setFeatureAnalyses(converterUtils.convertSet(source.getFeatureAnalyses(), FeAnalysisEntity.class));
cohortCharacterization.setFeatureAnalyses(
source.getFeatureAnalyses().stream().map(fa -> {
CcFeAnalysisEntity feAnalysisEntity = new CcFeAnalysisEntity();
feAnalysisEntity.setFeatureAnalysis(conversionService.convert(fa, FeAnalysisEntity.class));
feAnalysisEntity.setCohortCharacterization(cohortCharacterization);
feAnalysisEntity.setIncludeAnnual(fa.getIncludeAnnual());
feAnalysisEntity.setIncludeTemporal(fa.getIncludeTemporal());
return feAnalysisEntity;
}).collect(Collectors.toSet())
);

cohortCharacterization.setParameters(converterUtils.convertSet(source.getParameters(), CcParamEntity.class));
cohortCharacterization.setStratas(converterUtils.convertSet(source.getStratas(), CcStrataEntity.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public CohortCharacterizationDTO convert(final CohortCharacterizationEntity sour
final CohortCharacterizationDTO cohortCharacterizationDTO = super.convert(source);

cohortCharacterizationDTO.setCohorts(converterUtils.convertSet(source.getCohortDefinitions(), CohortMetadataImplDTO.class));
cohortCharacterizationDTO.setFeatureAnalyses(converterUtils.convertSet(source.getFeatureAnalyses(), FeAnalysisShortDTO.class));
cohortCharacterizationDTO.setFeatureAnalyses(converterUtils.convertSet(source.getCcFeatureAnalyses(), FeAnalysisShortDTO.class));
return cohortCharacterizationDTO;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package org.ohdsi.webapi.cohortcharacterization.domain;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.ohdsi.analysis.cohortcharacterization.design.FeatureAnalysis;
import org.ohdsi.analysis.cohortcharacterization.design.FeatureAnalysisDomain;
import org.ohdsi.analysis.cohortcharacterization.design.FeatureAnalysisType;
import org.ohdsi.webapi.feanalysis.domain.FeAnalysisEntity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;

@Entity
@Table(name = "cc_analysis")
public class CcFeAnalysisEntity implements FeatureAnalysis {

@Id
@GenericGenerator(
name = "cc_analysis_generator",
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
parameters = {
@Parameter(name = "sequence_name", value = "cc_analysis_seq"),
@Parameter(name = "increment_size", value = "1")
}
)
@GeneratedValue(generator = "cc_analysis_generator")
private Long id;
@ManyToOne(optional = false)
@JoinColumn(name = "cohort_characterization_id")
private CohortCharacterizationEntity cohortCharacterization;
@ManyToOne(optional = false)
@JoinColumn(name = "fe_analysis_id")
private FeAnalysisEntity featureAnalysis;
@Column(name = "include_annual")
private Boolean includeAnnual;
@Column(name = "include_temporal")
private Boolean includeTemporal;

public CohortCharacterizationEntity getCohortCharacterization() {
return cohortCharacterization;
}

public void setCohortCharacterization(CohortCharacterizationEntity cohortCharacterization) {
this.cohortCharacterization = cohortCharacterization;
}

public FeAnalysisEntity getFeatureAnalysis() {
return featureAnalysis;
}

public void setFeatureAnalysis(FeAnalysisEntity featureAnalysis) {
this.featureAnalysis = featureAnalysis;
}

public Long getId() {
return id;
}

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

public Boolean getIncludeAnnual() {
return includeAnnual;
}

public void setIncludeAnnual(Boolean includeAnnual) {
this.includeAnnual = includeAnnual;
}

public Boolean getIncludeTemporal() {
return includeTemporal;
}

public void setIncludeTemporal(Boolean includeTemporal) {
this.includeTemporal = includeTemporal;
}

private <T> T mapFeatureAnalysis(Function<FeAnalysisEntity, T> getter) {
return Optional.ofNullable(featureAnalysis).map(getter).orElse(null);
}

@Override
public FeatureAnalysisType getType() {
return mapFeatureAnalysis(FeatureAnalysis::getType);
}

@Override
public String getName() {
return mapFeatureAnalysis(FeatureAnalysis::getName);
}

@Override
public FeatureAnalysisDomain getDomain() {
return mapFeatureAnalysis(FeatureAnalysis::getDomain);
}

@Override
public String getDescr() {
return mapFeatureAnalysis(FeatureAnalysis::getDescr);
}

@Override
public Object getDesign() {
return mapFeatureAnalysis(FeatureAnalysis::getDesign);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ohdsi.webapi.cohortcharacterization.domain;

import java.util.*;
import java.util.stream.Collectors;

import javax.persistence.CascadeType;
import javax.persistence.Column;
Expand Down Expand Up @@ -52,11 +53,9 @@ public class CohortCharacterizationEntity extends CommonEntityExt<Long> implemen
inverseJoinColumns = @JoinColumn(name = "cohort_id", referencedColumnName = "id"))
private Set<CohortDefinition> cohortDefinitions = new HashSet<>();

@ManyToMany(targetEntity = FeAnalysisEntity.class, fetch = FetchType.LAZY)
@JoinTable(name = "cc_analysis",
joinColumns = @JoinColumn(name = "cohort_characterization_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "fe_analysis_id", referencedColumnName = "id"))
private Set<FeAnalysisEntity> featureAnalyses = new HashSet<>();
@OneToMany(orphanRemoval = true)
@JoinColumn(name = "cohort_characterization_id", insertable = false, updatable = false, nullable = false)
private Set<CcFeAnalysisEntity> featureAnalyses = new HashSet<>();

@OneToMany(mappedBy = "cohortCharacterization", fetch = FetchType.LAZY, targetEntity = CcParamEntity.class)
private Set<CcParamEntity> parameters = new HashSet<>();
Expand Down Expand Up @@ -89,6 +88,12 @@ public Set<CohortDefinition> getCohorts() {

@Override
public Set<FeAnalysisEntity> getFeatureAnalyses() {
return featureAnalyses != null ?
featureAnalyses.stream().map(CcFeAnalysisEntity::getFeatureAnalysis).collect(Collectors.toSet()) :
Collections.emptySet();
}

public Set<CcFeAnalysisEntity> getCcFeatureAnalyses() {
return featureAnalyses;
}

Expand All @@ -97,6 +102,10 @@ public Set<CcParamEntity> getParameters() {
return parameters;
}

public void setFeatureAnalyses(Set<CcFeAnalysisEntity> featureAnalyses) {
this.featureAnalyses = featureAnalyses;
}

@Override
public Long getId() {
return id;
Expand Down Expand Up @@ -126,10 +135,6 @@ public void setParameters(final Set<CcParamEntity> parameters) {
this.parameters = parameters;
}

public void setFeatureAnalyses(final Set<FeAnalysisEntity> featureAnalyses) {
this.featureAnalyses = featureAnalyses;
}

public Set<CohortDefinition> getCohortDefinitions() {
return cohortDefinitions;
}
Expand Down
Loading
Loading