563848e0ecc0
Create an egress template with mapping CSV
Uploads a CSV column-mapping file and associated metadata to define a new egress template for data export.
When to use: call this when no existing template covers the target tenant and entity type. To replace the CSV or update metadata on a template that already exists, use PUT /api/v1/egress-templates/{templateId} instead.
Preconditions: tenant-id header must be present and non-blank (returns 400 if missing). templateName and entityType are required form fields; entityType must be one of practitioner, facility, group. status on creation is limited to draft or active — inactive is rejected with 400 at create time.
Defaults applied when omitted: outputFormat -> csv, separator -> ,, status -> draft, scheduleEnabled -> false, scheduleFrequency -> daily, scheduleTime -> 02:00, scheduleTimezone -> UTC (the scheduleFrequency/scheduleTime defaults are skipped when scheduleCron is supplied).
Schedule field rules: scheduleFrequency accepts daily, weekly, monthly, or custom. scheduleCron (Quartz cron syntax, not Unix cron) is required when scheduleFrequency=custom and is rejected for any other frequency. scheduleTime (24-hour HH:mm) is required for daily/weekly/monthly. scheduleDayOfWeek (1 = Sunday ... 7 = Saturday) is required, and only allowed, for weekly. scheduleDayOfMonth (1-31) is required, and only allowed, for monthly.
CSV constraints: maximum file size is 5 MB; exceeding this returns 400. Column attribute paths are validated against the entity type's field schema.
Side effects: the CSV is uploaded to GCS before the template record is written. If the data-store write fails after a successful GCS upload, the GCS object is rolled back so no orphaned file is left behind. Not idempotent — each successful call creates a new template.
Returns: the created template, including the server-assigned id, version set to 1, and mappingsCsvUrl pointing at the uploaded CSV in GCS.
Headers
Response
The newly created egress template, with server-assigned id, version=1, and the mappings CSV's GCS URL
Example response
{
"createdAt": "2022-03-10T16:15:50Z",
"updatedAt": "2022-03-10T16:15:50Z",
"scheduleCron": "0 0 8 ? * MON",
"scheduleDaysOfWeek": "2,4,6",
"scheduleInterval": 6,
"lastExportAt": "2022-03-10T16:15:50Z",
"nextExportAt": "2022-03-10T16:15:50Z"
}