Product EngineeringFeaturesFile Type Report Upload

Backend

PY-2 livehealthapp finalization and Storage Manager, PY-3 crelio-app Storage Manager and Lambda-facing file-type helpers, persistence, indexing, and rendering.

👤 Rucha Mahesh Kulkarni📅 Updated: Mar 18, 2026📁 File Type Report Upload

Backend

This page consolidates server-side responsibilities: report conversion, presigned generation + reconcile, uploadFileTypeReportAPI branching (new vs legacy), mark-as-done, Elasticsearch and Pusher side effects, print/render special cases, and PY-3 Storage Manager + Lambda-authenticated file-type-report helpers.

Cross-links: Overview, Workflow Guide, Design Decisions.

Backend Technicalities

livehealthapp (PY-2)

1. Report conversion

File: apps/livehealthapp/labs/API.py
Function: convertReportToFileOrNormal

Responsibilities:

  • Authorize conversion (permissions + radiology guard + session shape).
  • Delete existing ReportValue rows.
  • Toggle fileInputReport and related flags (store_values_to_document_db reset in this path).
  • Reset completion, approval, signing, partial sign, print-done fields.
  • Trigger Pusher + patient report ES reindex + activity log.

2. File upload finalizer

File: apps/livehealthapp/reports/views.py
Function: uploadFileTypeReportAPI (+ save_file_type_report_to_report_value on the write path)

Responsibilities:

  • Branch detection: if initialFilePath is present and path-like → presigned-aware fast path (file already in storage).
  • Legacy branch: if fileData present → base64 decode path, restruct_uploaded_files, SmStore, then value write.
  • Update ReportValue.value to the stored path.
  • Mutate LabReportRelation completion / approval fields (e.g. completedTests, isApproved, timestamps, acting labUserId).
  • commonPusherFunctionForLabReportRelation (or equivalent) for waiting-list freshness.
  • Patient report Elasticsearch reindex for search surfaces.
  • Upload activity log entry.

Report mutations (presigned-aware branch - conceptual)

FieldEffect
ReportValue.valueFile path string
reportDate / lastUpdatedUpdated
isApprovedReset toward “needs review” posture (implementation-specific constants)
isPartialFillReset
labUserIdActing user
completedTestsDriven to completed posture for the file-report case

Exact field names should be verified in the implementation block inside uploadFileTypeReportAPI when debugging a specific deployment branch.

3. Legacy preprocessing

Same file: restruct_uploaded_files in reports/views.py

Role: normalize/validate uploads in legacy mode - images, damaged PDFs, EOF quirks, internal failure codes. Historically this is the kind of work the revamp tries to move off the synchronous PY-2 request path toward async / infra-assisted processing.

4. Storage Manager (PY-2)

File: apps/livehealthapp/labs/storage_manager.py

Class / functionResponsibility
SmGeneratePreSignedURLIssue direct-upload contract + create Storage Manager log
SmReconcilePreSignedURLhead_object-style verification + reconcile flags + size on log
get_storage_pathsPath structure generation
Cleanup utilitiese.g. replace deleted file-type attachments with file_not_exists.pdf

URL wiring: apps/livehealthapp/livehealthapp/urls.py (or equivalent project urls.py in your branch) - sm_generate_presigned_url/, sm_reconcile_presigned_url/, uploadFileTypeReport/, uploadFileWithHeader/.

5. Mark-as-done support

File: apps/livehealthapp/labs/newAPI.py
Function: mark_report_as_done_api

Marks sibling operational reports complete with business rules (e.g. at least one operational report must remain incomplete in the bill), updates ES, triggers hooks/Pusher as implemented.

6. Downstream rendering

FileWhy it matters
templates/labTemplates/fileInputReport.jinjaTemplate helper for rendering file-input images in lab print HTML
reports/v2_views/report_view.pySome print flows convert image-backed file input values into generated PDF pages

File-type reports are not “upload and forget”; print/download stacks branch on file paths vs parameter matrices.

crelio-app (PY-3)

1. Storage Manager APIs and core implementation

Capabilities include presigned POST generation, presigned download, reconcile, canonical path generation, extension gates, soft-delete / cleanup behaviors.

2. Canonical path generation (documented shape)

<DeploymentZone>/<LabId>/<PatientId>/<FileCategory>/<cloudDocId>_<filename>.<extension>

