@@ -24,7 +24,7 @@ export interface IFilesLinksTable {
24
24
}
25
25
26
26
class FilesLinksTableComponent extends LazyMobXTable < {
27
- [ id : string ] : string ;
27
+ [ id : string ] : string | number ;
28
28
} > { }
29
29
30
30
const RECORD_LIMIT = 500 ;
@@ -70,20 +70,24 @@ async function fetchFilesLinksData(
70
70
0
71
71
) ;
72
72
73
+ // get unique patient Ids from clinical data to get their resources
74
+ // via fetchResourceDataOfPatient.
73
75
const patientIds = new Map < string , string > ( ) ;
74
- _ . forEach ( sampleClinicalDataResponse . data , ( data , uniqueSampleId ) => {
76
+ _ . forEach ( sampleClinicalDataResponse . data , data => {
75
77
_ . forEach ( data , item => {
76
78
patientIds . set ( item . patientId , item . studyId ) ;
77
79
} ) ;
78
80
} ) ;
79
81
82
+ // get all resources for patients.
83
+ // improvement: use one request for getting a page of patients
84
+ // with their samples and resources.
80
85
const resourcesForPatients = await fetchResourceDataOfPatient ( patientIds ) ;
81
-
82
86
const buildItemsAndResources = ( resourceData : {
83
87
[ key : string ] : ResourceData [ ] ;
84
88
} ) => {
85
89
const resourcesPerPatient : { [ key : string ] : number } = { } ;
86
- const items : { [ attributeId : string ] : any } = [ ] ;
90
+ const items : { [ attributeId : string ] : string | number } [ ] = [ ] ;
87
91
_ . forEach ( resourceData , ( data : ResourceData [ ] ) => {
88
92
_ . forEach ( data , ( resource : ResourceData ) => {
89
93
items . push ( {
@@ -94,7 +98,7 @@ async function fetchFilesLinksData(
94
98
typeOfResource : resource ?. resourceDefinition ?. displayName ,
95
99
description : resource ?. resourceDefinition ?. description ,
96
100
url : resource ?. url ,
97
- } ) ;
101
+ } as { [ attributeId : string ] : string | number } ) ;
98
102
} ) ;
99
103
100
104
if ( data && data . length > 0 ) {
@@ -108,23 +112,25 @@ async function fetchFilesLinksData(
108
112
return { resourcesPerPatient, items } ;
109
113
} ;
110
114
111
- const resourcesForPatientsAndSamples = {
115
+ const resourcesForPatientsAndSamples : { [ key : string ] : ResourceData [ ] } = {
112
116
...sampleIdResourceData ,
113
117
...resourcesForPatients ,
114
118
} ;
115
119
116
- //we create objects with the necessary properties for each resource
117
- //calculate the total number of resources per patient.
118
-
120
+ // we create objects with the necessary properties for each resource
121
+ // calculate the total number of resources per patient.
119
122
const { resourcesPerPatient, items } = buildItemsAndResources (
120
123
resourcesForPatientsAndSamples
121
124
) ;
122
- const data = _ . mapValues ( items , item => {
125
+
126
+ // set the number of resources available per patient.
127
+ _ . forEach ( items , item => {
123
128
item . resourcesPerPatient = resourcesPerPatient [ item . patientId ] ;
124
- return item ;
125
129
} ) ;
126
130
127
- const sortedData = _ . orderBy ( data , 'resourcesPerPatient' , 'desc' ) ;
131
+ // there is a requirement to sort initially by 'resourcesPerPatient' field
132
+ // in descending order.
133
+ const sortedData = _ . orderBy ( items , 'resourcesPerPatient' , 'desc' ) ;
128
134
return {
129
135
totalItems : sortedData . length ,
130
136
data : _ . values ( sortedData ) ,
@@ -161,11 +167,7 @@ export class FilesAndLinks extends React.Component<IFilesLinksTable, {}> {
161
167
download : ( data : { [ id : string ] : string } ) => data [ key ] || '' ,
162
168
sortBy : ( data : { [ id : string ] : any } ) => {
163
169
if ( data [ key ] ) {
164
- if ( isNumber ) {
165
- return parseFloat ( data [ key ] ) ;
166
- } else {
167
- return data [ key ] ;
168
- }
170
+ return data [ key ] ;
169
171
}
170
172
return null ;
171
173
} ,
@@ -232,6 +234,7 @@ export class FilesAndLinks extends React.Component<IFilesLinksTable, {}> {
232
234
) ;
233
235
} ,
234
236
} ,
237
+
235
238
{
236
239
...this . getDefaultColumnConfig ( 'sampleId' , 'Sample ID' ) ,
237
240
render : ( data : { [ id : string ] : string } ) => {
0 commit comments