XNAT doesn't have a built-in way to extract values from DICOM fields in an imaging session and use the values to populate attributes on the corresponding subject. It would be great if it did, so much so that I
created a ticket to track this as a possible feature addition. That probably won't happen very soon though, so in the meantime I think you have the right idea with using event handlers. The best way to start with this is the
Event Service Quick Start. The basic idea is that you map some event–in this case either session or scan creation–to a container. When that event occurs, the associated container is launched. You would also need to create a container that can work with XNAT. This is described in the
Building Docker Images for Container Service documentation. That container would run a script of some sort–e.g. a Python script using
xnatpy, but it really depends on what you're comfortable using–to get the relevant value(s) from the data and update the subject properties based on that. It should be straightforward to make the script work with both DICOM and NIFTI data.
That might sound like a complicated process but actually each piece is simple on its own. Start by writing the script to work with a test subject and image session, then package it into a container, then associate the container with the appropriate event.