@@ -28,9 +28,9 @@ class EntityApprovalStatusService extends BaseService {
2828 return EntityApprovalStatus . schema . name ;
2929 }
3030
31- saveStatus ( entityUUID , entityType , status , db , approvalStatusComment ) {
31+ saveStatus ( entityUUID , entityType , status , db , approvalStatusComment , entityTypeUuid ) {
3232 const approvalStatus = this . getService ( EntityService ) . findByKey ( "status" , status , ApprovalStatus . schema . name ) ;
33- const entityApprovalStatus = EntityApprovalStatus . create ( entityUUID , entityType , approvalStatus , approvalStatusComment ) ;
33+ const entityApprovalStatus = EntityApprovalStatus . create ( entityUUID , entityType , approvalStatus , approvalStatusComment , false , entityTypeUuid ) ;
3434 const savedStatus = db . create ( this . getSchema ( ) , entityApprovalStatus ) ;
3535 db . create ( EntityQueue . schema . name , EntityQueue . create ( savedStatus , this . getSchema ( ) ) ) ;
3636 return savedStatus ;
@@ -77,14 +77,16 @@ class EntityApprovalStatusService extends BaseService {
7777 this . saveEntityWithStatus ( entity , schema , ApprovalStatus . statuses . Rejected , comment ) ;
7878 }
7979
80- createPendingStatus ( entityUUID , schema , db ) {
81- return this . saveStatus ( entityUUID , this . _getEntityTypeForSchema ( schema ) , ApprovalStatus . statuses . Pending , db ) ;
80+ createPendingStatus ( entityUUID , schema , db , entityTypeUuid ) {
81+ return this . saveStatus ( entityUUID , this . _getEntityTypeForSchema ( schema ) , ApprovalStatus . statuses . Pending , db , null , entityTypeUuid ) ;
8282 }
8383
8484 saveEntityWithStatus ( entity , schema , status , comment ) {
8585 const db = this . db ;
86+ const entityTypeUuid = _ . get ( entity , 'subjectType.uuid' ) || _ . get ( entity , 'encounterType.uuid' ) || _ . get ( entity , 'program.uuid' ) ;
87+
8688 this . db . write ( ( ) => {
87- entity . latestEntityApprovalStatus = this . saveStatus ( entity . uuid , this . _getEntityTypeForSchema ( schema ) , status , db , comment ) ;
89+ entity . latestEntityApprovalStatus = this . saveStatus ( entity . uuid , this . _getEntityTypeForSchema ( schema ) , status , db , comment , entityTypeUuid ) ;
8890 db . create ( schema , entity , true ) ;
8991 db . create ( EntityQueue . schema . name , EntityQueue . create ( entity , schema ) ) ;
9092 } ) ;
0 commit comments