@@ -550,18 +550,28 @@ function getCrossSourceVitalValues(personId: string): EventSourceValue[] {
550550 return [ ...values , ...getCachedProviderVitalValues ( personId ) ] ;
551551}
552552
553- function checkDateMismatches ( runId : string , personId : string , displayName : string ) : AuditIssue [ ] {
554- const events = getCrossSourceVitalValues ( personId )
553+ function checkDateMismatches (
554+ runId : string ,
555+ personId : string ,
556+ displayName : string ,
557+ events : EventSourceValue [ ] ,
558+ ) : AuditIssue [ ] {
559+ const dateEvents = events
555560 . filter ( ( event ) : event is EventSourceValue & { value : number } => typeof event . value === 'number' ) ;
556561
557- return findCrossSourceMismatches ( events , ( left , right ) => left === right )
562+ return findCrossSourceMismatches ( dateEvents , ( left , right ) => left === right )
558563 . map ( ( { eventType, details } ) => makeIssue ( runId , personId , 'date_mismatch' , 'warning' ,
559564 `${ displayName } : ${ eventType } date differs across sources (${ details } )` ,
560565 details , null ) ) ;
561566}
562567
563- function checkPlaceMismatches ( runId : string , personId : string , displayName : string ) : AuditIssue [ ] {
564- const events = getCrossSourceVitalValues ( personId )
568+ function checkPlaceMismatches (
569+ runId : string ,
570+ personId : string ,
571+ displayName : string ,
572+ events : EventSourceValue [ ] ,
573+ ) : AuditIssue [ ] {
574+ const placeEvents = events
565575 . filter ( ( event ) : event is EventSourceValue & { value : string } => typeof event . value === 'string' ) ;
566576
567577 const samePlace = ( left : string | number , right : string | number ) => {
@@ -570,7 +580,7 @@ function checkPlaceMismatches(runId: string, personId: string, displayName: stri
570580 return placesMatch ( a , b ) || placeContains ( a , b ) || placeContains ( b , a ) ;
571581 } ;
572582
573- return findCrossSourceMismatches ( events , samePlace ) . map ( ( { eventType, details } ) => makeIssue (
583+ return findCrossSourceMismatches ( placeEvents , samePlace ) . map ( ( { eventType, details } ) => makeIssue (
574584 runId , personId , 'place_mismatch' , 'warning' ,
575585 `${ displayName } : ${ eventType } place differs across sources (${ details } )` ,
576586 details , null ,
@@ -835,6 +845,9 @@ function auditPerson(
835845
836846 const issues : AuditIssue [ ] = [ ] ;
837847 let linkedSources = new Set < string > ( ) ;
848+ const crossSourceVitalValues = checksEnabled . includes ( 'date_mismatch' ) || checksEnabled . includes ( 'place_mismatch' )
849+ ? getCrossSourceVitalValues ( vitals . personId )
850+ : [ ] ;
838851
839852 if ( checksEnabled . includes ( 'impossible_date' ) ) {
840853 issues . push ( ...checkImpossibleDates ( runId , vitals ) ) ;
@@ -864,10 +877,10 @@ function auditPerson(
864877 linkedSources = new Set ( linked . map ( l => l . source ) ) ;
865878 }
866879 if ( checksEnabled . includes ( 'date_mismatch' ) ) {
867- issues . push ( ...checkDateMismatches ( runId , vitals . personId , vitals . displayName ) ) ;
880+ issues . push ( ...checkDateMismatches ( runId , vitals . personId , vitals . displayName , crossSourceVitalValues ) ) ;
868881 }
869882 if ( checksEnabled . includes ( 'place_mismatch' ) ) {
870- issues . push ( ...checkPlaceMismatches ( runId , vitals . personId , vitals . displayName ) ) ;
883+ issues . push ( ...checkPlaceMismatches ( runId , vitals . personId , vitals . displayName , crossSourceVitalValues ) ) ;
871884 }
872885
873886 return { issues, displayName : vitals . displayName , linkedSources } ;
0 commit comments