Documentation
¶
Overview ¶
Package export implements FHIR Bulk Data export orchestration for HAIStack.
The export service manages async job lifecycle (kickoff, poll, cancel, manifest), scans resources through store.ResourceStore, and writes NDJSON artifacts to a FileStore (temp file + PutStream when the store implements FileStoreWithStream). Runtime persists job records in store.JobStore (type export.bulk.record) and files in store.BlobStore: the configured object-store adapter when present, otherwise the chunked Postgres or SQLite blob store. Downloads use OpenFile when the file store implements FileStoreWithStream. Background execution integrates with pkg/jobs via TypeExportBulk.
HTTP adapters in pkg/http expose:
- GET /fhir/$export
- GET /fhir/Group/{id}/$export
- GET /fhir/$export/status/{jobId}
- DELETE /fhir/$export/status/{jobId}
- GET /fhir/$export/files/{jobId}/{filename}
Index ¶
- func ParseGroupPatientIDs(env *types.ResourceEnvelope) ([]string, error)
- type Config
- type DurableJobStore
- type ErrorFile
- type ExecuteRequest
- type ExecuteResult
- type Executor
- type FileStore
- type FileStoreWithStream
- type InMemoryFileStore
- func (s *InMemoryFileStore) Delete(_ context.Context, path string) error
- func (s *InMemoryFileStore) Get(_ context.Context, path string) ([]byte, string, error)
- func (s *InMemoryFileStore) Open(ctx context.Context, path string) (io.ReadCloser, string, error)
- func (s *InMemoryFileStore) Put(ctx context.Context, path string, data []byte, contentType string) error
- func (s *InMemoryFileStore) PutStream(_ context.Context, path string, r io.Reader, size int64, contentType string) error
- type InMemoryJobStore
- type Job
- type JobPayload
- type JobStatus
- type JobStore
- type KickoffRequest
- type LocalFileStore
- func (s *LocalFileStore) Delete(_ context.Context, path string) error
- func (s *LocalFileStore) Get(ctx context.Context, path string) ([]byte, string, error)
- func (s *LocalFileStore) Open(_ context.Context, path string) (io.ReadCloser, string, error)
- func (s *LocalFileStore) Put(ctx context.Context, path string, data []byte, contentType string) error
- func (s *LocalFileStore) PutStream(_ context.Context, path string, r io.Reader, size int64, contentType string) error
- type Manifest
- type OutputFile
- type ResourceLister
- type Service
- func (s *Service) Cancel(ctx context.Context, id string) error
- func (s *Service) DeleteJobFiles(ctx context.Context, jobID string) error
- func (s *Service) FileURL(jobID string) string
- func (s *Service) GetFile(ctx context.Context, jobID, filename string) ([]byte, string, error)
- func (s *Service) GetJob(ctx context.Context, id string) (*Job, error)
- func (s *Service) JobHandler() jobs.Handler
- func (s *Service) Kickoff(ctx context.Context, req KickoffRequest) (*Job, error)
- func (s *Service) Manifest(job *Job) *Manifest
- func (s *Service) OpenFile(ctx context.Context, jobID, filename string) (io.ReadCloser, string, error)
- func (s *Service) RunJob(ctx context.Context, jobID string) error
- func (s *Service) StatusURL(jobID string) string
- type TypeCatalog
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseGroupPatientIDs ¶
func ParseGroupPatientIDs(env *types.ResourceEnvelope) ([]string, error)
ParseGroupPatientIDs extracts Patient member ids from a Group resource envelope.
Types ¶
type Config ¶
type Config struct {
Jobs JobStore
Files FileStore
Executor *Executor
JobQueue store.JobStore
BasePath string
PublicURL string
Now func() time.Time
NewID func() string
}
Config configures a Service.
type DurableJobStore ¶
type DurableJobStore struct {
// contains filtered or unexported fields
}
DurableJobStore persists FHIR bulk export jobs in store.JobStore. Records use jobs.TypeExportBulkRecord so worker ClaimNext(TypeExportBulk) never claims status rows.
func NewDurableJobStore ¶
func NewDurableJobStore(db store.JobStore) *DurableJobStore
NewDurableJobStore wraps a database-backed job store.
func (*DurableJobStore) Create ¶
func (s *DurableJobStore) Create(ctx context.Context, job Job) error
func (*DurableJobStore) Delete ¶
func (s *DurableJobStore) Delete(ctx context.Context, id string) error
Delete removes a status row. Used to abandon a Kickoff that failed to enqueue.
type ExecuteRequest ¶
type ExecuteRequest struct {
JobID string
ResourceTypes []string
Since time.Time
GroupID string
PatientIDs []string
BaseFileURL string
OnProgress func(done, total int)
IsCancelled func() bool
}
ExecuteRequest configures one export execution pass.
type ExecuteResult ¶
type ExecuteResult struct {
Output []OutputFile
Errors []ErrorFile
}
ExecuteResult summarizes generated artifacts.
type Executor ¶
type Executor struct {
Resources ResourceLister
Types TypeCatalog
Files FileStore
Now func() time.Time
}
Executor scans resources and writes NDJSON export artifacts.
func (*Executor) Execute ¶
func (e *Executor) Execute(ctx context.Context, req ExecuteRequest) (*ExecuteResult, error)
Execute exports resources into NDJSON files stored in FileStore.
type FileStore ¶
type FileStore interface {
Put(ctx context.Context, path string, data []byte, contentType string) error
Get(ctx context.Context, path string) ([]byte, string, error)
Delete(ctx context.Context, path string) error
}
FileStore stores export artifact bytes keyed by relative path.
type FileStoreWithStream ¶
type FileStoreWithStream interface {
FileStore
PutStream(ctx context.Context, path string, r io.Reader, size int64, contentType string) error
Open(ctx context.Context, path string) (io.ReadCloser, string, error)
}
FileStoreWithStream optionally uploads and opens artifacts without a full []byte.
func NewBlobFileStore ¶
func NewBlobFileStore(blobs store.BlobStore) FileStoreWithStream
NewBlobFileStore wraps a blob store for export artifacts.
type InMemoryFileStore ¶
type InMemoryFileStore struct {
// contains filtered or unexported fields
}
InMemoryFileStore is a concurrent-safe FileStore for tests and local use.
func NewInMemoryFileStore ¶
func NewInMemoryFileStore() *InMemoryFileStore
NewInMemoryFileStore constructs an empty in-memory file store.
func (*InMemoryFileStore) Delete ¶
func (s *InMemoryFileStore) Delete(_ context.Context, path string) error
func (*InMemoryFileStore) Open ¶
func (s *InMemoryFileStore) Open(ctx context.Context, path string) (io.ReadCloser, string, error)
type InMemoryJobStore ¶
type InMemoryJobStore struct {
// contains filtered or unexported fields
}
InMemoryJobStore is a concurrent-safe JobStore for tests and local use.
func NewInMemoryJobStore ¶
func NewInMemoryJobStore() *InMemoryJobStore
NewInMemoryJobStore constructs an empty in-memory job store.
func (*InMemoryJobStore) Create ¶
func (s *InMemoryJobStore) Create(_ context.Context, job Job) error
func (*InMemoryJobStore) Delete ¶
func (s *InMemoryJobStore) Delete(_ context.Context, id string) error
type Job ¶
type Job struct {
ID string
Status JobStatus
Request KickoffRequest
TransactionTime time.Time
Progress string
Output []OutputFile
Errors []ErrorFile
CreatedAt time.Time
CompletedAt time.Time
LastError string
CancelRequested bool
}
Job is a durable bulk export job record.
type JobPayload ¶
type JobPayload struct {
JobID string `json:"jobId"`
}
JobPayload is the background job payload for bulk export execution.
type JobStore ¶
type JobStore interface {
Create(ctx context.Context, job Job) error
Get(ctx context.Context, id string) (*Job, error)
Update(ctx context.Context, job Job) error
}
JobStore persists bulk export job state.
type KickoffRequest ¶
type KickoffRequest struct {
TenantID string
PrincipalID string
ResourceTypes []string
Since time.Time
GroupID string
PatientID string
PatientExport bool
TypeFilter string
OutputFormat string
RequestURL string
RequiresAccess bool
}
KickoffRequest captures export parameters from an HTTP kickoff.
type LocalFileStore ¶
type LocalFileStore struct {
// contains filtered or unexported fields
}
LocalFileStore persists export artifacts on the local filesystem.
func NewLocalFileStore ¶
func NewLocalFileStore(root string) (*LocalFileStore, error)
NewLocalFileStore creates a filesystem-backed FileStore.
func (*LocalFileStore) Delete ¶
func (s *LocalFileStore) Delete(_ context.Context, path string) error
func (*LocalFileStore) Open ¶
func (s *LocalFileStore) Open(_ context.Context, path string) (io.ReadCloser, string, error)
type Manifest ¶
type Manifest struct {
TransactionTime time.Time `json:"transactionTime"`
Request string `json:"request"`
RequiresAccessToken bool `json:"requiresAccessToken"`
Output []OutputFile `json:"output"`
Error []ErrorFile `json:"error,omitempty"`
}
Manifest is the completed export manifest returned to clients.
type OutputFile ¶
OutputFile describes one exported NDJSON artifact.
type ResourceLister ¶
type ResourceLister interface {
ListIDs(ctx context.Context, resourceType string, limit, offset int) ([]string, error)
Read(ctx context.Context, resourceType, id string) (*types.ResourceEnvelope, error)
}
ResourceLister enumerates FHIR resources for export.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service orchestrates bulk export kickoff, polling, cancellation, and execution.
func NewService ¶
NewService validates configuration and returns a Service.
func (*Service) DeleteJobFiles ¶
DeleteJobFiles removes export artifacts after download.
func (*Service) JobHandler ¶
JobHandler returns a jobs.Handler that executes bulk export jobs.
func (*Service) Kickoff ¶
Kickoff creates an async export job and optionally enqueues background execution.
func (*Service) OpenFile ¶
func (s *Service) OpenFile(ctx context.Context, jobID, filename string) (io.ReadCloser, string, error)
OpenFile streams one export artifact without assembling a full []byte.
type TypeCatalog ¶
type TypeCatalog interface {
EnabledResourceTypes() []string
}
TypeCatalog returns exportable resource types when _type is omitted.