-
Notifications
You must be signed in to change notification settings - Fork 42
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
15766: item sent event #15920
15766: item sent event #15920
Changes from 1 commit
90ada17
a1cb856
06ab90c
997fd43
e6909dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ import com.microsoft.azure.functions.HttpRequestMessage | |
import com.microsoft.azure.functions.HttpResponseMessage | ||
import com.microsoft.azure.functions.HttpStatusType | ||
import com.networknt.org.apache.commons.validator.routines.InetAddressValidator | ||
import fhirengine.engine.CustomFhirPathFunctions | ||
import gov.cdc.prime.reportstream.shared.BlobUtils | ||
import gov.cdc.prime.router.ActionLog | ||
import gov.cdc.prime.router.ActionLogLevel | ||
import gov.cdc.prime.router.ClientSource | ||
|
@@ -25,11 +27,16 @@ import gov.cdc.prime.router.azure.db.tables.pojos.ItemLineage | |
import gov.cdc.prime.router.azure.db.tables.pojos.ReportFile | ||
import gov.cdc.prime.router.azure.db.tables.pojos.ReportLineage | ||
import gov.cdc.prime.router.azure.db.tables.pojos.Task | ||
import gov.cdc.prime.router.azure.observability.bundleDigest.BundleDigestExtractor | ||
import gov.cdc.prime.router.azure.observability.bundleDigest.FhirPathBundleDigestLabResultExtractorStrategy | ||
import gov.cdc.prime.router.azure.observability.event.IReportStreamEventService | ||
import gov.cdc.prime.router.azure.observability.event.ReportStreamEventName | ||
import gov.cdc.prime.router.azure.observability.event.ReportStreamEventProperties | ||
import gov.cdc.prime.router.common.AzureHttpUtils.getSenderIP | ||
import gov.cdc.prime.router.common.JacksonMapperUtilities | ||
import gov.cdc.prime.router.fhirengine.translation.hl7.utils.CustomContext | ||
import gov.cdc.prime.router.fhirengine.utils.FhirTranscoder | ||
import gov.cdc.prime.router.report.ReportService | ||
import io.ktor.http.HttpStatusCode | ||
import org.apache.logging.log4j.kotlin.Logging | ||
import org.jooq.impl.SQLDataType | ||
|
@@ -565,6 +572,7 @@ class ActionHistory( | |
result: String, | ||
header: WorkflowEngine.Header, | ||
reportEventService: IReportStreamEventService, | ||
reportService: ReportService, | ||
transportType: String, | ||
) { | ||
if (isReportAlreadyTracked(sentReportId)) { | ||
|
@@ -616,6 +624,45 @@ class ActionHistory( | |
) | ||
} | ||
|
||
val lineages = Report.createItemLineagesFromDb(header, sentReportId) | ||
lineages?.forEach { itemLineage -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This algorithm is okay for now, but just thinking out loud, downloading blobs and parsing them just to get Item information EVERY TIME we need it in the various steps seems inefficient. If we were storing "Item" in the database, the bundle digest is something that would fit nicely there and then we could just get it from the DB (given it does not contain PII). Alternatively, we could also use the covid pipelines metadata table strategy probably. I don't think any of this is worth considering until we gather the external message monitoring requirements. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense to me. My ultimate preference would to have a clearer delineation of the uses cases since this doesn't even feel like monitoring and is more an analytics/business reporting question |
||
val receiverFilterReportFile = reportService.getReportsForStep( | ||
itemLineage.parentReportId, | ||
itemLineage.parentIndex, | ||
TaskAction.receiver_filter | ||
) | ||
if (receiverFilterReportFile != null) { | ||
val blob = BlobAccess.downloadBlob( | ||
receiverFilterReportFile.bodyUrl, | ||
BlobUtils.digestToString(receiverFilterReportFile.blobDigest) | ||
) | ||
val bundle = FhirTranscoder.decode(blob) | ||
val bundleDigestExtractor = BundleDigestExtractor( | ||
FhirPathBundleDigestLabResultExtractorStrategy( | ||
CustomContext( | ||
bundle, | ||
bundle, | ||
mutableMapOf(), | ||
CustomFhirPathFunctions() | ||
) | ||
) | ||
) | ||
reportEventService.sendItemEvent(ReportStreamEventName.ITEM_SENT, reportFile, TaskAction.send) { | ||
trackingId(bundle) | ||
parentReportId(header.reportFile.reportId) | ||
childItemIndex(itemLineage.childIndex) | ||
params( | ||
mapOf( | ||
ReportStreamEventProperties.BUNDLE_DIGEST | ||
to bundleDigestExtractor.generateDigest(bundle), | ||
ReportStreamEventProperties.RECEIVER_NAME to receiver.fullName, | ||
) | ||
) | ||
} | ||
} else { | ||
logger.error("No translate report found for sent item.") | ||
} | ||
} | ||
reportsOut[reportFile.reportId] = reportFile | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ import org.jooq.CommonTableExpression | |
import org.jooq.DSLContext | ||
import org.jooq.Record | ||
import org.jooq.Record1 | ||
import org.jooq.Record2 | ||
import org.jooq.SelectOnConditionStep | ||
import org.jooq.impl.CustomRecord | ||
import org.jooq.impl.CustomTable | ||
|
@@ -213,6 +212,17 @@ class ReportGraph( | |
return descendantReportRecords(txn, cte, searchedForTaskActions).fetchInto(ReportFile::class.java) | ||
} | ||
|
||
fun getAncestorReports( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kdoc? |
||
txn: DataAccessTransaction, | ||
childReportId: UUID, | ||
childIndex: Int, | ||
searchedForTaskActions: Set<TaskAction>? = null, | ||
): ReportFile? { | ||
val cte = itemAncestorGraphCommonTableExpression(childReportId, childIndex) | ||
|
||
return ancestorReportRecords(txn, cte, searchedForTaskActions).fetchOneInto(ReportFile::class.java) | ||
} | ||
|
||
/** | ||
* Returns all the metadata rows associated with the passed in [ItemGraphRecord] | ||
* | ||
|
@@ -421,19 +431,15 @@ class ReportGraph( | |
*/ | ||
fun reportAncestorGraphCommonTableExpression(childReportIds: List<UUID>) = | ||
DSL.name(lineageCteName).fields( | ||
PARENT_REPORT_ID_FIELD, | ||
PATH_FIELD | ||
PARENT_REPORT_ID_FIELD | ||
).`as`( | ||
DSL.select( | ||
REPORT_LINEAGE.PARENT_REPORT_ID, | ||
REPORT_LINEAGE.CHILD_REPORT_ID.cast(SQLDataType.VARCHAR), | ||
REPORT_LINEAGE.PARENT_REPORT_ID | ||
).from(REPORT_LINEAGE) | ||
.where(REPORT_LINEAGE.CHILD_REPORT_ID.`in`(childReportIds)) | ||
.unionAll( | ||
DSL.select( | ||
REPORT_LINEAGE.PARENT_REPORT_ID, | ||
DSL.field("$lineageCteName.$PATH_FIELD", SQLDataType.VARCHAR) | ||
.concat(REPORT_LINEAGE.PARENT_REPORT_ID) | ||
REPORT_LINEAGE.PARENT_REPORT_ID | ||
) | ||
.from(REPORT_LINEAGE) | ||
.join(DSL.table(DSL.name(lineageCteName))) | ||
|
@@ -454,7 +460,7 @@ class ReportGraph( | |
*/ | ||
private fun rootReportRecords( | ||
txn: DataAccessTransaction, | ||
cte: CommonTableExpression<Record2<UUID, String>>, | ||
cte: CommonTableExpression<Record1<UUID>>, | ||
) = DSL.using(txn) | ||
.withRecursive(cte) | ||
.select(REPORT_FILE.asterisk()) | ||
|
@@ -520,4 +526,33 @@ class ReportGraph( | |
|
||
return select | ||
} | ||
|
||
/** | ||
* Fetches all descendant report records in a recursive manner. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "ancestor" instead of "descendant"? |
||
* | ||
* @param txn the data access transaction | ||
* @param cte the common table expression for report lineage | ||
* @return the descendant report records | ||
*/ | ||
private fun ancestorReportRecords( | ||
txn: DataAccessTransaction, | ||
cte: CommonTableExpression<ItemGraphRecord>, | ||
searchedForTaskActions: Set<TaskAction>?, | ||
): SelectOnConditionStep<Record> { | ||
val select = DSL.using(txn) | ||
.withRecursive(cte) | ||
.select(REPORT_FILE.asterisk()) | ||
.distinctOn(REPORT_FILE.REPORT_ID) | ||
.from(cte) | ||
.join(REPORT_FILE) | ||
.on(REPORT_FILE.REPORT_ID.eq(ItemGraphTable.ITEM_GRAPH.PARENT_REPORT_ID)) | ||
.join(ACTION) | ||
.on(ACTION.ACTION_ID.eq(REPORT_FILE.ACTION_ID)) | ||
|
||
if (searchedForTaskActions != null) { | ||
select.where(ACTION.ACTION_NAME.`in`(searchedForTaskActions)) | ||
} | ||
|
||
return select | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package gov.cdc.prime.router.report | |
|
||
import gov.cdc.prime.router.ReportId | ||
import gov.cdc.prime.router.azure.DatabaseAccess | ||
import gov.cdc.prime.router.azure.db.enums.TaskAction | ||
import gov.cdc.prime.router.azure.db.tables.pojos.ReportFile | ||
import gov.cdc.prime.router.common.BaseEngine | ||
import gov.cdc.prime.router.history.db.ReportGraph | ||
|
@@ -47,7 +48,13 @@ class ReportService( | |
* @return List of ReportFile objects of the root reports | ||
*/ | ||
fun getRootReports(childReportId: ReportId): List<ReportFile> { | ||
return reportGraph.getRootReports(childReportId) | ||
return reportGraph.getRootReports(childReportId).distinctBy { it.reportId } | ||
} | ||
|
||
fun getReportsForStep(childReportId: ReportId, childIndex: Int, task: TaskAction): ReportFile? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kdoc? Also confusing because query only returns one but method name is getReports? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, little copy pasta; this actually fetches a specific report for an item and action. Will update the name |
||
return db.transactReturning { txn -> | ||
reportGraph.getAncestorReports(txn, childReportId, childIndex, setOf(task)) | ||
} | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be better as a class member?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was really messy with how the action history gets instantiated to do it that way (also why I'm passed in the reportEventService that way originally). I was bucketing this is in things to clean up if we refactor how some this works