def patient_scan(patientcfg, add_sequence=None, sep=None):
    """Get patient/scan id

    Parameters
    ----------
    patientcfg      :   Dict < json (patient config file with pid, scanid in top level)
    add_sequence     :   Bool (Flag to join sequence id with pid, scanid)
    sep             :   Str (separator, default '_')

    Returns
    -------
    patient_scan_id :   str (concatenated)
    """

    if "pid" in patientcfg:
        patient_id = patientcfg["pid"]
    else:
        raise KeyError("patient_config:pid")
    if "scanid" in patientcfg:
        scan_id = patientcfg["scanid"]
    else:
        raise KeyError("patient_config:scanid")
    if add_sequence is None:
        add_sequence = False
    if sep is None:
        sep = '_'
    ps_id = []
    ps_id.extend((patient_id, sep, scan_id))

    if add_sequence:  # if True, default False
        if "sequenceid" in patientcfg:
            seq_id = patientcfg["sequenceid"]
            ps_id.extend((sep, seq_id))
        else:
            raise KeyError("patient_config:sequenceid")
    patient_scan_id = "".join(ps_id)

    return patient_scan_id