Yes, it is possible.
However, if you take maternity leave while on leave due to illness or injury, the way in which the number of days of absence is counted, whether or not you need to submit a leave of absence notification, and whether or not you need to consult with an industrial physician will differ depending on the type of illness or injury that caused the leave.
In either case ① or ② above, even if your leave of absence (=retirement date) is approaching, you will be given a postponement of retirement during pregnancy and until your child turns one year old, so please make efforts to recover your health so that you can return to work by then.
*If you have multiple injuries or illnesses, you must have recovered from all of them.
Related question:
I want to know about the leave system for personal injury and illness. – PASS
I want to know about procedures of mataniry and childbirth. – PASS