@@ -9,10 +9,11 @@ import { filterComplianceMembers } from '../utils/compliance-filters';
99
1010const SIX_MONTHS_MS = 6 * 30 * 24 * 60 * 60 * 1000 ;
1111
12- const TRAINING_VIDEO_IDS = [ 'sat-1' , 'sat-2' , 'sat-3' , 'sat-4' , 'sat-5' ] ;
12+ const GENERAL_TRAINING_IDS = [ 'sat-1' , 'sat-2' , 'sat-3' , 'sat-4' , 'sat-5' ] ;
13+ const HIPAA_TRAINING_ID = 'hipaa-sat-1' ;
1314
1415export async function getOverviewScores ( organizationId : string ) {
15- const [ allPolicies , allTasks , employees , onboarding , org ] = await Promise . all ( [
16+ const [ allPolicies , allTasks , employees , onboarding , org , hipaaInstance ] = await Promise . all ( [
1617 db . policy . findMany ( { where : { organizationId } } ) ,
1718 db . task . findMany ( { where : { organizationId } } ) ,
1819 db . member . findMany ( {
@@ -27,9 +28,14 @@ export async function getOverviewScores(organizationId: string) {
2728 where : { id : organizationId } ,
2829 select : { securityTrainingStepEnabled : true } ,
2930 } ) ,
31+ db . frameworkInstance . findFirst ( {
32+ where : { organizationId, framework : { name : 'HIPAA' } } ,
33+ select : { id : true } ,
34+ } ) ,
3035 ] ) ;
3136
3237 const securityTrainingStepEnabled = org ?. securityTrainingStepEnabled === true ;
38+ const hasHipaaFramework = ! ! hipaaInstance ;
3339
3440 // Policy breakdown
3541 const publishedPolicies = allPolicies . filter ( ( p ) => p . status === 'published' ) ;
@@ -60,9 +66,12 @@ export async function getOverviewScores(organizationId: string) {
6066 p . isRequiredToSign && p . status === 'published' && ! p . isArchived ,
6167 ) ;
6268
63- const trainingCompletions = securityTrainingStepEnabled
69+ const memberIds = activeEmployees . map ( ( e ) => e . id ) ;
70+ const needsCompletions = securityTrainingStepEnabled || hasHipaaFramework ;
71+
72+ const trainingCompletions = needsCompletions
6473 ? await db . employeeTrainingVideoCompletion . findMany ( {
65- where : { memberId : { in : activeEmployees . map ( ( e ) => e . id ) } } ,
74+ where : { memberId : { in : memberIds } } ,
6675 } )
6776 : [ ] ;
6877
@@ -71,21 +80,19 @@ export async function getOverviewScores(organizationId: string) {
7180 requiredPolicies . length === 0 ||
7281 requiredPolicies . every ( ( p ) => p . signedBy . includes ( emp . id ) ) ;
7382
83+ const completedVideoIds = trainingCompletions
84+ . filter ( ( c ) => c . memberId === emp . id && c . completedAt !== null )
85+ . map ( ( c ) => c . videoId ) ;
86+
7487 const hasCompletedAllTraining = securityTrainingStepEnabled
75- ? ( ( ) => {
76- const empCompletions = trainingCompletions . filter (
77- ( c ) => c . memberId === emp . id ,
78- ) ;
79- const completedVideoIds = empCompletions
80- . filter ( ( c ) => c . completedAt !== null )
81- . map ( ( c ) => c . videoId ) ;
82- return TRAINING_VIDEO_IDS . every ( ( vid ) =>
83- completedVideoIds . includes ( vid ) ,
84- ) ;
85- } ) ( )
88+ ? GENERAL_TRAINING_IDS . every ( ( vid ) => completedVideoIds . includes ( vid ) )
89+ : true ;
90+
91+ const hasCompletedHipaa = hasHipaaFramework
92+ ? completedVideoIds . includes ( HIPAA_TRAINING_ID )
8693 : true ;
8794
88- if ( hasAcceptedAllPolicies && hasCompletedAllTraining ) {
95+ if ( hasAcceptedAllPolicies && hasCompletedAllTraining && hasCompletedHipaa ) {
8996 completedMembers ++ ;
9097 }
9198 }
0 commit comments