Skip to content

Commit e1b10dd

Browse files
committed
Cosmetic changes per 20.03.2025
1 parent d293d8b commit e1b10dd

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/main/java/org/ohdsi/webapi/service/lock/ConceptSetLockingService.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,17 @@ public List<ConceptSetSnapshotParameters> listSnapshotsByConceptSetId(Integer co
203203
"WHERE CONCEPT_SET_ID = ? ORDER BY ACTION_DATE DESC", snapshotHistorySourceProvider.getSnapshotHistorySourceSchema());
204204

205205
CancelableJdbcTemplate jdbcTemplate = getSourceJdbcTemplate(snapshotHistorySourceProvider.getSnapshotHistorySource());
206-
return jdbcTemplate.query(sql, new Object[]{conceptSetId}, (rs, rowNum) -> toConceptSetSnapshotParameters(rs));
206+
List<ConceptSetSnapshotParameters> snapshots = jdbcTemplate.query(sql, new Object[]{conceptSetId}, (rs, rowNum) -> toConceptSetSnapshotParameters(rs));
207+
enrichSnapshotParametersWithEmptyIndicator(snapshots, jdbcTemplate);
208+
return snapshots;
209+
}
210+
private void enrichSnapshotParametersWithEmptyIndicator(List<ConceptSetSnapshotParameters> snapshots, CancelableJdbcTemplate jdbcTemplate){
211+
for (ConceptSetSnapshotParameters snapshot : snapshots) {
212+
Long snapshotId = snapshot.getSnapshotId();
213+
if (isSnapshotEmpty(jdbcTemplate, snapshotId)) {
214+
snapshot.setEmptySnapshot(true);
215+
}
216+
}
207217
}
208218

209219
private ConceptSetSnapshotParameters toConceptSetSnapshotParameters(ResultSet rs) throws SQLException {
@@ -253,6 +263,26 @@ public List<ConceptSetExpression.ConceptSetItem> getConceptSetSnapshotItemsBySna
253263
return jdbcTemplate.query(sql, new Object[]{snapshotId}, (rs, rowNum) -> convertToConceptSetItem(rs, type));
254264
}
255265

266+
/**
267+
* Helper method to check if the snapshot metadata ID has records in associated tables.
268+
*
269+
* @param jdbcTemplate JDBC template for querying the database.
270+
* @param snapshotMetadataId Metadata ID to check for records.
271+
* @return true if all tables are empty, false if at least one table contains records.
272+
*/
273+
private boolean isSnapshotEmpty(CancelableJdbcTemplate jdbcTemplate, Long snapshotMetadataId) {
274+
String itemSnapshotsQuery = String.format("SELECT COUNT(*) FROM %s.CONCEPT_SET_ITEM_SNAPSHOTS WHERE SNAPSHOT_METADATA_ID = ?", snapshotHistorySourceProvider.getSnapshotHistorySourceSchema());
275+
Integer itemSnapshotsCount = jdbcTemplate.queryForObject(itemSnapshotsQuery, new Object[]{snapshotMetadataId}, Integer.class);
276+
277+
String includedConceptsQuery = String.format("SELECT COUNT(*) FROM %s.INCLUDED_CONCEPTS_SNAPSHOTS WHERE SNAPSHOT_METADATA_ID = ?", snapshotHistorySourceProvider.getSnapshotHistorySourceSchema());
278+
Integer includedConceptsCount = jdbcTemplate.queryForObject(includedConceptsQuery, new Object[]{snapshotMetadataId}, Integer.class);
279+
280+
String includedSourceCodesQuery = String.format("SELECT COUNT(*) FROM %s.INCLUDED_SOURCE_CODES_SNAPSHOTS WHERE SNAPSHOT_METADATA_ID = ?", snapshotHistorySourceProvider.getSnapshotHistorySourceSchema());
281+
Integer includedSourceCodesCount = jdbcTemplate.queryForObject(includedSourceCodesQuery, new Object[]{snapshotMetadataId}, Integer.class);
282+
283+
return (itemSnapshotsCount == 0) && (includedConceptsCount == 0) && (includedSourceCodesCount == 0);
284+
}
285+
256286
private ConceptSetExpression.ConceptSetItem convertToConceptSetItem(ResultSet rs, GetConceptSetSnapshotItemsRequest.ItemType type) throws SQLException {
257287
Concept concept = new Concept();
258288
concept.conceptId = rs.getLong("CONCEPT_ID");

src/main/java/org/ohdsi/webapi/service/lock/dto/ConceptSetSnapshotParameters.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class ConceptSetSnapshotParameters {
1010
private String vocabularyBundleVersion;
1111
private String conceptSetVersion;
1212
private String message;
13+
private boolean emptySnapshot;
1314

1415
public String getSnapshotDate() {
1516
return snapshotDate;
@@ -82,4 +83,12 @@ public Long getSnapshotId() {
8283
public void setSnapshotId(Long snapshotId) {
8384
this.snapshotId = snapshotId;
8485
}
86+
87+
public boolean isEmptySnapshot() {
88+
return emptySnapshot;
89+
}
90+
91+
public void setEmptySnapshot(boolean emptySnapshot) {
92+
this.emptySnapshot = emptySnapshot;
93+
}
8594
}

0 commit comments

Comments
 (0)