@gen3/core 0.11.50 → 0.11.51

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/cjs/index.js CHANGED
@@ -2293,7 +2293,7 @@ const nestedHistogramQueryStrForEachField = (mainField, numericAggAsText)=>`
2293
2293
  }
2294
2294
  }
2295
2295
  }`;
2296
- const rawDataQueryStrForEachField = (field)=>{
2296
+ const rawDataQueryStrForEachField$1 = (field)=>{
2297
2297
  const splitFieldArray = field.split('.');
2298
2298
  const splitField = splitFieldArray.shift();
2299
2299
  if (splitFieldArray.length === 0) {
@@ -2303,10 +2303,361 @@ const rawDataQueryStrForEachField = (field)=>{
2303
2303
  }
2304
2304
  return `
2305
2305
  ${splitField} {
2306
- ${rawDataQueryStrForEachField(splitFieldArray.join('.'))}
2306
+ ${rawDataQueryStrForEachField$1(splitFieldArray.join('.'))}
2307
2307
  }`;
2308
2308
  };
2309
2309
 
2310
+ const convertNumericFromToArrayToFilters = (field, range, isNested = true)=>{
2311
+ const { from, to } = range;
2312
+ return {
2313
+ operator: 'and',
2314
+ operands: [
2315
+ isNested ? buildNestedFilterForOperation(field, {
2316
+ operator: '>=',
2317
+ field,
2318
+ operand: from
2319
+ }) : {
2320
+ operator: '>=',
2321
+ field,
2322
+ operand: from
2323
+ },
2324
+ isNested ? buildNestedFilterForOperation(field, {
2325
+ operator: '<',
2326
+ field,
2327
+ operand: to
2328
+ }) : {
2329
+ operator: '<',
2330
+ field,
2331
+ operand: to
2332
+ }
2333
+ ]
2334
+ };
2335
+ };
2336
+ const rawDataQueryStrForEachField = (field)=>{
2337
+ const splitFieldArray = field.split('.');
2338
+ const splitField = splitFieldArray.shift();
2339
+ let middleQuery = '';
2340
+ if (splitFieldArray.length === 0) {
2341
+ middleQuery = `${splitField} { histogram { count } }`;
2342
+ } else {
2343
+ middleQuery = `${splitField} { ${rawDataQueryStrForEachField(splitFieldArray.join('.'))} }`;
2344
+ }
2345
+ return middleQuery;
2346
+ };
2347
+ const buildAliasedNestedCountsQuery = ({ type, field, rangeName })=>{
2348
+ const dataParams = [
2349
+ `filter: $${rangeName}`
2350
+ ];
2351
+ const dataTypeLine = `${rangeName} : ${type} (accessibility: $accessibility ${dataParams}) {`;
2352
+ const processedFields = rawDataQueryStrForEachField(field);
2353
+ return `${dataTypeLine} ${processedFields} }`;
2354
+ };
2355
+ const buildRangeFilters = (field, ranges, filters, rangeBaseName, isNested = true)=>{
2356
+ return Object.entries(ranges).reduce((acc, [, rangeValue], idx)=>{
2357
+ acc[`${rangeBaseName}_${idx}`] = {
2358
+ mode: filters.mode,
2359
+ root: {
2360
+ ...filters.root,
2361
+ [field]: convertNumericFromToArrayToFilters(field, rangeValue, isNested)
2362
+ }
2363
+ };
2364
+ return acc;
2365
+ }, {});
2366
+ };
2367
+ const buildRangeQuery = (field, ranges, filters, rangeBaseName = 'range', index = 'cases', indexPrefix = '', isNested = true)=>{
2368
+ const rangeFilters = buildRangeFilters(field, ranges, filters, rangeBaseName, isNested);
2369
+ let query = `query rangeQuery ($accessibility: Accessibility, ${Object.keys(rangeFilters).map((rangeKey)=>`$${rangeKey}: JSON`).join(',')} ) { ${indexPrefix}_aggregation {`;
2370
+ Object.keys(rangeFilters).forEach((rangeKey)=>{
2371
+ const rangeQuery = buildAliasedNestedCountsQuery({
2372
+ type: index,
2373
+ field,
2374
+ rangeName: rangeKey
2375
+ });
2376
+ query += rangeQuery + ' \n';
2377
+ });
2378
+ query += `}}`;
2379
+ return {
2380
+ query: query,
2381
+ filters: rangeFilters
2382
+ };
2383
+ };
2384
+
2385
+ const { selectAll: selectAllCohorts, selectTotal: selectTotalCohorts, selectById: selectCohortById, selectIds: selectCohortIds } = cohortsAdapter.getSelectors((state)=>state.cohorts.cohortManager);
2386
+ /**
2387
+ * Internally used selector for the exported selectora
2388
+ * @param state
2389
+ */ const getCurrentCohortFromCoreState = (state)=>{
2390
+ return state.cohorts.cohortManager.currentCohortId;
2391
+ };
2392
+ const selectCohortFilters = (state)=>{
2393
+ const currentCohortId = getCurrentCohortFromCoreState(state);
2394
+ return state.cohorts.cohortManager.entities[currentCohortId]?.filters;
2395
+ };
2396
+ const selectCurrentCohortFilters = (state)=>{
2397
+ const currentCohortId = getCurrentCohortFromCoreState(state);
2398
+ return state.cohorts.cohortManager.entities[currentCohortId]?.filters;
2399
+ };
2400
+ const selectCurrentCohortId = (state)=>{
2401
+ return state.cohorts.cohortManager.currentCohortId;
2402
+ };
2403
+ const selectCurrentCohort = (state)=>cohortSelectors.selectById(state, getCurrentCohortFromCoreState(state));
2404
+ const selectCurrentCohortName = (state)=>cohortSelectors.selectById(state, getCurrentCohortFromCoreState(state)).name;
2405
+ /**
2406
+ * Select a filter by its name from the current cohort. If the filter is not found
2407
+ * returns undefined.
2408
+ * @param state - Core
2409
+ * @param index which cohort index to select from
2410
+ * @param name name of the filter to select
2411
+ */ const selectIndexedFilterByName = (state, index, name)=>{
2412
+ return cohortSelectors.selectById(state, getCurrentCohortFromCoreState(state)).filters[index]?.root[name];
2413
+ };
2414
+ /**
2415
+ * Returns all the cohorts in the state
2416
+ * @param state - the CoreState
2417
+ *
2418
+ * @category Cohort
2419
+ * @category Selectors
2420
+ */ const selectAvailableCohorts = (state)=>cohortSelectors.selectAll(state);
2421
+ /**
2422
+ * Returns if the current cohort is modified
2423
+ * @param state - the CoreState
2424
+ * @category Cohort
2425
+ * @category Selectors
2426
+ * @hidden
2427
+ */ const selectCurrentCohortModified = (state)=>{
2428
+ const cohort = cohortSelectors.selectById(state, getCurrentCohortFromCoreState(state));
2429
+ return cohort?.modified;
2430
+ };
2431
+ /**
2432
+ * Returns if the current cohort has been saved
2433
+ * @param state - the CoreState
2434
+ * @category Cohort
2435
+ * @category Selectors
2436
+ * @hidden
2437
+ */ const selectCurrentCohortSaved = (state)=>{
2438
+ const cohort = cohortSelectors.selectById(state, getCurrentCohortFromCoreState(state));
2439
+ return cohort?.saved;
2440
+ };
2441
+ /**
2442
+ * Select a filter by its name from the current cohort. If the filter is not found
2443
+ * returns undefined.
2444
+ * @param state - Core
2445
+ * @param name name of the filter to select
2446
+ */ const selectAvailableCohortByName = (state, name)=>cohortSelectors.selectAll(state).find((cohort)=>cohort.name === name);
2447
+ /**
2448
+ * Select a filter from the index.
2449
+ * returns undefined.
2450
+ * @param state - Core
2451
+ * @param index which cohort index to select from
2452
+ */ const selectIndexFilters = (state, index)=>{
2453
+ const cohort = cohortSelectors.selectById(state, getCurrentCohortFromCoreState(state));
2454
+ if (!cohort) {
2455
+ console.error('No Cohort Defined');
2456
+ }
2457
+ return cohort?.filters?.[index] ?? EmptyFilterSet;
2458
+ };
2459
+
2460
+ class ToGqlAllNested {
2461
+ constructor(){
2462
+ this.handleEquals = (op)=>{
2463
+ if (op.field.includes('.')) {
2464
+ const leafField = op.field.split('.').at(-1) ?? 'unset';
2465
+ return buildNestedGQLFilter(op.field, {
2466
+ '=': {
2467
+ [leafField]: op.operand
2468
+ }
2469
+ });
2470
+ }
2471
+ return {
2472
+ '=': {
2473
+ [op.field]: op.operand
2474
+ }
2475
+ };
2476
+ };
2477
+ this.handleNotEquals = (op)=>{
2478
+ if (op.field.includes('.')) {
2479
+ const leafField = op.field.split('.').at(-1) ?? 'unset';
2480
+ return buildNestedGQLFilter(op.field, {
2481
+ '!=': {
2482
+ [leafField]: op.operand
2483
+ }
2484
+ });
2485
+ }
2486
+ return {
2487
+ '!=': {
2488
+ [op.field]: op.operand
2489
+ }
2490
+ };
2491
+ };
2492
+ this.handleLessThan = (op)=>{
2493
+ if (op.field.includes('.')) {
2494
+ const leafField = op.field.split('.').at(-1) ?? 'unset';
2495
+ return buildNestedGQLFilter(op.field, {
2496
+ '<': {
2497
+ [leafField]: op.operand
2498
+ }
2499
+ });
2500
+ }
2501
+ return {
2502
+ '<': {
2503
+ [op.field]: op.operand
2504
+ }
2505
+ };
2506
+ };
2507
+ this.handleLessThanOrEquals = (op)=>{
2508
+ if (op.field.includes('.')) {
2509
+ const leafField = op.field.split('.').at(-1) ?? 'unset';
2510
+ return buildNestedGQLFilter(op.field, {
2511
+ '<=': {
2512
+ [leafField]: op.operand
2513
+ }
2514
+ });
2515
+ }
2516
+ return {
2517
+ '<=': {
2518
+ [op.field]: op.operand
2519
+ }
2520
+ };
2521
+ };
2522
+ this.handleGreaterThan = (op)=>{
2523
+ if (op.field.includes('.')) {
2524
+ const leafField = op.field.split('.').at(-1) ?? 'unset';
2525
+ return buildNestedGQLFilter(op.field, {
2526
+ '>': {
2527
+ [leafField]: op.operand
2528
+ }
2529
+ });
2530
+ }
2531
+ return {
2532
+ '>': {
2533
+ [op.field]: op.operand
2534
+ }
2535
+ };
2536
+ };
2537
+ this.handleGreaterThanOrEquals = (op)=>{
2538
+ if (op.field.includes('.')) {
2539
+ const leafField = op.field.split('.').at(-1) ?? 'unset';
2540
+ return buildNestedGQLFilter(op.field, {
2541
+ '>=': {
2542
+ [leafField]: op.operand
2543
+ }
2544
+ });
2545
+ }
2546
+ return {
2547
+ '>=': {
2548
+ [op.field]: op.operand
2549
+ }
2550
+ };
2551
+ };
2552
+ this.handleIncludes = (op)=>{
2553
+ if (op.field.includes('.')) {
2554
+ const leafField = op.field.split('.').at(-1) ?? 'unset';
2555
+ return buildNestedGQLFilter(op.field, {
2556
+ in: {
2557
+ [leafField]: op.operands
2558
+ }
2559
+ });
2560
+ }
2561
+ return {
2562
+ in: {
2563
+ [op.field]: op.operands
2564
+ }
2565
+ };
2566
+ };
2567
+ this.handleExcludes = (op)=>{
2568
+ if (op.field.includes('.')) {
2569
+ const leafField = op.field.split('.').at(-1) ?? 'unset';
2570
+ return buildNestedGQLFilter(op.field, {
2571
+ exclude: {
2572
+ [leafField]: op.operands
2573
+ }
2574
+ });
2575
+ }
2576
+ return {
2577
+ exclude: {
2578
+ [op.field]: op.operands
2579
+ }
2580
+ };
2581
+ };
2582
+ this.handleExcludeIfAny = (op)=>{
2583
+ if (op.field.includes('.')) {
2584
+ const leafField = op.field.split('.').at(-1) ?? 'unset';
2585
+ return buildNestedGQLFilter(op.field, {
2586
+ excludeifany: {
2587
+ [leafField]: op.operands
2588
+ }
2589
+ });
2590
+ }
2591
+ return {
2592
+ excludeifany: {
2593
+ [op.field]: op.operands
2594
+ }
2595
+ };
2596
+ };
2597
+ this.handleIntersection = (op)=>({
2598
+ and: op.operands.map((x)=>convertFilterToGqlFilter(x))
2599
+ });
2600
+ this.handleUnion = (op)=>({
2601
+ or: op.operands.map((x)=>convertFilterToGqlFilter(x))
2602
+ });
2603
+ this.handleMissing = (op)=>{
2604
+ if (op.field.includes('.')) {
2605
+ const leafField = op.field.split('.').at(-1) ?? 'unset';
2606
+ return buildNestedGQLFilter(op.field, {
2607
+ is: {
2608
+ [leafField]: 'MISSING'
2609
+ }
2610
+ });
2611
+ }
2612
+ return {
2613
+ is: {
2614
+ [op.field]: 'MISSING'
2615
+ }
2616
+ };
2617
+ };
2618
+ this.handleExists = (op)=>{
2619
+ if (op.field.includes('.')) {
2620
+ const leafField = op.field.split('.').at(-1) ?? 'unset';
2621
+ return buildNestedGQLFilter(op.field, {
2622
+ not: {
2623
+ [leafField]: op?.operand ?? null
2624
+ }
2625
+ });
2626
+ }
2627
+ return {
2628
+ not: {
2629
+ [op.field]: op?.operand ?? null
2630
+ }
2631
+ };
2632
+ };
2633
+ this.handleNestedFilter = (op)=>{
2634
+ const child = convertFilterToGqlFilter(op.operand);
2635
+ return {
2636
+ nested: {
2637
+ path: op.path,
2638
+ ...child
2639
+ }
2640
+ };
2641
+ };
2642
+ }
2643
+ }
2644
+ const convertFilterToNestedGqlFilter = (filter)=>{
2645
+ const handler = new ToGqlAllNested();
2646
+ return handleOperation(handler, filter);
2647
+ };
2648
+ const convertFilterSetToNestedGqlFilter = (fs, toplevelOp = 'and')=>{
2649
+ const fsKeys = Object.keys(fs.root);
2650
+ // if no keys return undefined
2651
+ if (fsKeys.length === 0) return {
2652
+ and: []
2653
+ };
2654
+ return toplevelOp === 'and' ? {
2655
+ and: fsKeys.map((key)=>convertFilterToNestedGqlFilter(fs.root[key]))
2656
+ } : {
2657
+ or: fsKeys.map((key)=>convertFilterToNestedGqlFilter(fs.root[key]))
2658
+ };
2659
+ };
2660
+
2310
2661
  const statusEndpoint = '/_status';
2311
2662
  const fetchJson = async (url)=>{
2312
2663
  const res = await fetch(url, {
@@ -2399,7 +2750,7 @@ const explorerTags = guppyApi.enhanceEndpoints({
2399
2750
  const dataTypeLine = `${indexPrefix}${type} (accessibility: ${accessibility}, offset: ${offset}, first: ${size},
2400
2751
  ${dataParams}) {`;
2401
2752
  const typeAggsLine = `${type} (${gqlFilter && `filter: $${filterName},`} accessibility: ${accessibility}) {`;
2402
- const processedFields = fields.map((field)=>rawDataQueryStrForEachField(field));
2753
+ const processedFields = fields.map((field)=>rawDataQueryStrForEachField$1(field));
2403
2754
  const query = `${queryLine}
2404
2755
  ${dataTypeLine}
2405
2756
  ${processedFields.join(' ')}
@@ -2630,6 +2981,23 @@ const explorerTags = guppyApi.enhanceEndpoints({
2630
2981
  return {};
2631
2982
  }
2632
2983
  }),
2984
+ customRange: builder.query({
2985
+ query: ({ filters, field, ranges, rangeBaseName, index, indexPrefix, accessibility = Accessibility.ALL, isNested = true })=>{
2986
+ // remove field from FilterSet
2987
+ const queryData = buildRangeQuery(field, ranges, filters, rangeBaseName, index, indexPrefix, isNested);
2988
+ const gqlFilters = Object.entries(queryData.filters).reduce((acc, [key, filter])=>{
2989
+ acc[key] = isNested ? convertFilterSetToNestedGqlFilter(filter) : convertFilterSetToGqlFilter(filter);
2990
+ return acc;
2991
+ }, {});
2992
+ return {
2993
+ query: queryData.query,
2994
+ variables: {
2995
+ accessibility,
2996
+ ...gqlFilters
2997
+ }
2998
+ };
2999
+ }
3000
+ }),
2633
3001
  generalGQL: builder.query({
2634
3002
  query: ({ query, variables })=>{
2635
3003
  return {
@@ -2695,7 +3063,7 @@ const buildGetStatsAggregationQuery = (type, fields, filters, accessibility = Ac
2695
3063
  };
2696
3064
  return queryBody;
2697
3065
  };
2698
- const { useGetRawDataAndTotalCountsQuery, useGetAccessibleDataQuery, useGetAllFieldsForTypeQuery, useGetAggsQuery, useLazyGetAggsQuery, useGetStatsAggregationsQuery, useLazyGetStatsAggregationsQuery, useGetSubAggsQuery, useGetCountsQuery, useLazyGetCountsQuery, useGetFieldCountSummaryQuery, useGetFieldsForIndexQuery, useGetSharedFieldsForIndexQuery, useGeneralGQLQuery, useLazyGeneralGQLQuery } = explorerApi;
3066
+ const { useGetRawDataAndTotalCountsQuery, useGetAccessibleDataQuery, useGetAllFieldsForTypeQuery, useGetAggsQuery, useLazyGetAggsQuery, useGetStatsAggregationsQuery, useLazyGetStatsAggregationsQuery, useGetSubAggsQuery, useGetCountsQuery, useLazyGetCountsQuery, useGetFieldCountSummaryQuery, useGetFieldsForIndexQuery, useGetSharedFieldsForIndexQuery, useGeneralGQLQuery, useLazyGeneralGQLQuery, useCustomRangeQuery, useLazyCustomRangeQuery } = explorerApi;
2699
3067
 
2700
3068
  /**
2701
3069
  * Defines coreListeners for adding middleware.
@@ -3722,81 +4090,6 @@ class CohortStorage {
3722
4090
  }
3723
4091
  }
3724
4092
 
3725
- const { selectAll: selectAllCohorts, selectTotal: selectTotalCohorts, selectById: selectCohortById, selectIds: selectCohortIds } = cohortsAdapter.getSelectors((state)=>state.cohorts.cohortManager);
3726
- /**
3727
- * Internally used selector for the exported selectora
3728
- * @param state
3729
- */ const getCurrentCohortFromCoreState = (state)=>{
3730
- return state.cohorts.cohortManager.currentCohortId;
3731
- };
3732
- const selectCohortFilters = (state)=>{
3733
- const currentCohortId = getCurrentCohortFromCoreState(state);
3734
- return state.cohorts.cohortManager.entities[currentCohortId]?.filters;
3735
- };
3736
- const selectCurrentCohortFilters = (state)=>{
3737
- const currentCohortId = getCurrentCohortFromCoreState(state);
3738
- return state.cohorts.cohortManager.entities[currentCohortId]?.filters;
3739
- };
3740
- const selectCurrentCohortId = (state)=>{
3741
- return state.cohorts.cohortManager.currentCohortId;
3742
- };
3743
- const selectCurrentCohort = (state)=>cohortSelectors.selectById(state, getCurrentCohortFromCoreState(state));
3744
- const selectCurrentCohortName = (state)=>cohortSelectors.selectById(state, getCurrentCohortFromCoreState(state)).name;
3745
- /**
3746
- * Select a filter by its name from the current cohort. If the filter is not found
3747
- * returns undefined.
3748
- * @param state - Core
3749
- * @param index which cohort index to select from
3750
- * @param name name of the filter to select
3751
- */ const selectIndexedFilterByName = (state, index, name)=>{
3752
- return cohortSelectors.selectById(state, getCurrentCohortFromCoreState(state)).filters[index]?.root[name];
3753
- };
3754
- /**
3755
- * Returns all the cohorts in the state
3756
- * @param state - the CoreState
3757
- *
3758
- * @category Cohort
3759
- * @category Selectors
3760
- */ const selectAvailableCohorts = (state)=>cohortSelectors.selectAll(state);
3761
- /**
3762
- * Returns if the current cohort is modified
3763
- * @param state - the CoreState
3764
- * @category Cohort
3765
- * @category Selectors
3766
- * @hidden
3767
- */ const selectCurrentCohortModified = (state)=>{
3768
- const cohort = cohortSelectors.selectById(state, getCurrentCohortFromCoreState(state));
3769
- return cohort?.modified;
3770
- };
3771
- /**
3772
- * Returns if the current cohort has been saved
3773
- * @param state - the CoreState
3774
- * @category Cohort
3775
- * @category Selectors
3776
- * @hidden
3777
- */ const selectCurrentCohortSaved = (state)=>{
3778
- const cohort = cohortSelectors.selectById(state, getCurrentCohortFromCoreState(state));
3779
- return cohort?.saved;
3780
- };
3781
- /**
3782
- * Select a filter by its name from the current cohort. If the filter is not found
3783
- * returns undefined.
3784
- * @param state - Core
3785
- * @param name name of the filter to select
3786
- */ const selectAvailableCohortByName = (state, name)=>cohortSelectors.selectAll(state).find((cohort)=>cohort.name === name);
3787
- /**
3788
- * Select a filter from the index.
3789
- * returns undefined.
3790
- * @param state - Core
3791
- * @param index which cohort index to select from
3792
- */ const selectIndexFilters = (state, index)=>{
3793
- const cohort = cohortSelectors.selectById(state, getCurrentCohortFromCoreState(state));
3794
- if (!cohort) {
3795
- console.error('No Cohort Defined');
3796
- }
3797
- return cohort?.filters?.[index] ?? EmptyFilterSet;
3798
- };
3799
-
3800
4093
  const isFileItem = (item)=>{
3801
4094
  return item && 'guid' in item;
3802
4095
  };
@@ -6129,7 +6422,7 @@ exports.prependIndexToFieldName = prependIndexToFieldName;
6129
6422
  exports.processHistogramResponse = processHistogramResponse;
6130
6423
  exports.projectCodeFromResourcePath = projectCodeFromResourcePath;
6131
6424
  exports.queryMultipleMDSRecords = queryMultipleMDSRecords;
6132
- exports.rawDataQueryStrForEachField = rawDataQueryStrForEachField;
6425
+ exports.rawDataQueryStrForEachField = rawDataQueryStrForEachField$1;
6133
6426
  exports.registerDefaultRemoteSupport = registerDefaultRemoteSupport;
6134
6427
  exports.removeCohort = removeCohort;
6135
6428
  exports.removeCohortFilter = removeCohortFilter;
@@ -6215,6 +6508,7 @@ exports.useCoreDispatch = useCoreDispatch;
6215
6508
  exports.useCoreSelector = useCoreSelector;
6216
6509
  exports.useCreateAuthzResourceMutation = useCreateAuthzResourceMutation;
6217
6510
  exports.useCreateRequestMutation = useCreateRequestMutation;
6511
+ exports.useCustomRangeQuery = useCustomRangeQuery;
6218
6512
  exports.useDataLibrary = useDataLibrary;
6219
6513
  exports.useDownloadFromGuppyQuery = useDownloadFromGuppyQuery;
6220
6514
  exports.useFetchUserDetailsQuery = useFetchUserDetailsQuery;
@@ -6273,6 +6567,7 @@ exports.useGraphQLQuery = useGraphQLQuery;
6273
6567
  exports.useIsExternalConnectedQuery = useIsExternalConnectedQuery;
6274
6568
  exports.useIsUserLoggedIn = useIsUserLoggedIn;
6275
6569
  exports.useLaunchWorkspaceMutation = useLaunchWorkspaceMutation;
6570
+ exports.useLazyCustomRangeQuery = useLazyCustomRangeQuery;
6276
6571
  exports.useLazyDownloadFromGuppyQuery = useLazyDownloadFromGuppyQuery;
6277
6572
  exports.useLazyFetchUserDetailsQuery = useLazyFetchUserDetailsQuery;
6278
6573
  exports.useLazyGeneralGQLQuery = useLazyGeneralGQLQuery;