Are we sure that it's always true that the first xform_id in case.xform_ids is the opening xform and the last is the closing xform?

Here is at least one place where xform_ids is touched without respecting order:

https://github.com/dimagi/casexml/blob/c695629e876b9ed566642fbc3edea161618074d0/casexml/apps/case/models.py#L608

It would be more explicit to inspect the case actions and find the action with the correct type.