import pathlib


def get_pname(p: pathlib.Path):
    """
    resolve patient name.

    e.g.
        /path/to/abc.mha -> abc
        /path/to/abc_seg.mha -> abc
    """
    if p.stem.endswith('_seg'):
        return p.stem[:-len('_seg')]
    return p.stem