It has comments! It creates a completely lazy map from patientInTrialId to the value for that patient in the data row.

The inner call creates a patientInTrialId -> to a number between 0 and (number of assays - 1) map, where the value is the index of the corresponding assay for that patient (in this result set). Then it converts the values from of this map from this number to the actual value in the result set. Finally it purges entries with a null value (assays for which there's no data).