@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.
- package/lib/{chunk-LZOMFHX3.mjs → chunk-3QS3WKRC.mjs} +2 -9
- package/lib/cors-options-lambda.handler.mjs +1 -1
- package/lib/data-store-postgres-replication.handler.mjs +1 -1
- package/lib/firehose-archive-transform.handler.mjs +1 -1
- package/lib/index.js +14 -2
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +15 -3
- package/lib/index.mjs.map +1 -1
- package/lib/post-authentication.handler.mjs +1 -1
- package/lib/pre-token-generation.handler.mjs +1 -1
- package/lib/rest-api-lambda.handler.js +19 -145
- package/lib/rest-api-lambda.handler.js.map +1 -1
- package/lib/rest-api-lambda.handler.mjs +18 -146
- package/lib/rest-api-lambda.handler.mjs.map +1 -1
- package/package.json +1 -1
- /package/lib/{chunk-LZOMFHX3.mjs.map → chunk-3QS3WKRC.mjs.map} +0 -0
|
@@ -36,7 +36,7 @@ module.exports = __toCommonJS(rest_api_lambda_handler_exports);
|
|
|
36
36
|
var import_serverless_express2 = __toESM(require("@codegenie/serverless-express"));
|
|
37
37
|
|
|
38
38
|
// src/data/rest-api/rest-api.ts
|
|
39
|
-
var
|
|
39
|
+
var import_node_path = __toESM(require("path"));
|
|
40
40
|
var import_express150 = __toESM(require("express"));
|
|
41
41
|
|
|
42
42
|
// src/data/middleware/normalize-json-body.ts
|
|
@@ -1488,7 +1488,7 @@ async function batchGetWithRetry(entity, keys) {
|
|
|
1488
1488
|
while (pending.length > 0) {
|
|
1489
1489
|
if (attempt > 0) {
|
|
1490
1490
|
await new Promise(
|
|
1491
|
-
(
|
|
1491
|
+
(resolve) => setTimeout(resolve, BATCH_GET_BASE_BACKOFF_MS * 2 ** (attempt - 1))
|
|
1492
1492
|
);
|
|
1493
1493
|
}
|
|
1494
1494
|
attempt++;
|
|
@@ -24928,133 +24928,8 @@ var import_express106 = __toESM(require("express"));
|
|
|
24928
24928
|
|
|
24929
24929
|
// src/data/operations/data/patient/patient-create-operation.ts
|
|
24930
24930
|
var import_ulid99 = require("ulid");
|
|
24931
|
-
|
|
24932
|
-
// src/data/import-patient.ts
|
|
24933
|
-
var import_node_fs = require("fs");
|
|
24934
|
-
var import_node_path = require("path");
|
|
24935
|
-
var import_types14 = require("@openhi/types");
|
|
24936
|
-
function extractPatient(parsed) {
|
|
24937
|
-
if (parsed && typeof parsed === "object" && "resourceType" in parsed) {
|
|
24938
|
-
const root = parsed;
|
|
24939
|
-
if (root.resourceType === "Patient" && root.id) {
|
|
24940
|
-
return root;
|
|
24941
|
-
}
|
|
24942
|
-
if (root.resourceType === "Bundle" && "entry" in parsed) {
|
|
24943
|
-
const entries = parsed.entry;
|
|
24944
|
-
if (Array.isArray(entries)) {
|
|
24945
|
-
const patientEntry = entries.find(
|
|
24946
|
-
(e) => e?.resource?.resourceType === "Patient" && e.resource.id
|
|
24947
|
-
);
|
|
24948
|
-
if (patientEntry?.resource) {
|
|
24949
|
-
return patientEntry.resource;
|
|
24950
|
-
}
|
|
24951
|
-
}
|
|
24952
|
-
}
|
|
24953
|
-
}
|
|
24954
|
-
throw new Error(
|
|
24955
|
-
"File must be a FHIR Patient resource or a Bundle containing at least one Patient entry"
|
|
24956
|
-
);
|
|
24957
|
-
}
|
|
24958
|
-
var SK12 = "CURRENT";
|
|
24959
|
-
var defaultAudit = {
|
|
24960
|
-
createdDate: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24961
|
-
createdById: "import",
|
|
24962
|
-
createdByName: "Bulk import",
|
|
24963
|
-
modifiedDate: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24964
|
-
modifiedById: "import",
|
|
24965
|
-
modifiedByName: "Bulk import"
|
|
24966
|
-
};
|
|
24967
|
-
function patientToPutAttrs(patient, options) {
|
|
24968
|
-
const {
|
|
24969
|
-
tenantId,
|
|
24970
|
-
workspaceId,
|
|
24971
|
-
createdDate,
|
|
24972
|
-
createdById,
|
|
24973
|
-
createdByName,
|
|
24974
|
-
modifiedDate,
|
|
24975
|
-
modifiedById,
|
|
24976
|
-
modifiedByName
|
|
24977
|
-
} = options;
|
|
24978
|
-
const lastUpdated = patient.meta?.lastUpdated ?? modifiedDate ?? defaultAudit.modifiedDate ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
24979
|
-
const auditMerged = {
|
|
24980
|
-
...defaultAudit,
|
|
24981
|
-
...createdDate != null && { createdDate },
|
|
24982
|
-
...createdById != null && { createdById },
|
|
24983
|
-
...createdByName != null && { createdByName },
|
|
24984
|
-
...modifiedDate != null && { modifiedDate },
|
|
24985
|
-
...modifiedById != null && { modifiedById },
|
|
24986
|
-
...modifiedByName != null && { modifiedByName }
|
|
24987
|
-
};
|
|
24988
|
-
const patientWithMeta = {
|
|
24989
|
-
...patient,
|
|
24990
|
-
meta: mergeAuditIntoMeta(patient.meta, auditMerged)
|
|
24991
|
-
};
|
|
24992
|
-
if (lastUpdated && !patientWithMeta.meta.lastUpdated) {
|
|
24993
|
-
patientWithMeta.meta.lastUpdated = lastUpdated;
|
|
24994
|
-
}
|
|
24995
|
-
return {
|
|
24996
|
-
sk: SK12,
|
|
24997
|
-
tenantId,
|
|
24998
|
-
workspaceId,
|
|
24999
|
-
id: patient.id,
|
|
25000
|
-
resource: compressResource(JSON.stringify(patientWithMeta)),
|
|
25001
|
-
summary: JSON.stringify(
|
|
25002
|
-
(0, import_types14.extractSummary)(patientWithMeta)
|
|
25003
|
-
),
|
|
25004
|
-
vid: lastUpdated.replace(/[-:T.Z]/g, "").slice(0, 12) || Date.now().toString(36),
|
|
25005
|
-
lastUpdated,
|
|
25006
|
-
identifierSystem: "",
|
|
25007
|
-
identifierValue: "",
|
|
25008
|
-
facilityId: "",
|
|
25009
|
-
normalizedName: ""
|
|
25010
|
-
};
|
|
25011
|
-
}
|
|
25012
|
-
async function importPatientFromFile(filePath, options) {
|
|
25013
|
-
const resolved = (0, import_node_path.resolve)(filePath);
|
|
25014
|
-
const raw = (0, import_node_fs.readFileSync)(resolved, "utf-8");
|
|
25015
|
-
const parsed = JSON.parse(raw);
|
|
25016
|
-
const patient = extractPatient(parsed);
|
|
25017
|
-
const service = getDynamoDataService(options.tableName);
|
|
25018
|
-
const attrs = patientToPutAttrs(patient, options);
|
|
25019
|
-
const result = await service.entities.patient.put(attrs).go();
|
|
25020
|
-
const data = result.data;
|
|
25021
|
-
if (!data) {
|
|
25022
|
-
throw new Error(`Put failed for Patient ${patient.id}`);
|
|
25023
|
-
}
|
|
25024
|
-
return {
|
|
25025
|
-
id: data.id,
|
|
25026
|
-
tenantId: data.tenantId,
|
|
25027
|
-
workspaceId: data.workspaceId
|
|
25028
|
-
};
|
|
25029
|
-
}
|
|
25030
|
-
async function main() {
|
|
25031
|
-
const [, , fileArg, tenantId = "tenant-1", workspaceId = "ws-1"] = process.argv;
|
|
25032
|
-
if (!fileArg) {
|
|
25033
|
-
console.error(
|
|
25034
|
-
"Usage: import-patient.ts <path-to-patient.json> [tenantId] [workspaceId]"
|
|
25035
|
-
);
|
|
25036
|
-
process.exit(1);
|
|
25037
|
-
}
|
|
25038
|
-
try {
|
|
25039
|
-
const result = await importPatientFromFile(fileArg, {
|
|
25040
|
-
tenantId,
|
|
25041
|
-
workspaceId
|
|
25042
|
-
});
|
|
25043
|
-
console.log(
|
|
25044
|
-
`Imported Patient ${result.id} (tenant=${result.tenantId}, workspace=${result.workspaceId})`
|
|
25045
|
-
);
|
|
25046
|
-
} catch (err) {
|
|
25047
|
-
console.error(err);
|
|
25048
|
-
process.exit(1);
|
|
25049
|
-
}
|
|
25050
|
-
}
|
|
25051
|
-
if (require.main === module) {
|
|
25052
|
-
void main();
|
|
25053
|
-
}
|
|
25054
|
-
|
|
25055
|
-
// src/data/operations/data/patient/patient-create-operation.ts
|
|
25056
24931
|
async function createPatientOperation(params) {
|
|
25057
|
-
const { context, body } = params;
|
|
24932
|
+
const { context, body, tableName } = params;
|
|
25058
24933
|
const { tenantId, workspaceId, date, actorId, actorName } = context;
|
|
25059
24934
|
const id = body.id ?? (0, import_ulid99.ulid)();
|
|
25060
24935
|
const meta = {
|
|
@@ -25062,29 +24937,28 @@ async function createPatientOperation(params) {
|
|
|
25062
24937
|
lastUpdated: date,
|
|
25063
24938
|
versionId: "1"
|
|
25064
24939
|
};
|
|
25065
|
-
const
|
|
24940
|
+
const patientWithAudit = {
|
|
25066
24941
|
...body,
|
|
25067
24942
|
resourceType: "Patient",
|
|
25068
24943
|
id,
|
|
25069
|
-
meta
|
|
24944
|
+
meta: mergeAuditIntoMeta(meta, {
|
|
24945
|
+
createdDate: date,
|
|
24946
|
+
createdById: actorId,
|
|
24947
|
+
createdByName: actorName,
|
|
24948
|
+
modifiedDate: date,
|
|
24949
|
+
modifiedById: actorId,
|
|
24950
|
+
modifiedByName: actorName
|
|
24951
|
+
})
|
|
25070
24952
|
};
|
|
25071
|
-
const
|
|
24953
|
+
const service = getDynamoDataService(tableName);
|
|
24954
|
+
return createDataEntityRecord(
|
|
24955
|
+
service.entities.patient,
|
|
25072
24956
|
tenantId,
|
|
25073
24957
|
workspaceId,
|
|
25074
|
-
createdDate: date,
|
|
25075
|
-
createdById: actorId,
|
|
25076
|
-
createdByName: actorName,
|
|
25077
|
-
modifiedDate: date,
|
|
25078
|
-
modifiedById: actorId,
|
|
25079
|
-
modifiedByName: actorName
|
|
25080
|
-
};
|
|
25081
|
-
const service = getDynamoDataService(params.tableName);
|
|
25082
|
-
const attrs = patientToPutAttrs(patient, options);
|
|
25083
|
-
await service.entities.patient.put(attrs).go();
|
|
25084
|
-
return {
|
|
25085
24958
|
id,
|
|
25086
|
-
|
|
25087
|
-
|
|
24959
|
+
patientWithAudit,
|
|
24960
|
+
date
|
|
24961
|
+
);
|
|
25088
24962
|
}
|
|
25089
24963
|
|
|
25090
24964
|
// src/data/rest-api/routes/data/patient/patient-create-route.ts
|
|
@@ -34055,7 +33929,7 @@ router149.delete("/:id", deleteVisionPrescriptionRoute);
|
|
|
34055
33929
|
// src/data/rest-api/rest-api.ts
|
|
34056
33930
|
var app = (0, import_express150.default)();
|
|
34057
33931
|
app.set("view engine", "ejs");
|
|
34058
|
-
app.set("views",
|
|
33932
|
+
app.set("views", import_node_path.default.join(__dirname, "views"));
|
|
34059
33933
|
app.use(import_express150.default.json());
|
|
34060
33934
|
app.use(import_express150.default.urlencoded({ extended: true }));
|
|
34061
33935
|
app.use(normalizeJsonBodyMiddleware);
|