From 611a84a86855e3eac18b8387a128af112d6c02cd Mon Sep 17 00:00:00 2001 From: Luke Sikina Date: Thu, 25 Apr 2024 14:40:00 -0400 Subject: [PATCH] [ALS-6344] - Make new query that retuns patient count and concept count --- .../avillach/hpds/data/query/ResultType.java | 8 ++++++- .../hpds/processing/CountProcessor.java | 16 ++++++++++++++ .../processing/PatientAndConceptCount.java | 21 +++++++++++++++++++ .../avillach/hpds/service/PicSureService.java | 3 +++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/PatientAndConceptCount.java diff --git a/client-api/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/query/ResultType.java b/client-api/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/query/ResultType.java index 4481190b..380b4db9 100644 --- a/client-api/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/query/ResultType.java +++ b/client-api/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/data/query/ResultType.java @@ -94,5 +94,11 @@ public enum ResultType { * is suitable to time series analysis and/or loading into another * instance of HPDS. */ - DATAFRAME_TIMESERIES + DATAFRAME_TIMESERIES, + + /** + * Count number of patients and number of available concept paths. Useful for federated networks + * where not every concept path in a query is guaranteed to be in a specific portal + */ + PATIENT_AND_CONCEPT_COUNT } diff --git a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/CountProcessor.java b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/CountProcessor.java index 246880b4..fdac9532 100644 --- a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/CountProcessor.java +++ b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/CountProcessor.java @@ -229,4 +229,20 @@ public Map runVariantCount(Query query) { } return response; } + + public PatientAndConceptCount runPatientAndConceptCount(Query incomingQuery) { + log.info("Starting Patient and Concept Count query {}", incomingQuery.getPicSureId()); + log.info("Calculating available concepts"); + long concepts = incomingQuery.getFields().stream() + .map(abstractProcessor::nullableGetCube) + .filter(Optional::isPresent) + .count(); + log.info("Calculating patient counts"); + int patients = runCounts(incomingQuery); + PatientAndConceptCount patientAndConceptCount = new PatientAndConceptCount(); + patientAndConceptCount.setConceptCount(concepts); + patientAndConceptCount.setPatientCount(patients); + log.info("Completed Patient and Concept Count query {}", incomingQuery.getPicSureId()); + return patientAndConceptCount; + } } diff --git a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/PatientAndConceptCount.java b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/PatientAndConceptCount.java new file mode 100644 index 00000000..bcbb37c0 --- /dev/null +++ b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/PatientAndConceptCount.java @@ -0,0 +1,21 @@ +package edu.harvard.hms.dbmi.avillach.hpds.processing; + +public class PatientAndConceptCount { + private long patientCount, conceptCount; + + public long getPatientCount() { + return patientCount; + } + + public void setPatientCount(long patientCount) { + this.patientCount = patientCount; + } + + public long getConceptCount() { + return conceptCount; + } + + public void setConceptCount(long conceptCount) { + this.conceptCount = conceptCount; + } +} diff --git a/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/PicSureService.java b/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/PicSureService.java index d1d2fb71..686df5d2 100644 --- a/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/PicSureService.java +++ b/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/PicSureService.java @@ -455,6 +455,9 @@ private Response submitQueryAndWaitForCompletion(QueryRequest resultRequest) thr case COUNT: return queryOkResponse(countProcessor.runCounts(incomingQuery), incomingQuery).build(); + case PATIENT_AND_CONCEPT_COUNT: + return queryOkResponse(countProcessor.runPatientAndConceptCount(incomingQuery), incomingQuery).build(); + default: // no valid type return Response.status(Status.BAD_REQUEST).build();