import {
  getDynamoDataService
} from "./chunk-6BB4CRSS.mjs";
import {
  createDataEntityRecord,
  mergeAuditIntoMeta
} from "./chunk-V6AO5T57.mjs";
import {
  NotFoundError
} from "./chunk-FYHBHHWK.mjs";
import {
  getDynamoControlService
} from "./chunk-EUIP2U5F.mjs";

// src/data/operations/control/role/role-get-by-id-operation.ts
async function getRoleByIdOperation(params) {
  const { id, tableName } = params;
  const service = getDynamoControlService(tableName);
  const response = await service.entities.role.get({ id, sk: "CURRENT" }).go();
  const item = response.data;
  if (!item) {
    throw new NotFoundError(`Role not found: ${id}`);
  }
  const parsedResource = JSON.parse(item.resource);
  return {
    id,
    resource: { resourceType: "Role", id, ...parsedResource }
  };
}

// src/data/operations/data/account/account-create-operation.ts
import { ulid } from "ulid";
async function createAccountOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const accountWithAudit = {
    ...body,
    resourceType: "Account",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.account,
    tenantId,
    workspaceId,
    id,
    accountWithAudit,
    date
  );
}

// src/data/operations/data/appointment/appointment-create-operation.ts
import { ulid as ulid2 } from "ulid";
async function createAppointmentOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid2();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const resourceWithAudit = {
    ...body,
    resourceType: "Appointment",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.appointment,
    tenantId,
    workspaceId,
    id,
    resourceWithAudit,
    date
  );
}

// src/data/operations/data/claim/claim-create-operation.ts
import { ulid as ulid3 } from "ulid";
async function createClaimOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid3();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const resourceWithAudit = {
    ...body,
    resourceType: "Claim",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.claim,
    tenantId,
    workspaceId,
    id,
    resourceWithAudit,
    date
  );
}

// src/data/operations/data/condition/condition-create-operation.ts
import { ulid as ulid4 } from "ulid";
async function createConditionOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid4();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const resourceWithAudit = {
    ...body,
    resourceType: "Condition",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.condition,
    tenantId,
    workspaceId,
    id,
    resourceWithAudit,
    date
  );
}

// src/data/operations/data/coverage/coverage-create-operation.ts
import { ulid as ulid5 } from "ulid";
async function createCoverageOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid5();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const resourceWithAudit = {
    ...body,
    resourceType: "Coverage",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.coverage,
    tenantId,
    workspaceId,
    id,
    resourceWithAudit,
    date
  );
}

// src/data/operations/data/encounter/encounter-create-operation.ts
import { ulid as ulid6 } from "ulid";
async function createEncounterOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid6();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const encounterWithAudit = {
    ...body,
    resourceType: "Encounter",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.encounter,
    tenantId,
    workspaceId,
    id,
    encounterWithAudit,
    date
  );
}

// src/data/operations/data/location/location-create-operation.ts
import { ulid as ulid7 } from "ulid";
async function createLocationOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid7();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const resourceWithAudit = {
    ...body,
    resourceType: "Location",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.location,
    tenantId,
    workspaceId,
    id,
    resourceWithAudit,
    date
  );
}

// src/data/operations/data/observation/observation-create-operation.ts
import { ulid as ulid8 } from "ulid";
async function createObservationOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid8();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const resourceWithAudit = {
    ...body,
    resourceType: "Observation",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.observation,
    tenantId,
    workspaceId,
    id,
    resourceWithAudit,
    date
  );
}

// src/data/operations/data/organization/organization-create-operation.ts
import { ulid as ulid9 } from "ulid";
async function createOrganizationOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid9();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const resourceWithAudit = {
    ...body,
    resourceType: "Organization",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.organization,
    tenantId,
    workspaceId,
    id,
    resourceWithAudit,
    date
  );
}

// src/data/operations/data/patient/patient-create-operation.ts
import { ulid as ulid10 } from "ulid";
async function createPatientOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid10();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const patientWithAudit = {
    ...body,
    resourceType: "Patient",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.patient,
    tenantId,
    workspaceId,
    id,
    patientWithAudit,
    date
  );
}

// src/data/operations/data/paymentnotice/paymentnotice-create-operation.ts
import { ulid as ulid11 } from "ulid";
async function createPaymentNoticeOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid11();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const resourceWithAudit = {
    ...body,
    resourceType: "PaymentNotice",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.paymentnotice,
    tenantId,
    workspaceId,
    id,
    resourceWithAudit,
    date
  );
}

// src/data/operations/data/practitioner/practitioner-create-operation.ts
import { ulid as ulid12 } from "ulid";
async function createPractitionerOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid12();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const practitionerWithAudit = {
    ...body,
    resourceType: "Practitioner",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.practitioner,
    tenantId,
    workspaceId,
    id,
    practitionerWithAudit,
    date
  );
}

// src/data/operations/data/procedure/procedure-create-operation.ts
import { ulid as ulid13 } from "ulid";
async function createProcedureOperation(params) {
  const { context, body, tableName } = params;
  const { tenantId, workspaceId, date, actorId, actorName } = context;
  const id = body.id ?? ulid13();
  const meta = {
    ...body.meta ?? {},
    lastUpdated: date,
    versionId: "1"
  };
  const resourceWithAudit = {
    ...body,
    resourceType: "Procedure",
    id,
    meta: mergeAuditIntoMeta(meta, {
      createdDate: date,
      createdById: actorId,
      createdByName: actorName,
      modifiedDate: date,
      modifiedById: actorId,
      modifiedByName: actorName
    })
  };
  const service = getDynamoDataService(tableName);
  return createDataEntityRecord(
    service.entities.procedure,
    tenantId,
    workspaceId,
    id,
    resourceWithAudit,
    date
  );
}

export {
  getRoleByIdOperation,
  createAccountOperation,
  createAppointmentOperation,
  createClaimOperation,
  createConditionOperation,
  createCoverageOperation,
  createEncounterOperation,
  createLocationOperation,
  createObservationOperation,
  createOrganizationOperation,
  createPatientOperation,
  createPaymentNoticeOperation,
  createPractitionerOperation,
  createProcedureOperation
};
//# sourceMappingURL=chunk-2TLJKOJL.mjs.map