I think you may want to share how you have defined verifyCertificateChain function or provide the documentation for that function, so we can provide more specific feedback?
The process is similar to validating the assertions in section 6 of
UDAP Client Authorization Grants using JSON Web Tokens, except that for UDAP DCR you only need to validate the signature and confirm the certificate is trusted, and usually that also means making sure the certificate has not expired or been revoked, nor has its issuer.
The server's own certificate is not in scope here - that is for validation by counter parties as per UDAP Server Metadata. You should be validating against your set of trusted CA certificates for this purpose (which needs to include the EMRDirectTestCA if you are using the UDAP Test Tool).
I'm assuming you're adding back the BEGIN and END because your library only understands PEM.
I don't see that the decoded signed software statement is checked to see that the JWT is still valid and is for the correct aud (or additional validation as per local policy/TBD).
Climbing the certificate chain to validate that the root or some intermediate cert is trusted is a separate step. The x5c[0] cert is the first link in the certificate chain; a complete certificate chain needs to be constructed from x5c[0] to an anchor in your caStore.
For more information about certificate chaining, see section 3.2 of
RFC 5280. The chain is built sufficiently to validate trust with some intermediate issuer or the root certificate. The process is likely well established in PKI libraries you'll encounter, but if you think more details summarizing relevant aspects of the referenced RFCs would be helpful, let us know.