Merged in feature/textExtractionsPart2 (pull request #193)

Continue finishing the parts of the text extraction plan

* add missing fields
This commit is contained in:
Jay Brown
2025-12-02 19:13:08 +00:00
parent c45e1dd427
commit 3bdc27f4de
21 changed files with 2392 additions and 215 deletions
+52 -2
View File
@@ -158,13 +158,63 @@ INSERT INTO documentFieldExtractionArrayFields (
);
-- name: AddFieldExtractionEntry :exec
INSERT INTO documentFieldExtractionVersions (fieldExtractionId, version, createdBy)
VALUES ($1, $2, $3);
-- Insert a new version entry for a field extraction
-- documentId is required for the unique constraint enforcement
INSERT INTO documentFieldExtractionVersions (fieldExtractionId, documentId, version, createdBy)
VALUES ($1, $2, $3, $4);
-- name: LockFieldExtractionVersionsForDocument :many
-- Lock all existing version rows for a document to prevent concurrent inserts
-- Must be called within a transaction before GetMaxFieldExtractionVersion
-- Returns the locked rows (which may be empty for first version)
SELECT id, version FROM documentFieldExtractionVersions
WHERE documentId = $1
FOR UPDATE;
-- name: GetMaxFieldExtractionVersion :one
-- Get the current max version for a document (call after LockFieldExtractionVersionsForDocument)
-- Returns 0 if no versions exist, otherwise the max version number
-- COALESCE ensures we always get a non-NULL value that can be scanned into int64
SELECT COALESCE(MAX(version), 0) as max_version
FROM documentFieldExtractionVersions
WHERE documentId = $1;
-- name: GetCurrentFieldExtraction :one
SELECT * FROM currentFieldExtractions
WHERE documentId = $1;
-- name: GetFieldExtractionByVersion :one
-- Retrieves a specific version of field extraction for a document
-- Returns the field extraction record with version metadata
SELECT
dfe.id,
dfe.documentId,
dfe.fileName,
dfe.contractTitle,
dfe.aareteDerivedAmendmentNum,
dfe.clientName,
dfe.payerName,
dfe.payerState,
dfe.providerState,
dfe.filenameTin,
dfe.provGroupTin,
dfe.provGroupNpi,
dfe.provGroupNameFull,
dfe.provOtherTin,
dfe.provOtherNpi,
dfe.provOtherNameFull,
dfe.aareteDerivedEffectiveDt,
dfe.aareteDerivedTerminationDt,
dfe.autoRenewalInd,
dfe.autoRenewalTerm,
dfev.version,
dfev.createdBy,
dfev.createdAt
FROM documentFieldExtractions dfe
JOIN documentFieldExtractionVersions dfev
ON dfev.fieldExtractionId = dfe.id
WHERE dfev.documentId = $1 AND dfev.version = $2;
-- name: GetCurrentFieldExtractionWithArrayCount :one
SELECT * FROM currentFieldExtractionsWithArrayCount
WHERE documentId = $1;