Thanks for your help all!
I've got a working script that I'm pretty happy with. Couldn't do the healing fatal wounds thing, but really that's ok because that's what medikits are for. Also decided painkillers weren't worth the effort. [I'm sure my soldiers love me]
I have uncovered possibly incorrect behavior in the stun mechanic though!
[07-01-2020_23-42-57] [DEBUG] Script debug log at 0x6f6: IMS - Incapacitation detected for ID 2 . health = 20 , stun = 29 , maxStun = 180
[07-01-2020_23-42-57] [DEBUG] Script debug log at 0x87c: IMS - Shooting some stims for ID 2 , Energy now 87 , Stun now 25
Soldier is a heap on the floor
[07-01-2020_23-43-15] [DEBUG] Script debug log at 0x6f6: IMS - Incapacitation detected for ID 2 . health = 20 , stun = 24 , maxStun = 180
[07-01-2020_23-43-15] [DEBUG] Script debug log at 0x87c: IMS - Shooting some stims for ID 2 , Energy now 87 , Stun now 20
Soldier is a heap on the floor
[07-01-2020_23-43-43] [DEBUG] Script debug log at 0x780: IMS - Incapacitation risk for ID 2 . health = 20 , stun = 19 , maxStun = 180
[07-01-2020_23-43-43] [DEBUG] Script debug log at 0x87c: IMS - Shooting some stims for ID 2 , Energy now 87 , Stun now 15
Even before my mod pumped a stimmie into this soldier, he should be on his feet, but he's not!
[07-01-2020_23-45-52] [DEBUG] Script debug log at 0x780: IMS - Incapacitation risk for ID 2 . health = 20 , stun = 14 , maxStun = 180
[07-01-2020_23-45-52] [DEBUG] Script debug log at 0x87c: IMS - Shooting some stims for ID 2 , Energy now 87 , Stun now 10
NOW the soldier is finally up and about.