Documentation
¶
Overview ¶
Package bulkimport implements FHIR Bulk Data $import orchestration for HAIStack.
The import service accepts a Parameters kickoff (Prefer: respond-async), reads application/fhir+ndjson inputs, and creates or updates resources through a ResourceWriter. Runtime persists job records in store.JobStore (type export.import.record) and input/error NDJSON in store.BlobStore: the configured object-store adapter when present, otherwise the chunked Postgres or SQLite blob store. Background execution integrates with pkg/jobs via TypeImportBulk.
Remote input.url values are fetched only when a URLLoader is configured. The runtime wires HTTPLoader, which GETs http and https URLs with a 60s timeout and a 64MiB size limit. file:// and other non-http(s) schemes are rejected; redirects to those schemes are also refused. Tests may omit the loader so URL-only kickoffs fail closed.
HTTP adapters in pkg/http expose:
- POST /fhir/$import
- GET /fhir/$import/status/{jobId}
- DELETE /fhir/$import/status/{jobId}
- GET /fhir/$import/files/{jobId}/{filename} — download import error NDJSON
Index ¶
- Constants
- type Config
- type CountFile
- type DurableJobStore
- type ErrorFile
- type ExecuteRequest
- type ExecuteResult
- type Executor
- type FileStore
- type HTTPLoader
- type InMemoryFileStore
- type InMemoryJobStore
- type InputFile
- type Job
- type JobPayload
- type JobStatus
- type JobStore
- type KickoffRequest
- type Manifest
- type ResourceWriter
- type Service
- func (s *Service) Cancel(ctx context.Context, id 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) RunJob(ctx context.Context, jobID string) error
- func (s *Service) StatusURL(jobID string) string
- type URLLoader
Constants ¶
const ( // HTTPLoaderTimeout is the default client timeout for remote NDJSON fetches. HTTPLoaderTimeout = 60 * time.Second // HTTPLoaderMaxBytes is the default maximum size of a fetched NDJSON payload. HTTPLoaderMaxBytes int64 = 64 << 20 )
const InputFormatNDJSON = "application/fhir+ndjson"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Jobs JobStore
Files FileStore
Executor *Executor
JobQueue store.JobStore
Loader URLLoader
BasePath string
PublicURL string
Now func() time.Time
NewID func() string
}
Config configures a Service.
type CountFile ¶
type CountFile struct {
Type string `json:"type"`
Count int `json:"count"`
URL string `json:"url,omitempty"`
}
CountFile summarizes imported resources of one type.
type DurableJobStore ¶
type DurableJobStore struct {
// contains filtered or unexported fields
}
DurableJobStore persists FHIR bulk import jobs in store.JobStore. Records use jobs.TypeImportBulkRecord so worker ClaimNext(TypeImportBulk) 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
Inputs []InputFile
BaseFileURL string
IsCancelled func() bool
OnProgress func(done, total int)
}
ExecuteRequest configures one import execution pass.
type ExecuteResult ¶
ExecuteResult summarizes imported counts and error artifacts.
type Executor ¶
type Executor struct {
Resources ResourceWriter
Files FileStore
Codec types.ResourceCodec
}
Executor reads NDJSON inputs and upserts resources.
func (*Executor) Execute ¶
func (e *Executor) Execute(ctx context.Context, req ExecuteRequest) (*ExecuteResult, error)
Execute imports NDJSON inputs stored for the job.
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 import input and error artifact bytes keyed by relative path.
func NewBlobFileStore ¶
NewBlobFileStore wraps a blob store for import artifacts.
type HTTPLoader ¶
HTTPLoader fetches import input.url values over HTTP(S).
Only http and https URLs are accepted. file://, data:, and other schemes are rejected before the request is issued, and redirects to those schemes are refused. The default client uses a 60s timeout and reads at most 64MiB.
func NewHTTPLoader ¶
func NewHTTPLoader() *HTTPLoader
NewHTTPLoader returns an HTTPLoader with a 60s timeout.
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
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 InputFile ¶
type InputFile struct {
Type string `json:"type"`
URL string `json:"url,omitempty"`
NDJSON []byte `json:"-"`
}
InputFile is one NDJSON source in a kickoff request.
type Job ¶
type Job struct {
ID string
Status JobStatus
Request KickoffRequest
TransactionTime time.Time
Progress string
Output []CountFile
Errors []ErrorFile
CreatedAt time.Time
CompletedAt time.Time
LastError string
CancelRequested bool
}
Job is a durable bulk import job record.
type JobPayload ¶
type JobPayload struct {
JobID string `json:"jobId"`
}
JobPayload is the background job payload for bulk import 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 import job state.
type KickoffRequest ¶
type KickoffRequest struct {
TenantID string
PrincipalID string
InputFormat string
Inputs []InputFile
RequestURL string
RequiresAccess bool
}
KickoffRequest captures import parameters from an HTTP kickoff.
func ParseParametersKickoff ¶
func ParseParametersKickoff(data []byte) (KickoffRequest, error)
ParseParametersKickoff decodes a FHIR Parameters resource into a kickoff request. Each repeating `input` parameter must include a `type` part and either inline NDJSON (`valueString` / `ndjson`) or a `url` part.
type Manifest ¶
type Manifest struct {
TransactionTime time.Time `json:"transactionTime"`
Request string `json:"request"`
RequiresAccessToken bool `json:"requiresAccessToken"`
Output []CountFile `json:"output"`
Error []ErrorFile `json:"error,omitempty"`
}
Manifest is the completed import manifest returned to clients.
type ResourceWriter ¶
type ResourceWriter interface {
Create(ctx context.Context, resource *types.ResourceEnvelope) (*types.ResourceEnvelope, error)
Update(ctx context.Context, resource *types.ResourceEnvelope) (*types.ResourceEnvelope, error)
Read(ctx context.Context, resourceType, id string) (*types.ResourceEnvelope, error)
}
ResourceWriter persists imported FHIR resources.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service orchestrates bulk import kickoff, polling, cancellation, and execution.
func NewService ¶
NewService validates configuration and returns a Service.
func (*Service) JobHandler ¶
JobHandler returns a jobs.Handler that executes bulk import jobs.
func (*Service) Kickoff ¶
Kickoff creates an async import job and optionally enqueues background execution.