@@ -450,23 +450,22 @@ const collectData = async (request, reply) => {
450450 const bundles = await Promise . all (
451451 patientIds . map ( async id => {
452452 const patient = await findResourceById ( id , 'Patient' ) ;
453- const measureReports = [ ] ;
454- const patientResourcePromises = measures . map ( async measure => {
455- const patientResources = await findPatientResources ( patient , measure ) ;
456- measureReports . push (
457- createDataExchangeMeasureReport (
453+ const resourcesMRPairs = await Promise . all (
454+ measures . map ( async measure => {
455+ const patientResources = await findPatientResources ( patient , measure ) ;
456+ const measureReport = createDataExchangeMeasureReport (
458457 measure ,
459458 {
460459 start : parameters . periodStart ,
461460 end : parameters . periodEnd
462461 } ,
463462 id ,
464463 patientResources
465- )
466- ) ;
467- return patientResources ;
468- } ) ;
469- const patientResourcesArray = await Promise . all ( patientResourcePromises ) ;
464+ ) ;
465+ return [ patientResources , measureReport ] ;
466+ } )
467+ ) ;
468+ const [ patientResourcesArray , measureReports ] = _ . unzip ( resourcesMRPairs ) ;
470469 const uniqueResources = _ . uniqBy (
471470 patientResourcesArray . flat ( ) ,
472471 resource => `${ resource . resourceType } /${ resource . id } `
0 commit comments