@openfn/language-fhir-4 0.2.6 → 0.2.8

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/dist/index.cjs CHANGED
@@ -32,6 +32,7 @@ __export(src_exports, {
32
32
  cursor: () => import_language_common3.cursor,
33
33
  dataPath: () => import_language_common3.dataPath,
34
34
  dataValue: () => import_language_common3.dataValue,
35
+ datatypes: () => datatypes_exports,
35
36
  dateFns: () => import_language_common3.dateFns,
36
37
  default: () => src_default,
37
38
  delete: () => _delete,
@@ -368,6 +369,7 @@ __export(builders_exports, {
368
369
  explanationOfBenefit: () => explanationOfBenefit,
369
370
  ext: () => ext,
370
371
  extendSystemMap: () => extendSystemMap,
372
+ extendValues: () => extendValues,
371
373
  extension: () => extension,
372
374
  familyMemberHistory: () => familyMemberHistory,
373
375
  findExtension: () => findExtension,
@@ -388,8 +390,10 @@ __export(builders_exports, {
388
390
  library: () => library,
389
391
  list: () => list,
390
392
  location: () => location,
393
+ lookupValue: () => lookupValue,
391
394
  manufacturedItemDefinition: () => manufacturedItemDefinition,
392
395
  mapSystems: () => mapSystems,
396
+ mapValues: () => mapValues,
393
397
  measure: () => measure,
394
398
  measureReport: () => measureReport,
395
399
  media: () => media,
@@ -431,6 +435,7 @@ __export(builders_exports, {
431
435
  schedule: () => schedule,
432
436
  serviceRequest: () => serviceRequest,
433
437
  setSystemMap: () => setSystemMap,
438
+ setValues: () => setValues,
434
439
  slot: () => slot,
435
440
  specimen: () => specimen,
436
441
  specimenDefinition: () => specimenDefinition,
@@ -445,10 +450,64 @@ __export(builders_exports, {
445
450
  visionPrescription: () => visionPrescription
446
451
  });
447
452
 
453
+ // src/profiles/Account.ts
454
+ var import_lodash2 = __toESM(require("lodash"), 1);
455
+
448
456
  // src/datatypes.ts
457
+ var datatypes_exports = {};
458
+ __export(datatypes_exports, {
459
+ addExtension: () => addExtension,
460
+ c: () => c,
461
+ cc: () => cc,
462
+ coding: () => coding,
463
+ composite: () => composite,
464
+ concept: () => concept,
465
+ ext: () => ext,
466
+ extendSystemMap: () => extendSystemMap,
467
+ extendValues: () => extendValues,
468
+ extension: () => extension,
469
+ findExtension: () => findExtension,
470
+ id: () => id,
471
+ identifier: () => identifier,
472
+ lookupValue: () => lookupValue,
473
+ mapSystems: () => mapSystems,
474
+ mapValues: () => mapValues,
475
+ ref: () => ref,
476
+ reference: () => reference,
477
+ setSystemMap: () => setSystemMap,
478
+ setValues: () => setValues,
479
+ value: () => value
480
+ });
449
481
  var import_lodash = __toESM(require("lodash"), 1);
450
482
  var systemMap = {};
451
483
  var datetimeregex = /^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?$/;
484
+ var defaultValues = {};
485
+ var userValues = {};
486
+ var setValues = (url, values, type = "user") => {
487
+ if (type === "default") {
488
+ defaultValues[url] ?? (defaultValues[url] = {});
489
+ defaultValues[url] = values;
490
+ } else {
491
+ userValues[url] ?? (userValues[url] = {});
492
+ userValues[url] = values;
493
+ }
494
+ };
495
+ var extendValues = (url, values, type = "user") => {
496
+ if (type === "default") {
497
+ defaultValues[url] ?? (defaultValues[url] = {});
498
+ Object.assign(defaultValues[url], values);
499
+ } else {
500
+ userValues[url] ?? (userValues[url] = {});
501
+ Object.assign(userValues[url], values);
502
+ }
503
+ };
504
+ var lookupValue = (url, code) => {
505
+ var _a, _b;
506
+ let value2;
507
+ value2 = ((_a = userValues[url]) == null ? void 0 : _a[code]) ?? code;
508
+ value2 = ((_b = defaultValues[url]) == null ? void 0 : _b[value2]) ?? value2;
509
+ return value2;
510
+ };
452
511
  var mapSystems = (obj) => {
453
512
  if (Array.isArray(obj)) {
454
513
  return obj.map(mapSystems);
@@ -461,6 +520,13 @@ var mapSystems = (obj) => {
461
520
  }
462
521
  return obj;
463
522
  };
523
+ var mapValues = (obj, hints) => {
524
+ const newObj = { ...obj };
525
+ for (const key in obj) {
526
+ newObj[key] = key in hints ? lookupValue(hints[key], obj[key]) : newObj[key];
527
+ }
528
+ return newObj;
529
+ };
464
530
  var setSystemMap = (newMappings) => (state) => {
465
531
  systemMap = newMappings;
466
532
  return state;
@@ -468,20 +534,19 @@ var setSystemMap = (newMappings) => (state) => {
468
534
  var extendSystemMap = (newMappings) => {
469
535
  Object.assign(systemMap, newMappings);
470
536
  };
471
- var identifier = (id2, ...ext2) => {
537
+ var identifier = (id2, ext2 = [], valueHints = {}) => {
472
538
  if (Array.isArray(id2)) {
473
- return id2.map((i2) => identifier(i2));
539
+ return id2.map((i2) => identifier(i2, ext2, valueHints));
474
540
  }
475
- const i = {};
541
+ const i = mapValues(id2, valueHints);
476
542
  if (typeof id2 === "string") {
477
543
  i.value = id2;
478
544
  } else {
479
- if (id2.type) {
480
- id2.type = concept(id2.type);
545
+ if (i.type) {
546
+ i.type = concept(i.type);
481
547
  }
482
- Object.assign(i, id2);
483
548
  }
484
- ext2.forEach((e) => {
549
+ ext2 == null ? void 0 : ext2.forEach((e) => {
485
550
  addExtension(i, e.url, e.value);
486
551
  });
487
552
  return mapSystems(i);
@@ -511,11 +576,20 @@ var findExtension = (obj, targetUrl, path) => {
511
576
  }
512
577
  return result;
513
578
  };
514
- var coding = (code, system, extra = {}) => mapSystems({
515
- code,
516
- system,
517
- ...extra
518
- });
579
+ function coding(code, system, extra = {}) {
580
+ if (arguments.length === 1) {
581
+ if (Array.isArray(arguments[0])) {
582
+ const [code2, system2, extra2] = arguments[0];
583
+ return coding(code2, system2, extra2);
584
+ }
585
+ return mapSystems(arguments[0]);
586
+ }
587
+ return mapSystems({
588
+ code,
589
+ system,
590
+ ...extra
591
+ });
592
+ }
519
593
  var c = coding;
520
594
  var value = (value2, system, ...extra) => mapSystems({
521
595
  value: value2,
@@ -596,7 +670,6 @@ var composite = (object, key, value2) => {
596
670
  };
597
671
 
598
672
  // src/profiles/Account.ts
599
- var import_lodash2 = __toESM(require("lodash"), 1);
600
673
  function Account_default(props) {
601
674
  const resource = {
602
675
  resourceType: "Account",
@@ -3183,6 +3256,13 @@ function Encounter_default(props) {
3183
3256
  resource.statusHistory.push(_statusHistory);
3184
3257
  }
3185
3258
  }
3259
+ if (!import_lodash33.default.isNil(props.class)) {
3260
+ let src = props.class;
3261
+ if (typeof src === "string") {
3262
+ src = lookupValue("http://terminology.hl7.org/ValueSet/v3-ActEncounterCode", src);
3263
+ }
3264
+ resource.class = coding(src);
3265
+ }
3186
3266
  if (!import_lodash33.default.isNil(props.classHistory)) {
3187
3267
  let src = props.classHistory;
3188
3268
  if (!Array.isArray(src)) {
@@ -4271,6 +4351,13 @@ function ImagingStudy_default(props) {
4271
4351
  }
4272
4352
  resource.identifier = identifier(props.identifier);
4273
4353
  }
4354
+ if (!import_lodash48.default.isNil(props.modality)) {
4355
+ let src = props.modality;
4356
+ if (typeof src === "string") {
4357
+ src = lookupValue("http://dicom.nema.org/medical/dicom/current/output/chtml/part16/sect_CID_29.html", src);
4358
+ }
4359
+ resource.modality = coding(src);
4360
+ }
4274
4361
  if (!import_lodash48.default.isNil(props.subject)) {
4275
4362
  resource.subject = reference(props.subject);
4276
4363
  }
@@ -4829,6 +4916,13 @@ function Location_default(props) {
4829
4916
  }
4830
4917
  resource.identifier = identifier(props.identifier);
4831
4918
  }
4919
+ if (!import_lodash57.default.isNil(props.operationalStatus)) {
4920
+ let src = props.operationalStatus;
4921
+ if (typeof src === "string") {
4922
+ src = lookupValue("http://terminology.hl7.org/ValueSet/v2-0116", src);
4923
+ }
4924
+ resource.operationalStatus = coding(src);
4925
+ }
4832
4926
  if (!import_lodash57.default.isNil(props.type)) {
4833
4927
  if (!Array.isArray(props.type)) {
4834
4928
  props.type = [props.type];
@@ -5803,6 +5897,13 @@ function MedicinalProductDefinition_default(props) {
5803
5897
  }
5804
5898
  resource.clinicalTrial = reference(props.clinicalTrial);
5805
5899
  }
5900
+ if (!import_lodash68.default.isNil(props.code)) {
5901
+ let src = props.code;
5902
+ if (typeof src === "string") {
5903
+ src = lookupValue("http://hl7.org/fhir/ValueSet/medication-codes", src);
5904
+ }
5905
+ resource.code = coding(src);
5906
+ }
5806
5907
  if (!import_lodash68.default.isNil(props.name)) {
5807
5908
  let src = props.name;
5808
5909
  if (!Array.isArray(src)) {
@@ -6969,6 +7070,13 @@ function Questionnaire_default(props) {
6969
7070
  }
6970
7071
  resource.jurisdiction = concept(props.jurisdiction);
6971
7072
  }
7073
+ if (!import_lodash85.default.isNil(props.code)) {
7074
+ let src = props.code;
7075
+ if (typeof src === "string") {
7076
+ src = lookupValue("http://hl7.org/fhir/ValueSet/questionnaire-questions", src);
7077
+ }
7078
+ resource.code = coding(src);
7079
+ }
6972
7080
  if (!import_lodash85.default.isNil(props.item)) {
6973
7081
  let src = props.item;
6974
7082
  if (!Array.isArray(src)) {
@@ -9820,6 +9928,7 @@ var src_default = Adaptor_exports;
9820
9928
  cursor,
9821
9929
  dataPath,
9822
9930
  dataValue,
9931
+ datatypes,
9823
9932
  dateFns,
9824
9933
  delete: null,
9825
9934
  each,
package/dist/index.js CHANGED
@@ -340,6 +340,7 @@ __export(builders_exports, {
340
340
  explanationOfBenefit: () => explanationOfBenefit,
341
341
  ext: () => ext,
342
342
  extendSystemMap: () => extendSystemMap,
343
+ extendValues: () => extendValues,
343
344
  extension: () => extension,
344
345
  familyMemberHistory: () => familyMemberHistory,
345
346
  findExtension: () => findExtension,
@@ -360,8 +361,10 @@ __export(builders_exports, {
360
361
  library: () => library,
361
362
  list: () => list,
362
363
  location: () => location,
364
+ lookupValue: () => lookupValue,
363
365
  manufacturedItemDefinition: () => manufacturedItemDefinition,
364
366
  mapSystems: () => mapSystems,
367
+ mapValues: () => mapValues,
365
368
  measure: () => measure,
366
369
  measureReport: () => measureReport,
367
370
  media: () => media,
@@ -403,6 +406,7 @@ __export(builders_exports, {
403
406
  schedule: () => schedule,
404
407
  serviceRequest: () => serviceRequest,
405
408
  setSystemMap: () => setSystemMap,
409
+ setValues: () => setValues,
406
410
  slot: () => slot,
407
411
  specimen: () => specimen,
408
412
  specimenDefinition: () => specimenDefinition,
@@ -417,10 +421,64 @@ __export(builders_exports, {
417
421
  visionPrescription: () => visionPrescription
418
422
  });
419
423
 
424
+ // src/profiles/Account.ts
425
+ import _2 from "lodash";
426
+
420
427
  // src/datatypes.ts
428
+ var datatypes_exports = {};
429
+ __export(datatypes_exports, {
430
+ addExtension: () => addExtension,
431
+ c: () => c,
432
+ cc: () => cc,
433
+ coding: () => coding,
434
+ composite: () => composite,
435
+ concept: () => concept,
436
+ ext: () => ext,
437
+ extendSystemMap: () => extendSystemMap,
438
+ extendValues: () => extendValues,
439
+ extension: () => extension,
440
+ findExtension: () => findExtension,
441
+ id: () => id,
442
+ identifier: () => identifier,
443
+ lookupValue: () => lookupValue,
444
+ mapSystems: () => mapSystems,
445
+ mapValues: () => mapValues,
446
+ ref: () => ref,
447
+ reference: () => reference,
448
+ setSystemMap: () => setSystemMap,
449
+ setValues: () => setValues,
450
+ value: () => value
451
+ });
421
452
  import _ from "lodash";
422
453
  var systemMap = {};
423
454
  var datetimeregex = /^([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\.[0-9]+)?(Z|(\+|-)((0[0-9]|1[0-3]):[0-5][0-9]|14:00)))?)?)?$/;
455
+ var defaultValues = {};
456
+ var userValues = {};
457
+ var setValues = (url, values, type = "user") => {
458
+ if (type === "default") {
459
+ defaultValues[url] ?? (defaultValues[url] = {});
460
+ defaultValues[url] = values;
461
+ } else {
462
+ userValues[url] ?? (userValues[url] = {});
463
+ userValues[url] = values;
464
+ }
465
+ };
466
+ var extendValues = (url, values, type = "user") => {
467
+ if (type === "default") {
468
+ defaultValues[url] ?? (defaultValues[url] = {});
469
+ Object.assign(defaultValues[url], values);
470
+ } else {
471
+ userValues[url] ?? (userValues[url] = {});
472
+ Object.assign(userValues[url], values);
473
+ }
474
+ };
475
+ var lookupValue = (url, code) => {
476
+ var _a, _b;
477
+ let value2;
478
+ value2 = ((_a = userValues[url]) == null ? void 0 : _a[code]) ?? code;
479
+ value2 = ((_b = defaultValues[url]) == null ? void 0 : _b[value2]) ?? value2;
480
+ return value2;
481
+ };
424
482
  var mapSystems = (obj) => {
425
483
  if (Array.isArray(obj)) {
426
484
  return obj.map(mapSystems);
@@ -433,6 +491,13 @@ var mapSystems = (obj) => {
433
491
  }
434
492
  return obj;
435
493
  };
494
+ var mapValues = (obj, hints) => {
495
+ const newObj = { ...obj };
496
+ for (const key in obj) {
497
+ newObj[key] = key in hints ? lookupValue(hints[key], obj[key]) : newObj[key];
498
+ }
499
+ return newObj;
500
+ };
436
501
  var setSystemMap = (newMappings) => (state) => {
437
502
  systemMap = newMappings;
438
503
  return state;
@@ -440,20 +505,19 @@ var setSystemMap = (newMappings) => (state) => {
440
505
  var extendSystemMap = (newMappings) => {
441
506
  Object.assign(systemMap, newMappings);
442
507
  };
443
- var identifier = (id2, ...ext2) => {
508
+ var identifier = (id2, ext2 = [], valueHints = {}) => {
444
509
  if (Array.isArray(id2)) {
445
- return id2.map((i2) => identifier(i2));
510
+ return id2.map((i2) => identifier(i2, ext2, valueHints));
446
511
  }
447
- const i = {};
512
+ const i = mapValues(id2, valueHints);
448
513
  if (typeof id2 === "string") {
449
514
  i.value = id2;
450
515
  } else {
451
- if (id2.type) {
452
- id2.type = concept(id2.type);
516
+ if (i.type) {
517
+ i.type = concept(i.type);
453
518
  }
454
- Object.assign(i, id2);
455
519
  }
456
- ext2.forEach((e) => {
520
+ ext2 == null ? void 0 : ext2.forEach((e) => {
457
521
  addExtension(i, e.url, e.value);
458
522
  });
459
523
  return mapSystems(i);
@@ -483,11 +547,20 @@ var findExtension = (obj, targetUrl, path) => {
483
547
  }
484
548
  return result;
485
549
  };
486
- var coding = (code, system, extra = {}) => mapSystems({
487
- code,
488
- system,
489
- ...extra
490
- });
550
+ function coding(code, system, extra = {}) {
551
+ if (arguments.length === 1) {
552
+ if (Array.isArray(arguments[0])) {
553
+ const [code2, system2, extra2] = arguments[0];
554
+ return coding(code2, system2, extra2);
555
+ }
556
+ return mapSystems(arguments[0]);
557
+ }
558
+ return mapSystems({
559
+ code,
560
+ system,
561
+ ...extra
562
+ });
563
+ }
491
564
  var c = coding;
492
565
  var value = (value2, system, ...extra) => mapSystems({
493
566
  value: value2,
@@ -568,7 +641,6 @@ var composite = (object, key, value2) => {
568
641
  };
569
642
 
570
643
  // src/profiles/Account.ts
571
- import _2 from "lodash";
572
644
  function Account_default(props) {
573
645
  const resource = {
574
646
  resourceType: "Account",
@@ -3155,6 +3227,13 @@ function Encounter_default(props) {
3155
3227
  resource.statusHistory.push(_statusHistory);
3156
3228
  }
3157
3229
  }
3230
+ if (!_33.isNil(props.class)) {
3231
+ let src = props.class;
3232
+ if (typeof src === "string") {
3233
+ src = lookupValue("http://terminology.hl7.org/ValueSet/v3-ActEncounterCode", src);
3234
+ }
3235
+ resource.class = coding(src);
3236
+ }
3158
3237
  if (!_33.isNil(props.classHistory)) {
3159
3238
  let src = props.classHistory;
3160
3239
  if (!Array.isArray(src)) {
@@ -4243,6 +4322,13 @@ function ImagingStudy_default(props) {
4243
4322
  }
4244
4323
  resource.identifier = identifier(props.identifier);
4245
4324
  }
4325
+ if (!_48.isNil(props.modality)) {
4326
+ let src = props.modality;
4327
+ if (typeof src === "string") {
4328
+ src = lookupValue("http://dicom.nema.org/medical/dicom/current/output/chtml/part16/sect_CID_29.html", src);
4329
+ }
4330
+ resource.modality = coding(src);
4331
+ }
4246
4332
  if (!_48.isNil(props.subject)) {
4247
4333
  resource.subject = reference(props.subject);
4248
4334
  }
@@ -4801,6 +4887,13 @@ function Location_default(props) {
4801
4887
  }
4802
4888
  resource.identifier = identifier(props.identifier);
4803
4889
  }
4890
+ if (!_57.isNil(props.operationalStatus)) {
4891
+ let src = props.operationalStatus;
4892
+ if (typeof src === "string") {
4893
+ src = lookupValue("http://terminology.hl7.org/ValueSet/v2-0116", src);
4894
+ }
4895
+ resource.operationalStatus = coding(src);
4896
+ }
4804
4897
  if (!_57.isNil(props.type)) {
4805
4898
  if (!Array.isArray(props.type)) {
4806
4899
  props.type = [props.type];
@@ -5775,6 +5868,13 @@ function MedicinalProductDefinition_default(props) {
5775
5868
  }
5776
5869
  resource.clinicalTrial = reference(props.clinicalTrial);
5777
5870
  }
5871
+ if (!_68.isNil(props.code)) {
5872
+ let src = props.code;
5873
+ if (typeof src === "string") {
5874
+ src = lookupValue("http://hl7.org/fhir/ValueSet/medication-codes", src);
5875
+ }
5876
+ resource.code = coding(src);
5877
+ }
5778
5878
  if (!_68.isNil(props.name)) {
5779
5879
  let src = props.name;
5780
5880
  if (!Array.isArray(src)) {
@@ -6941,6 +7041,13 @@ function Questionnaire_default(props) {
6941
7041
  }
6942
7042
  resource.jurisdiction = concept(props.jurisdiction);
6943
7043
  }
7044
+ if (!_85.isNil(props.code)) {
7045
+ let src = props.code;
7046
+ if (typeof src === "string") {
7047
+ src = lookupValue("http://hl7.org/fhir/ValueSet/questionnaire-questions", src);
7048
+ }
7049
+ resource.code = coding(src);
7050
+ }
6944
7051
  if (!_85.isNil(props.item)) {
6945
7052
  let src = props.item;
6946
7053
  if (!Array.isArray(src)) {
@@ -9791,6 +9898,7 @@ export {
9791
9898
  cursor,
9792
9899
  dataPath,
9793
9900
  dataValue,
9901
+ datatypes_exports as datatypes,
9794
9902
  dateFns,
9795
9903
  src_default as default,
9796
9904
  _delete as delete,
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@openfn/language-fhir-4",
3
3
  "label": "FHIR r4",
4
- "version": "0.2.6",
4
+ "version": "0.2.8",
5
5
  "description": "OpenFn FHIR r4 adaptor",
6
6
  "author": "Open Function Group",
7
7
  "license": "LGPLv3",
8
8
  "type": "module",
9
9
  "fhir": {
10
10
  "specUrl": "https://hl7.org/fhir/R4B/definitions.json.zip",
11
- "adaptorGeneratedDate": "2025-11-04T12:57:02.139Z",
12
- "generatorVersion": "0.4.1",
11
+ "adaptorGeneratedDate": "2026-02-19T17:52:48.093Z",
12
+ "generatorVersion": "0.6.0",
13
13
  "options": {
14
14
  "simpleBuilders": true
15
15
  }