@openhi/constructs 0.0.176 → 0.0.178

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,6 @@
1
1
  import {
2
2
  buildSchemaBootstrapStatements
3
- } from "./chunk-XJ5SRUGN.mjs";
3
+ } from "./chunk-B6GCDQKX.mjs";
4
4
  import {
5
5
  createRoleOperation
6
6
  } from "./chunk-SD7J3N3C.mjs";
@@ -5646,6 +5646,16 @@ function jsonbPathToStringShape(jsonbPath) {
5646
5646
  if (arrayOfScalars) {
5647
5647
  return { kind: "array-of-scalars", field: arrayOfScalars[1] };
5648
5648
  }
5649
+ const arrayOfArrays = /^\$\.([A-Za-z_][A-Za-z0-9_]*)\[\*\]\.([A-Za-z_][A-Za-z0-9_]*)\[\*\]$/.exec(
5650
+ jsonbPath
5651
+ );
5652
+ if (arrayOfArrays) {
5653
+ return {
5654
+ kind: "array-of-arrays",
5655
+ field: arrayOfArrays[1],
5656
+ subfield: arrayOfArrays[2]
5657
+ };
5658
+ }
5649
5659
  const arrayOfObjs = /^\$\.([A-Za-z_][A-Za-z0-9_]*)\[\*\]\.([A-Za-z_][A-Za-z0-9_]*)$/.exec(
5650
5660
  jsonbPath
5651
5661
  );
@@ -5657,7 +5667,7 @@ function jsonbPathToStringShape(jsonbPath) {
5657
5667
  };
5658
5668
  }
5659
5669
  throw new Error(
5660
- `String predicate cannot translate JSONPath "${jsonbPath}". Supported shapes: "$.field", "$.field[*]", "$.field[*].subfield".`
5670
+ `String predicate cannot translate JSONPath "${jsonbPath}". Supported shapes: "$.field", "$.field[*]", "$.field[*].subfield", "$.field[*].subfield[*]".`
5661
5671
  );
5662
5672
  }
5663
5673
  function escapeLikePattern(value) {
@@ -5690,6 +5700,13 @@ function buildIlikeExtractSql(shape, paramName) {
5690
5700
  `jsonb_array_elements(resource->'${shape.field}') AS s_obj(obj)`,
5691
5701
  `WHERE s_obj.obj->>'${shape.subfield}' ILIKE :${paramName})`
5692
5702
  ].join(" ");
5703
+ case "array-of-arrays":
5704
+ return [
5705
+ "EXISTS (SELECT 1 FROM",
5706
+ `jsonb_array_elements(resource->'${shape.field}') AS s_obj(obj),`,
5707
+ `jsonb_array_elements_text(s_obj.obj->'${shape.subfield}') AS s_elem(text_val)`,
5708
+ `WHERE s_elem.text_val ILIKE :${paramName})`
5709
+ ].join(" ");
5693
5710
  }
5694
5711
  }
5695
5712
  function emitStringPredicate(opts) {
@@ -5930,8 +5947,8 @@ function buildGenericSearchSql(opts) {
5930
5947
  const lines = [
5931
5948
  "SELECT resource_id AS id, resource",
5932
5949
  "FROM resources",
5933
- "WHERE tenant_id = :tenantId",
5934
- " AND workspace_id = :workspaceId",
5950
+ "WHERE LOWER(tenant_id) = LOWER(:tenantId)",
5951
+ " AND LOWER(workspace_id) = LOWER(:workspaceId)",
5935
5952
  " AND LOWER(resource_type) = LOWER(:resourceType)",
5936
5953
  " AND deleted_at IS NULL"
5937
5954
  ];
@@ -5962,12 +5979,23 @@ async function genericSearchOperation(params) {
5962
5979
  ...combined.params
5963
5980
  ];
5964
5981
  const rows = await runner.query(sql, queryParams);
5965
- const entries = rows.map((row) => ({
5966
- id: row.id,
5967
- resource: { ...row.resource, id: row.id }
5968
- }));
5982
+ const entries = rows.map((row) => {
5983
+ const parsed = parseResourceColumn(row.resource);
5984
+ const bodyId = typeof parsed.id === "string" ? parsed.id : void 0;
5985
+ const id = bodyId ?? row.id;
5986
+ return {
5987
+ id,
5988
+ resource: { ...parsed, id }
5989
+ };
5990
+ });
5969
5991
  return { entries, total: entries.length };
5970
5992
  }
5993
+ function parseResourceColumn(raw) {
5994
+ if (typeof raw === "string") {
5995
+ return JSON.parse(raw);
5996
+ }
5997
+ return raw;
5998
+ }
5971
5999
 
5972
6000
  // src/data/search/registry/allergyintolerance-search-parameters.ts
5973
6001
  var ALLERGYINTOLERANCE_SEARCH_PARAMETERS = [
@@ -6568,7 +6596,7 @@ var PATIENT_SEARCH_PARAMETERS = [
6568
6596
  {
6569
6597
  code: "given",
6570
6598
  type: "string",
6571
- jsonbPath: "$.name[*].given",
6599
+ jsonbPath: "$.name[*].given[*]",
6572
6600
  modifiers: ["exact", "contains", "missing", "not"]
6573
6601
  },
6574
6602
  { code: "active", type: "token", jsonbPath: "$.active" },
@@ -6618,7 +6646,7 @@ var PRACTITIONER_SEARCH_PARAMETERS = [
6618
6646
  {
6619
6647
  code: "given",
6620
6648
  type: "string",
6621
- jsonbPath: "$.name[*].given",
6649
+ jsonbPath: "$.name[*].given[*]",
6622
6650
  modifiers: ["exact", "contains", "missing", "not"]
6623
6651
  },
6624
6652
  { code: "active", type: "token", jsonbPath: "$.active" },