Example:

IN/123/456456/FileTypeReport/16915654908422848526992_foo.jpeg

Both PY-2 and PY-3 utilities support caller-supplied cloud_path patterns; the temp vs concrete distinction matters when Lambda rewrites paths.

3. File-type-report Lambda-facing APIs

File: apps/crelio-app/report/views/file_type_report_lambda.py
Routes: see apps/crelio-app/report/urls.py

Endpoint familyResponsibility
report-value/file-type/get/storage-manager/pathAccept temporary path → return canonical concrete Storage Manager path
report-value/file-type/updateUpdate report_results / lab report state with final file path + SM log path rewrite semantics

FetchFileTypeReportPath (conceptual): looks up SM log for temp path, pulls file metadata, resolves S3 account details, emits canonical path. Important implementation detail from source analysis: extension normalization may force .pdf in the helper path - treat this as a normalization contract when reasoning about mixed image/PDF inputs on Lambda-shaped flows.

UpdateReportValueWithFilePath (conceptual): accepts filePath, temporary_filepath, labReportId; updates report_results.value, timestamps, completion flags; aligns SM log from temporary to final path.

4. Lambda authentication

File: apps/crelio-app/core/utils/aws/authenticate_lambda_requests.py

  • Expects header X-Lambda-Token
  • Validates against settings.CRON_SIGNING_KEY (naming may vary by environment - confirm in deployment secrets)

5. File type reports beyond manual UI upload

Example: apps/crelio-app/interfacing/models/device.py - instrument/device flows can persist file_category="FileTypeReport" style outputs.

Format linkage: apps/crelio-app/report/views/report_format_link.py - format type 4 correlates with fileInput=1 semantics in that module’s conventions.

DB and architecture

Relational state, object storage, Storage Manager logs, and Elasticsearch documents together implement the feature; PY-2 remains the observed domain finalizer for the default frontend path.

Core entities

EntityWhy it matters
labReportRelation / LabReportRelationfileInputReport, completedTests, approval / signing flags
ReportValue / report_resultsvalue holds the file path for file-type reports
StorageManagerLogPresigned lifecycle, sizes, paths, reconcile markers
Patient report ES documentSearch + waiting-list propagation

What gets persisted where

LayerStored value
S3Binary PDF/image object
Report DBPath in ReportValue.value or report_results.value
Report rowCompletion / approval metadata
Storage Manager logUpload metadata, category, paths, reconcile state, file size
ElasticsearchPatient-report doc + SM log record

File path semantics

Path typeTypical exampleWho creates it
Temporary caller-specifiedFileTypeReports/IN/28/123456/ab12cd/report.pdfFrontend
Canonical SMIN/28/20798388/FileTypeReport/<cloudDocId>_report.pdfStorage Manager / PY-3 helper
Compatible pathHuman-stable equivalent without generated cloud id prefixStorage Manager utilities
BehaviorExplanation
Requested path can be honored as-isCaller-supplied cloud_path supported in SM utilities
Temp vs concrete can divergeBasis for Lambda + PY-3 helper design
Deleted attachments normalizedCleanup may rewrite to file_not_exists.pdf
PY-3 path helper may force .pdfNormalization / downstream PDF assumption in Lambda-assisted architecture

Setup dependencies by layer

LayerDependencyWhy
FrontendSession with lab contextSM + finalization are lab-scoped
FrontendReport already in file modeWrong mode → wrong UX path
PY-2S3 account for FileTypeReportpresigned generation
PY-2extension allowlistSM rejects unsupported types
PY-2SM ES loggingreconcile + observability
PY-2patient report ESsearchable completion state
PY-2Pusher / realtimeoperator UI freshness
PY-3Lambda token authsecured helper endpoints
AWSS3 + optional event routingdirect upload + optional Lambda

Architectural caveats (backend-focused)

  1. Observed FE still finalizes in PY-2 - presigned + reconcile can be PY-2 while PY-3 exposes parallel helpers.
  2. Lambda source not in repo snapshot - only contracts + auth + endpoints are verifiable here.
  3. Header/footer remains uploadFileWithHeader / base64 transport on PY-2.
  4. Temporary path may be what PY-2 stores in the observed path until/unless a later job rewrites - contrast with PY-3 “temp → canonical” helper intent.

For rationale and decision framing, see Design Decisions.

On this page