-
Notifications
You must be signed in to change notification settings - Fork 12
/
ResultsTable.jsx
1102 lines (1047 loc) · 42.8 KB
/
ResultsTable.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import React from 'react';
import { Link } from 'react-router-dom';
import {
TableContainer, Table, TableHead, TableBody, TableCell, TableRow,
Collapse, IconButton, Box, Paper, Tabs, Tab, Checkbox, TableSortLabel, Tooltip,
FormControlLabel, Switch, Skeleton
} from '@mui/material';
import {
KeyboardArrowDown as KeyboardArrowDownIcon,
KeyboardArrowUp as KeyboardArrowUpIcon,
Flag as FlagIcon,
ArrowForward as ForwardIcon,
Public as PublicIcon,
Lock as PrivateIcon,
Warning as WarningIcon,
PriorityHigh as PriorityIcon,
InfoOutlined as HighlightIcon
} from '@mui/icons-material'
import { TablePagination } from '@mui/material';
import {
map, startCase, get, without, uniq, includes, find, keys, values, isEmpty, filter, reject, has,
isFunction, compact, flatten, last, isArray, times, every, forEach
} from 'lodash';
import {
BLUE, WHITE, COLOR_ROW_SELECTED, ORANGE, GREEN, EMPTY_VALUE
} from '../../common/constants';
import {
formatDateTime, headFirst, isLoggedIn, defaultCreatePin, defaultDeletePin,
getCurrentUserUsername, isCurrentUserMemberOf, isAdminUser, currentUserHasAccess, getAppliedServerConfig,
} from '../../common/utils';
import ReleasedChip from '../common/ReleasedChip';
import AllMappingsTables from '../mappings/AllMappingsTables';
import APIService from '../../services/APIService';
import PinIcon from '../common/PinIcon';
import MappingOptions from '../mappings/MappingOptions';
import { ALL_COLUMNS, TAGS, CODE_SYSTEM_VERSION_TAGS, HIGHLIGHT_ICON_WHITELISTED_FILEDS } from './ResultConstants'
import SelectedResourceControls from './SelectedResourceControls';
import FhirContainerResource from '../fhir/ContainerResource';
import { HtmlToolTipClone as HtmlToolTipNormalRaw } from '../common/HtmlToolTipRaw'
const getColumns = definition => isFunction(definition) ? definition() : definition
const RESOURCE_DEFINITIONS = {
references: {
headBgColor: BLUE,
headTextColor: WHITE,
columns: getColumns(ALL_COLUMNS.references).slice(0, 3),
},
concepts: {
headBgColor: BLUE,
headTextColor: WHITE,
columns: getColumns(ALL_COLUMNS.concepts).slice(0, 7),
tabs: ['Mappings', 'Synonyms', 'Descriptions', 'History',],
expandible: false,
},
mappings: {
headBgColor: BLUE,
headTextColor: WHITE,
columns: getColumns(ALL_COLUMNS.mappings).slice(0, 7),
tabs: ['History',],
expandible: false,
},
sources: {
headBgColor: GREEN,
headTextColor: WHITE,
columns: getColumns(ALL_COLUMNS.sources).slice(0, 4),
tagWaitAttribute: 'summary',
tags: TAGS.sources,
tabs: ['Versions',],
expandible: false,
pinnable: true,
},
collections: {
headBgColor: GREEN,
headTextColor: WHITE,
columns: getColumns(ALL_COLUMNS.collections).slice(0, 4),
tagWaitAttribute: 'summary',
tags: TAGS.collections,
tabs: ['Versions'],
expandible: false,
pinnable: true,
},
organizations: {
headBgColor: ORANGE,
headTextColor: WHITE,
columns: getColumns(ALL_COLUMNS.organizations).slice(0, 3),
tags: TAGS.organizations,
expandible: false,
pinnable: true,
},
users: {
headBgColor: ORANGE,
headTextColor: WHITE,
columns: getColumns(ALL_COLUMNS.users).slice(0, 3),
tags: TAGS.users,
expandible: false,
},
CodeSystem: {
headBgColor: GREEN,
headTextColor: WHITE,
columns: getColumns(ALL_COLUMNS.CodeSystem),
tagWaitAttribute: 'resource',
tags: TAGS.CodeSystem,
expandible: true,
tabs: ['Details', 'Versions', 'Copyright'],
},
ValueSet: {
headBgColor: GREEN,
headTextColor: WHITE,
columns: getColumns(ALL_COLUMNS.ValueSet),
tagWaitAttribute: 'resource',
tags: TAGS.ValueSet,
getTags: hapi => hapi ? TAGS.ValueSet : null,
expandible: true,
tabs: ['Details', 'Versions', 'Copyright'],
},
ConceptMap: {
headBgColor: BLUE,
headTextColor: WHITE,
columns: getColumns(ALL_COLUMNS.ConceptMap),
tagWaitAttribute: 'resource',
expandible: true,
tabs: ['Details', 'Versions', 'Copyright'],
},
}
const getValue = (item, column, refTranslation) => {
const value = get(item, column.value, '')
if(get(column, 'formatter') && value)
return column.formatter(value)
if(get(column, 'renderer'))
return column.translation ? column.renderer(item, refTranslation) : column.renderer(item)
if(isArray(value))
return value.join(', ')
return value
}
const getTag = (tag, item, hapi) => {
const formatCount = count => count === null ? '-' : count.toLocaleString()
const value = isFunction(tag.getValue) ? tag.getValue(item, hapi) : formatCount(get(item, tag.value, null));
const icon = isFunction(tag.getIcon) ? tag.getIcon(item) : tag.icon;
const getTagDom = () => (
<div style={{fontSize: '14px', lineHeight: '0px', marginBottom: '2px', ...(tag.style || {})}}>
<div className='flex-vertical-center'>
<span>{icon}</span>
{
!tag.noCount &&
<span style={{padding: '2px'}}>{value}</span>
}
</div>
</div>
);
return (
<React.Fragment key={tag.id}>
{
tag.noTooltip ?
getTagDom() :
<Tooltip title={tag.label} key={tag.id}>
{
getTagDom()
}
</Tooltip>
}
</React.Fragment>
);
}
const FHIRHistoryTable = ({ versions, resource }) => {
const isValueSet = resource === 'ValueSet'
const isCodeSystem = resource === 'CodeSystem'
const getVersionLabel = version => {
const versionName = version.resource.version
const changeId = get(version, 'resource.meta.versionId')
if(isValueSet && versionName !== changeId && versionName && changeId)
return `${versionName} (${changeId})`
return versionName || changeId
}
return (
<Table size="small" aria-label="versions">
<TableHead>
<TableRow>
{ isValueSet && <TableCell /> }
<TableCell align='center'>Version</TableCell>
<TableCell align='left'>Status</TableCell>
<TableCell align='left'>Content</TableCell>
<TableCell align='left'>Release Date</TableCell>
{ isCodeSystem && <TableCell /> }
</TableRow>
</TableHead>
<TableBody>
{
map(versions, (version, index) => {
const versionLabel = getVersionLabel(version)
return (
<TableRow hover key={versionLabel + '-' + index}>
{
isValueSet &&
<TableCell align='center'>
<span className='flex-vertical-center'>
{
get(version, 'resource.experimental') &&
<Tooltip arrow title='For testing purposes, not real usage'>
<span className='flex-vertical-center'>
<WarningIcon fontSize='small' style={{marginTop: '2px'}} />
</span>
</Tooltip>
}
{
get(version, 'resource.immutable') &&
<Tooltip arrow title='Changes to the content logical definition may occur'>
<span className='flex-vertical-center'>
<PriorityIcon fontSize='small' style={{marginTop: '2px'}} />
</span>
</Tooltip>
}
</span>
</TableCell>
}
<TableCell align='center'> { versionLabel } </TableCell>
<TableCell align='left'> { version.resource.status } </TableCell>
<TableCell align='left'> { version.resource.content } </TableCell>
<TableCell align='left'> { formatDateTime(version.resource.date) } </TableCell>
{
isCodeSystem &&
<TableCell align='left'>
{ map(CODE_SYSTEM_VERSION_TAGS, tag => getTag(tag, version)) }
</TableCell>
}
</TableRow>
)
})
}
</TableBody>
</Table>
)
}
const HistoryTable = ({ versions }) => {
return (
<Table size="small" aria-label="versions">
<TableHead>
<TableRow>
<TableCell align='center'>Version</TableCell>
<TableCell align='left'>Comment/Description</TableCell>
<TableCell align='left'>Created By</TableCell>
<TableCell align='left'>Created On</TableCell>
<TableCell />
</TableRow>
</TableHead>
<TableBody>
{
map(headFirst(versions), version => (
<TableRow hover key={version.version || version.uuid || version.id}>
<TableCell align='center'>
{ version.version || version.uuid || version.id }
</TableCell>
<TableCell align='left'>
{ version.update_comment || version.description }
</TableCell>
<TableCell align='left'>
{ version.version_created_by }
</TableCell>
<TableCell align='left'>
{ formatDateTime(version.version_created_on || version.created_at) }
</TableCell>
{
version.released ?
<TableCell align='center'><ReleasedChip /></TableCell> :
<TableCell />
}
</TableRow>
))
}
</TableBody>
</Table>
);
}
const LocalesTable = ({ locales, isDescription }) => {
const nameAttr = isDescription ? 'description' : 'name';
const typeAttr = isDescription ? 'description_type' : 'name_type';
return (
<Table size="small" aria-label="locales">
<TableHead>
<TableRow>
<TableCell align='right'>ID</TableCell>
<TableCell align='left'>Type</TableCell>
<TableCell align='left'>{startCase(nameAttr)}</TableCell>
<TableCell align='left'>External ID</TableCell>
</TableRow>
</TableHead>
<TableBody>
{
isEmpty(locales) ?
<TableRow colSpan='5'>
<TableCell colSpan='6' align='center'>No Records</TableCell>
</TableRow> :
map(locales, locale => (
<TableRow hover key={locale.uuid}>
<TableCell align='right' style={{width: '100px'}}>
<span className='flex-vertical-center'>
{
locale.locale_preferred &&
<span style={{marginRight: '5px'}}>
<Tooltip arrow title={`Preferred ${nameAttr} for this locale`} placement='top-start'>
<FlagIcon color='secondary' fontSize='small' style={{width: '18px', marginTop: '4px'}}/>
</Tooltip>
</span>
}
{
locale.external_id &&
<span style={{marginRight: '5px'}}>
<Tooltip arrow title={`External ID: ${locale.external_id}`} placement='top-start'>
<ForwardIcon
fontSize='small'
color='secondary'
style={{
border: '1px solid', borderRadius: '10px',
background: 'gray', color: 'white',
width: '18px',
height: '18px',
marginTop: '4px'
}}
/>
</Tooltip>
</span>
}
<span> { locale.uuid } </span>
</span>
</TableCell>
<TableCell align='left'>{ startCase(get(locale, typeAttr)) || EMPTY_VALUE }</TableCell>
<TableCell align='left' className='ellipsis-text'>
<span className='gray-italics-small'>{`[${locale.locale}]`}</span>
<span>{ get(locale, nameAttr) }</span>
</TableCell>
<TableCell align='left'>{ locale.external_id || EMPTY_VALUE }</TableCell>
</TableRow>
))
}
</TableBody>
</Table>
);
}
const ExpandibleRow = props => {
const {
item, resourceDefinition, resource, isSelected, isSelectable, onPinCreate, onPinDelete, pins,
showPin, columns, hapi, fhir, history, asReference, lastSelected, refTranslation
} = props;
const [isFetchingMappings, setIsFetchingMappings] = React.useState(true);
const [mappings, setMappings] = React.useState([]);
const [versions, setVersions] = React.useState([]);
const [names, setNames] = React.useState([]);
const [descriptions, setDescriptions] = React.useState([]);
const [open, setOpen] = React.useState(false);
const [pinned, setPin] = React.useState(() => includes(map(pins, 'resource_uri'), item.url));
const [tab, setTab] = React.useState(0);
const [selected, setSelected] = React.useState(isSelected);
const isConceptContainer = includes(['sources', 'collections'], resource);
const isSourceChild = includes(['concepts', 'mappings'], resource)
const isValueSet = resource === 'ValueSet';
const isConceptMap = resource === 'ConceptMap';
const isPublic = includes(['view', 'edit'], get(item, 'public_access', '').toLowerCase()) && isConceptContainer;
const pinId = get(find(pins, {resource_uri: item.url}), 'id');
const tags = resourceDefinition.getTags ? resourceDefinition.getTags(hapi) : resourceDefinition.tags;
const columnsCount = get(columns, 'length', 1) +
((isConceptContainer || isValueSet || isConceptMap) ? 1 : 0) + //public column
(isSelectable ? 1 : 0) + // select column
((resourceDefinition.expandible || showPin) ? 1 : 0) + // expand icon column
(tags ? 1 : 0); //tags column
React.useEffect(() => setPin(includes(map(pins, 'resource_uri'), item.url)), [pins]);
React.useEffect(() => setSelected(isSelected), [isSelected]);
const onClick = event => {
if(!resourceDefinition.expandible)
return;
event.stopPropagation()
event.preventDefault()
setOpen(prevOpen => {
const newOpen = !prevOpen
if(newOpen) {
fetchVersions();
if(resource === 'concepts') {
fetchNames();
fetchDescriptions();
fetchMappings();
}
}
return newOpen
})
}
const getPinService = pinId => {
const username = get(props, 'match.params.user') || getCurrentUserUsername();
const orgId = get(props, 'match.params.org');
let service = null;
if(orgId && (isCurrentUserMemberOf(orgId) || isAdminUser()))
service = APIService.orgs(orgId)
else if(username && isLoggedIn())
service = APIService.users(username)
if(service) {
if(pinId)
return service.pins(pinId)
return service.pins()
}
}
const createPin = (resourceType, resourceId) => {
if(onPinCreate)
onPinCreate(resourceType, resourceId)
else
defaultCreatePin(resourceType, resourceId, getPinService())
}
const deletePin = pinId => {
if(onPinDelete)
onPinDelete(pinId)
else
defaultDeletePin(getPinService(pinId))
}
const onPinClick = event => {
if(!showPin)
return;
event.stopPropagation()
event.preventDefault()
pinned ? deletePin(pinId) : createPin(item.type, item.uuid);
return false;
}
const onRowClick = event => {
if(asReference)
return;
if(includes(['references'], resource))
return
event.stopPropagation();
event.preventDefault()
let url;
if(fhir) {
if(hapi)
url = `/fhir/${resource}/${item.resource.id}`;
else
url = `/fhir${getOCLFHIRResourceURL(item)}`
} else {
if(props.containerOnSelectChange) {
event.persist()
onCheckboxClick(event)
} else {
if(isSourceChild) {
event.persist()
onCheckboxClick(event)
}
else
url = item.url
}
};
if(url)
history.push(url)
}
const handleTabChange = (event, newValue) => setTab(newValue);
const getOCLFHIRResourceURL = item => {
const identifiers = flatten([get(item, 'resource.identifier', [])])
let ident = find(identifiers, ident => get(ident, 'system', '').match('fhir.'))
if(!ident)
ident = find(identifiers, ident => get(ident, 'system', '').match('api.'))
return '/' + compact(get(ident, 'value', '').split('/')).splice(0, 4).join('/')
};
const fetchVersions = () => {
if(fhir) {
if(hapi) {
const baseURI = get(getAppliedServerConfig(), 'info.baseURI')
const resourceType = get(item, 'resource.resourceType')
const resourceId = get(item, 'resource.id')
if(resourceType && resourceId)
APIService.new().overrideURL(`${baseURI}${resourceType}/${resourceId}/_history/?_total=accurate&_sort=-date`).get().then(response => {
if(response.status === 200)
setVersions(response.data.entry)
})
} else {
const uri = getOCLFHIRResourceURL(item);
if(uri)
APIService.new().overrideURL(uri).appendToUrl('/version/').get().then(response => {
if(response.status === 200)
setVersions(response.data.entry)
})
}
} else {
if(item.url) {
APIService.new().overrideURL(item.url)
.appendToUrl('versions/')
.get()
.then(response => {
if(response.status === 200)
setVersions(response.data)
})
}
}
}
const fetchNames = () => {
if(item) {
APIService.new().overrideURL(item.url)
.appendToUrl('names/')
.get()
.then(response => {
if(response.status === 200)
setNames(response.data)
})
}
}
const fetchDescriptions = () => {
if(item) {
APIService.new().overrideURL(item.url)
.appendToUrl('descriptions/')
.get()
.then(response => {
if(response.status === 200)
setDescriptions(response.data)
})
}
}
const fetchMappings = () => {
if(item) {
APIService.new().overrideURL(item.url)
.appendToUrl('mappings/')
.get(null, null, {includeInverseMappings: true})
.then(response => {
setIsFetchingMappings(false)
if(response.status === 200)
setMappings(response.data)
})
}
}
const onCheckboxClick = event => {
setSelected(prevSelected => {
const newValue = !prevSelected;
props.onSelectChange(item.uuid, newValue)
return newValue;
})
event.stopPropagation();
event.preventDefault();
}
const getTab = label => {
return (
<Tab key={label} label={label} style={{fontSize: '12px', fontWeight: 'bold'}} />
)
}
const navigateTo = (event, item, url) => {
let _url = isFunction(url) ? url(item, hapi) : url;
if(!isConceptContainer && !fhir)
_url = url.replace('/versions', '/history')
event.stopPropagation()
event.preventDefault()
window.location.hash = _url
}
const getHighlightText = () => {
let texts = []
forEach(item?.search_meta?.search_highlight, (values, key) => {
let _text = ''
if(['same_as_map_codes', 'other_map_codes'].includes(key))
_text += startCase(key.replace('map_codes', '')) + ' Map Code'
else
_text += startCase(key)
_text += ': ' + map(values, value => value.replace('<em>', '<b>').replace('</em>', '</b>')).join(', ')
texts.push(_text)
})
return texts.join('<br />')
}
const hasSearchMeta = (isConceptContainer || isSourceChild) && has(item, 'search_meta.search_highlight')
const shouldShowHighlightIcon = hasSearchMeta && every(keys(item?.search_meta.search_highlight), key => includes(get(HIGHLIGHT_ICON_WHITELISTED_FILEDS, resource), key))
const highlightedText = getHighlightText()
return (
<React.Fragment>
<TableRow
hover
style={selected ? {backgroundColor: (item.uuid === lastSelected && isSourceChild) ? 'rgb(190, 209, 226)' : COLOR_ROW_SELECTED, cursor: 'pointer'} : {cursor: 'pointer'}}
onClick={onRowClick}>
{
isConceptContainer &&
<TableCell align='center'>
{
isPublic ?
<Tooltip arrow title='Public'>
<span className='flex-vertical-center' style={{marginTop: '5px'}}>
<PublicIcon fontSize='small' />
</span>
</Tooltip> :
<Tooltip arrow title='Private'>
<span className='flex-vertical-center' style={{marginTop: '5px'}}>
<PrivateIcon fontSize='small' />
</span>
</Tooltip>
}
</TableCell>
}
{
(isValueSet || isConceptMap) &&
<TableCell align='center'>
<span className='flex-vertical-center'>
{
get(item, 'resource.experimental') &&
<Tooltip arrow title='For testing purposes, not real usage'>
<span className='flex-vertical-center'>
<WarningIcon fontSize='small' style={{marginTop: '2px'}} />
</span>
</Tooltip>
}
{
get(item, 'resource.immutable') &&
<Tooltip arrow title='Changes to the content logical definition may occur'>
<span className='flex-vertical-center'>
<PriorityIcon fontSize='small' style={{marginTop: '2px'}} />
</span>
</Tooltip>
}
</span>
</TableCell>
}
{
isSelectable &&
<TableCell style={{maxWidth: '30px', padding: '2px'}} align="center">
<Checkbox size='small' style={{padding: '0px'}} checked={selected} onClick={onCheckboxClick} />
</TableCell>
}
{
map(columns, column => (
<TableCell key={column.id} align={column.align || 'left'} className={column.className}>
{ getValue(item, column, refTranslation) }
</TableCell>
))
}
{
!isSelectable &&
<TableCell align='right' style={{width: '120px', padding: '2px', paddingRight: '10px'}}>
{
resourceDefinition.tagWaitAttribute && !has(item, resourceDefinition.tagWaitAttribute) ?
map(tags, tag => <span key={tag.id} style={{display: 'flex', justifyContent: 'flex-end', margin: '2px 0', marginRight: '10px'}}><Skeleton variant='circular' height={20} width={20} /></span>) :
map(tags, tag => tag.text ? getTag(tag, item, hapi) : (
<Link key={tag.id} to='' onClick={event => navigateTo(event, item, isFunction(tag.hrefAttr) ? tag.hrefAttr : get(item, tag.hrefAttr))}>
{getTag(tag, item, hapi)}
</Link>
))
}
</TableCell>
}
{
(resourceDefinition.expandible || showPin) &&
<TableCell align='right' style={{width: '50px'}}>
{
resourceDefinition.expandible &&
(
resource === 'mappings' ?
<MappingOptions mapping={item} /> :
<IconButton aria-label="expand row" size="small" onClick={onClick}>
{open ? <KeyboardArrowUpIcon /> : <KeyboardArrowDownIcon />}
</IconButton>
)
}
{
showPin &&
<IconButton aria-label="expand row" size="small" onClick={onPinClick}>
<PinIcon fontSize="small" pinned={pinned ? pinned.toString() : undefined} />
</IconButton>
}
</TableCell>
}
{
hasSearchMeta &&
<TableCell align='right' style={{width: '50px'}}>
{
shouldShowHighlightIcon &&
<HtmlToolTipNormalRaw
title={
<div>
<div>This matched with:</div>
<br />
<div dangerouslySetInnerHTML={{__html: highlightedText}} />
</div>
}
placement='left'>
<HighlightIcon style={{color: 'rgba(0, 0, 0, 0.6)'}} />
</HtmlToolTipNormalRaw>
}
</TableCell>
}
</TableRow>
{
resourceDefinition.expandible &&
<TableRow>
<TableCell style={{ padding: 0 }} colSpan={columnsCount}>
<Collapse in={open} timeout="auto" unmountOnExit>
<Box margin={1}>
<Paper square style={{boxShadow: 'none', border: '1px solid lightgray'}}>
<Tabs
value={tab}
indicatorColor="primary"
textColor="primary"
onChange={handleTabChange}
>
{
map(resourceDefinition.tabs, label => getTab(label))
}
</Tabs>
{
tab === resourceDefinition.tabs.indexOf('Mappings') &&
<div style={{borderTop: '1px solid lightgray', maxHeight: '175px', overflow: 'auto'}}>
<AllMappingsTables mappings={mappings} concept_url={item.url} isLoading={isFetchingMappings} />
</div>
}
{
tab === resourceDefinition.tabs.indexOf('Synonyms') &&
<div style={{borderTop: '1px solid lightgray', maxHeight: '175px', overflow: 'auto'}}>
<LocalesTable locales={names} />
</div>
}
{
tab === resourceDefinition.tabs.indexOf('Descriptions') &&
<div style={{borderTop: '1px solid lightgray', maxHeight: '175px', overflow: 'auto'}}>
<LocalesTable locales={descriptions} isDescription />
</div>
}
{
fhir && tab === resourceDefinition.tabs.indexOf('Copyright') &&
<div style={{borderTop: '1px solid lightgray', maxHeight: '175px', overflow: 'auto'}}>
<div className="col-md-12" style={{padding: '20px'}} dangerouslySetInnerHTML={{__html: item.resource.copyright}} />
</div>
}
{
fhir && tab === resourceDefinition.tabs.indexOf('Details') &&
<div style={{borderTop: '1px solid lightgray', maxHeight: '175px', overflow: 'auto'}}>
<FhirContainerResource {...item} style={{padding: '20px'}} />
</div>
}
{
(
tab === resourceDefinition.tabs.indexOf('History') ||
tab === resourceDefinition.tabs.indexOf('Versions')
) &&
<div style={{borderTop: '1px solid lightgray', maxHeight: '175px', overflow: 'auto'}}>
{
fhir ?
<FHIRHistoryTable versions={versions} resource={resource} /> :
<HistoryTable versions={versions} />
}
</div>
}
</Paper>
</Box>
</Collapse>
</TableCell>
</TableRow>
}
</React.Fragment>
)
}
const ResultsTable = (
{
resource, results, onPageChange, onSortChange, sortParams,
onPinCreate, onPinDelete, pins, nested, showPin, essentialColumns, onReferencesDelete,
isVersionedObject, onCreateSimilarClick, onCreateMappingClick, viewFields, hapi, fhir, history,
onSelect, asReference, onSelectChange, onIndependentDetailsToggle, onWidthChange, onLimitChange,
isInsideConfiguredOrg, isLoading, limit
}
) => {
const [details, setDetails] = React.useState(null);
const [refTranslation, setRefTranslation] = React.useState(true)
const resourceDefinition = RESOURCE_DEFINITIONS[resource];
const theadBgColor = get(resourceDefinition, 'headBgColor', BLUE);
const theadTextColor = get(resourceDefinition, 'headTextColor', WHITE);
const theadStyles = {
backgroundColor: theadBgColor,
}
const isConceptContainer = includes(['sources', 'collections'], resource);
const isValueSet = resource === 'ValueSet'
const isConceptMap = resource === 'ConceptMap'
const shouldShowPin = showPin && resourceDefinition.pinnable;
const canRender = (results.total && resourceDefinition) || isLoading;
const defaultOrderBy = get(find(resourceDefinition.columns, {sortOn: get(values(sortParams), '0', 'last_update')}), 'id', 'UpdateOn');
const defaultOrder = get(keys(sortParams), '0') === 'sortAsc' ? 'asc' : 'desc';
const [selectedList, setSelectedList] = React.useState([]);
const [orderBy, setOrderBy] = React.useState(defaultOrderBy)
const [order, setOrder] = React.useState(defaultOrder)
const hasAccess = currentUserHasAccess()
const isSourceChild = includes(['concepts', 'mappings'], resource);
const isReferenceResource = resource === 'references';
const isSelectable = (isReferenceResource && hasAccess && isVersionedObject) ||
isSourceChild;
const hasZeroActiveButSomeRetiredResults = () => isSourceChild && results?.total === 0 && Boolean(retiredResults())
const retiredResults = () => {
const retired = results.facets?.fields?.retired
return get(find(retired, info => info[0] === 'true' && info[1] > 0 && info[2] === false), '1')
}
const onAllSelect = event => {
const newList = event.target.checked ? map(results.items, 'uuid') : [];
setSelectedList(newList)
if(onSelectChange)
onSelectChange(isEmpty(newList) ? [] : map(filter(results.items, item => includes(newList, item.uuid)), 'version_url'))
};
const updateSelected = (id, selected) => {
const newList = selected ? uniq([...selectedList, id]) : without(selectedList, id)
setSelectedList(newList)
const lastSelected = find(results.items, {uuid: last(newList)})
if(includes(['concepts', 'mappings'], resource)) {
if(onSelectChange)
onSelectChange(map(filter(results.items, item => includes(newList, item.uuid)), 'version_url'))
if(onSelect)
onSelect(lastSelected)
if(!onSelect && !onSelectChange)
onDetailsToggle(lastSelected)
}
};
const getOppositeOrder = order => order === 'asc' ? 'desc' : 'asc';
const onSort = (event, columnId) => {
const column = find(resourceDefinition.columns, {id: columnId})
let newOrder = get(column, 'sortBy') || 'desc';
if(orderBy === columnId)
newOrder = getOppositeOrder(order)
const sortOn = get(column, 'sortOn', 'last_update')
let sortQuery = {sortDesc: sortOn}
if(newOrder === 'asc')
sortQuery = {sortAsc: sortOn}
setOrder(newOrder)
setOrderBy(columnId)
onSortChange(sortQuery)
}
const filterColumnsFromViewFields = () => {
const result = map(viewFields, fieldConfig => {
const attr = keys(fieldConfig)[0]
const label = fieldConfig[attr];
const column = find(getColumns(ALL_COLUMNS[resource]), {value: attr})
return column ? {...column, label: label} : {label: label, id: attr, value: attr, sortable: false}
})
return result
}
const getSelectedItems = () => filter(results.items, item => includes(selectedList, item.uuid))
let columns = essentialColumns ?
reject(resourceDefinition.columns, c => c.essential === false) :
resourceDefinition.columns;
const hasSearchMeta = (isConceptContainer || isSourceChild) && get(results, 'items.0.search_meta.search_highlight')
columns = isEmpty(viewFields) ? columns : filterColumnsFromViewFields()
let columnsCount = get(columns, 'length', 1) + ((resourceDefinition.expandible || shouldShowPin) ? 2 : 1) + ((isConceptContainer || isValueSet || isConceptMap) ? 1 : 0);
if(hasSearchMeta)
columnsCount += 1
const selectionRowColumnsCount = get(selectedList, 'length', 0) > 0 ? columnsCount - 2 : columnsCount;
const onDetailsToggle = item => {
setDetails(item)
if(onIndependentDetailsToggle)
onIndependentDetailsToggle(item)
}
const onCloseSideDrawer = () => {
onWidthChange(false)
onDetailsToggle(null)
}
React.useEffect(() => !details && onCloseSideDrawer(), [details])
React.useEffect(() => setSelectedList(map(getSelectedItems(), 'uuid')) , [results])
const selectedItems = getSelectedItems()
const selectedCount = get(selectedItems, 'length', 0)
const hasItems = Boolean(selectedCount)
const isAllSelected = hasItems && selectedCount === get(results, 'items.length', 0)
const isSomeSelected = hasItems && selectedCount > 0 && !isAllSelected
return (
<React.Fragment>
<div className='col-sm-12 no-side-padding'>
{
canRender ?
<div className='col-sm-12 no-side-padding search-results'>
<Paper sx={{ width: '100%', overflow: 'hidden' }}>
<TableContainer style={{borderRadius: '4px'}} sx={{maxHeight: nested && !isInsideConfiguredOrg ? '65vh': '75vh'}}>
<Table stickyHeader size='small'>
<TableHead>
{
selectedCount > 0 &&
<TableRow colSpan={selectionRowColumnsCount} style={{backgroundColor: 'rgba(0, 0, 0, 0.09)'}}>
<TableCell colSpan={columnsCount} align='left' style={{backgroundColor: 'rgba(224, 224, 224, 1)'}}>
<span className='flex-vertical-center'>
<span style={{margin: '0px 10px', whiteSpace: 'pre'}}>{selectedCount} Selected</span>
{
!asReference &&
<SelectedResourceControls
selectedItems={selectedItems}
resource={resource}
onCreateSimilarClick={onCreateSimilarClick}
onCreateMappingClick={onCreateMappingClick}
onReferencesDelete={onReferencesDelete}
/>
}
</span>
</TableCell>
</TableRow>
}
<TableRow style={theadStyles}>
{
(isConceptContainer || isValueSet || isConceptMap) &&
<TableCell style={{...theadStyles, top: selectedCount > 0 ? 40 : 0}} />
}
{
isSelectable &&
<TableCell style={{maxWidth: '30px', padding: '2px', ...theadStyles, top: selectedCount > 0 ? 40 : 0}} align="center">
<Checkbox checked={isAllSelected} indeterminate={isSomeSelected} size='small' style={{color: theadTextColor, padding: '0px'}} onChange={onAllSelect} />
</TableCell>
}
{
map(columns, column => {
const isSortable = column.sortable !== false;
return isSortable ? (
<TableCell
key={column.id}
sortDirection={orderBy === column.id ? order : false}
align={column.align || 'left'}
style={{color: theadTextColor, ...theadStyles, top: selectedCount > 0 ? 40 : 0}}>
{
column.tooltip ?
<Tooltip arrow placement='top' title={column.tooltip}>
<TableSortLabel
className='table-sort-label-white'
active={orderBy === column.id}
direction={orderBy === column.id ? order : (column.sortBy || 'desc')}
onClick={(event) => onSort(event, column.id)}
style={{color: theadTextColor}}
>
{ column.label }
</TableSortLabel>
</Tooltip> :
<TableSortLabel
className='table-sort-label-white'
active={orderBy === column.id}
direction={orderBy === column.id ? order : (column.sortBy || 'desc')}
onClick={(event) => onSort(event, column.id)}
style={{color: theadTextColor}}
>
{ column.label }
</TableSortLabel>
}
</TableCell>
) : (
<TableCell key={column.id} align={column.align || 'left'} style={{color: theadTextColor, ...theadStyles, top: selectedCount > 0 ? 40 : 0}}>
{
column.translation ?
<span>
<span>{column.label}</span>
<span style={{marginLeft: '20px'}}>
<FormControlLabel
size='small'
control={
<Switch
color="default"
size='small'
checked={refTranslation}
onChange={event => setRefTranslation(event.target.checked)} />
}
label={
<span style={{fontSize: '12px', marginLeft: '5px'}}>
{refTranslation ? 'Show Expression' : 'Show Translation'}
</span>
}
/>
</span>
</span> :
column.label
}
</TableCell>