@openhi/constructs 0.0.90 → 0.0.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,4 @@
1
- import {
2
- __require
3
- } from "./chunk-LZOMFHX3.mjs";
1
+ import "./chunk-3QS3WKRC.mjs";
4
2
 
5
3
  // src/data/lambda/rest-api-lambda.handler.ts
6
4
  import serverlessExpress from "@codegenie/serverless-express";
@@ -1458,7 +1456,7 @@ async function batchGetWithRetry(entity, keys) {
1458
1456
  while (pending.length > 0) {
1459
1457
  if (attempt > 0) {
1460
1458
  await new Promise(
1461
- (resolve2) => setTimeout(resolve2, BATCH_GET_BASE_BACKOFF_MS * 2 ** (attempt - 1))
1459
+ (resolve) => setTimeout(resolve, BATCH_GET_BASE_BACKOFF_MS * 2 ** (attempt - 1))
1462
1460
  );
1463
1461
  }
1464
1462
  attempt++;
@@ -24905,133 +24903,8 @@ import express106 from "express";
24905
24903
 
24906
24904
  // src/data/operations/data/patient/patient-create-operation.ts
24907
24905
  import { ulid as ulid99 } from "ulid";
24908
-
24909
- // src/data/import-patient.ts
24910
- import { readFileSync } from "fs";
24911
- import { resolve } from "path";
24912
- import { extractSummary as extractSummary14 } from "@openhi/types";
24913
- function extractPatient(parsed) {
24914
- if (parsed && typeof parsed === "object" && "resourceType" in parsed) {
24915
- const root = parsed;
24916
- if (root.resourceType === "Patient" && root.id) {
24917
- return root;
24918
- }
24919
- if (root.resourceType === "Bundle" && "entry" in parsed) {
24920
- const entries = parsed.entry;
24921
- if (Array.isArray(entries)) {
24922
- const patientEntry = entries.find(
24923
- (e) => e?.resource?.resourceType === "Patient" && e.resource.id
24924
- );
24925
- if (patientEntry?.resource) {
24926
- return patientEntry.resource;
24927
- }
24928
- }
24929
- }
24930
- }
24931
- throw new Error(
24932
- "File must be a FHIR Patient resource or a Bundle containing at least one Patient entry"
24933
- );
24934
- }
24935
- var SK12 = "CURRENT";
24936
- var defaultAudit = {
24937
- createdDate: (/* @__PURE__ */ new Date()).toISOString(),
24938
- createdById: "import",
24939
- createdByName: "Bulk import",
24940
- modifiedDate: (/* @__PURE__ */ new Date()).toISOString(),
24941
- modifiedById: "import",
24942
- modifiedByName: "Bulk import"
24943
- };
24944
- function patientToPutAttrs(patient, options) {
24945
- const {
24946
- tenantId,
24947
- workspaceId,
24948
- createdDate,
24949
- createdById,
24950
- createdByName,
24951
- modifiedDate,
24952
- modifiedById,
24953
- modifiedByName
24954
- } = options;
24955
- const lastUpdated = patient.meta?.lastUpdated ?? modifiedDate ?? defaultAudit.modifiedDate ?? (/* @__PURE__ */ new Date()).toISOString();
24956
- const auditMerged = {
24957
- ...defaultAudit,
24958
- ...createdDate != null && { createdDate },
24959
- ...createdById != null && { createdById },
24960
- ...createdByName != null && { createdByName },
24961
- ...modifiedDate != null && { modifiedDate },
24962
- ...modifiedById != null && { modifiedById },
24963
- ...modifiedByName != null && { modifiedByName }
24964
- };
24965
- const patientWithMeta = {
24966
- ...patient,
24967
- meta: mergeAuditIntoMeta(patient.meta, auditMerged)
24968
- };
24969
- if (lastUpdated && !patientWithMeta.meta.lastUpdated) {
24970
- patientWithMeta.meta.lastUpdated = lastUpdated;
24971
- }
24972
- return {
24973
- sk: SK12,
24974
- tenantId,
24975
- workspaceId,
24976
- id: patient.id,
24977
- resource: compressResource(JSON.stringify(patientWithMeta)),
24978
- summary: JSON.stringify(
24979
- extractSummary14(patientWithMeta)
24980
- ),
24981
- vid: lastUpdated.replace(/[-:T.Z]/g, "").slice(0, 12) || Date.now().toString(36),
24982
- lastUpdated,
24983
- identifierSystem: "",
24984
- identifierValue: "",
24985
- facilityId: "",
24986
- normalizedName: ""
24987
- };
24988
- }
24989
- async function importPatientFromFile(filePath, options) {
24990
- const resolved = resolve(filePath);
24991
- const raw = readFileSync(resolved, "utf-8");
24992
- const parsed = JSON.parse(raw);
24993
- const patient = extractPatient(parsed);
24994
- const service = getDynamoDataService(options.tableName);
24995
- const attrs = patientToPutAttrs(patient, options);
24996
- const result = await service.entities.patient.put(attrs).go();
24997
- const data = result.data;
24998
- if (!data) {
24999
- throw new Error(`Put failed for Patient ${patient.id}`);
25000
- }
25001
- return {
25002
- id: data.id,
25003
- tenantId: data.tenantId,
25004
- workspaceId: data.workspaceId
25005
- };
25006
- }
25007
- async function main() {
25008
- const [, , fileArg, tenantId = "tenant-1", workspaceId = "ws-1"] = process.argv;
25009
- if (!fileArg) {
25010
- console.error(
25011
- "Usage: import-patient.ts <path-to-patient.json> [tenantId] [workspaceId]"
25012
- );
25013
- process.exit(1);
25014
- }
25015
- try {
25016
- const result = await importPatientFromFile(fileArg, {
25017
- tenantId,
25018
- workspaceId
25019
- });
25020
- console.log(
25021
- `Imported Patient ${result.id} (tenant=${result.tenantId}, workspace=${result.workspaceId})`
25022
- );
25023
- } catch (err) {
25024
- console.error(err);
25025
- process.exit(1);
25026
- }
25027
- }
25028
- if (__require.main === module) {
25029
- void main();
25030
- }
25031
-
25032
- // src/data/operations/data/patient/patient-create-operation.ts
25033
24906
  async function createPatientOperation(params) {
25034
- const { context, body } = params;
24907
+ const { context, body, tableName } = params;
25035
24908
  const { tenantId, workspaceId, date, actorId, actorName } = context;
25036
24909
  const id = body.id ?? ulid99();
25037
24910
  const meta = {
@@ -25039,29 +24912,28 @@ async function createPatientOperation(params) {
25039
24912
  lastUpdated: date,
25040
24913
  versionId: "1"
25041
24914
  };
25042
- const patient = {
24915
+ const patientWithAudit = {
25043
24916
  ...body,
25044
24917
  resourceType: "Patient",
25045
24918
  id,
25046
- meta
24919
+ meta: mergeAuditIntoMeta(meta, {
24920
+ createdDate: date,
24921
+ createdById: actorId,
24922
+ createdByName: actorName,
24923
+ modifiedDate: date,
24924
+ modifiedById: actorId,
24925
+ modifiedByName: actorName
24926
+ })
25047
24927
  };
25048
- const options = {
24928
+ const service = getDynamoDataService(tableName);
24929
+ return createDataEntityRecord(
24930
+ service.entities.patient,
25049
24931
  tenantId,
25050
24932
  workspaceId,
25051
- createdDate: date,
25052
- createdById: actorId,
25053
- createdByName: actorName,
25054
- modifiedDate: date,
25055
- modifiedById: actorId,
25056
- modifiedByName: actorName
25057
- };
25058
- const service = getDynamoDataService(params.tableName);
25059
- const attrs = patientToPutAttrs(patient, options);
25060
- await service.entities.patient.put(attrs).go();
25061
- return {
25062
24933
  id,
25063
- resource: patient
25064
- };
24934
+ patientWithAudit,
24935
+ date
24936
+ );
25065
24937
  }
25066
24938
 
25067
24939
  // src/data/rest-api/routes/data/patient/patient-create-route.ts