diff --git a/core/nurse_scheduling/scheduler.py b/core/nurse_scheduling/scheduler.py index 06cf8da4..db29759d 100644 --- a/core/nurse_scheduling/scheduler.py +++ b/core/nurse_scheduling/scheduler.py @@ -49,9 +49,11 @@ def schedule( ctx.n_people = len(ctx.people.items) ctx.dates.items = [ctx.dates.range.startDate + timedelta(days=d) for d in range(ctx.n_days)] - # Map shift type ID to shift type index + # Map shift type ID to shift type index. + # IDs are stringified so unquoted YAML scalars (e.g. `0` parsed as int) + # produce the same map key as the string lookups in `parse_sids`. for s in range(ctx.n_shift_types): - ctx.map_sid_s[ctx.shiftTypes.items[s].id] = [s] + ctx.map_sid_s[str(ctx.shiftTypes.items[s].id)] = [s] # Add shift type ALL and OFF keywords ctx.map_sid_s[ALL] = list(range(ctx.n_shift_types)) ctx.map_sid_s[OFF] = [OFF_sid] @@ -59,17 +61,18 @@ def schedule( for g in range(len(ctx.shiftTypes.groups)): group = ctx.shiftTypes.groups[g] # Flatten and deduplicate shift type indices for the group - ctx.map_sid_s[group.id] = sorted(set().union(*[ctx.map_sid_s[sid] for sid in group.members])) - # Map person ID to person index + ctx.map_sid_s[str(group.id)] = sorted(set().union(*[ctx.map_sid_s[str(sid)] for sid in group.members])) + # Map person ID to person index. + # IDs are stringified for the same reason as shift type IDs above. for p in range(ctx.n_people): - ctx.map_pid_p[ctx.people.items[p].id] = [p] + ctx.map_pid_p[str(ctx.people.items[p].id)] = [p] # Add people ALL keyword ctx.map_pid_p[ALL] = list(range(ctx.n_people)) # Map people group ID to list of person indices for g in range(len(ctx.people.groups)): group = ctx.people.groups[g] # Flatten and deduplicate person indices for the group - ctx.map_pid_p[group.id] = sorted(set().union(*[ctx.map_pid_p[pid] for pid in group.members])) + ctx.map_pid_p[str(group.id)] = sorted(set().union(*[ctx.map_pid_p[str(pid)] for pid in group.members])) # Map date string (YYYY-MM-DD) to date index if ctx.country is not None and ctx.country != 'TW': diff --git a/core/nurse_scheduling/utils.py b/core/nurse_scheduling/utils.py index 38f6a10d..9723b7aa 100644 --- a/core/nurse_scheduling/utils.py +++ b/core/nurse_scheduling/utils.py @@ -88,7 +88,9 @@ def parse_dates(dates, map_did_d, date_range): return sorted(set(result)) def parse_sids(sids, map_sid_s): - sids = ensure_list(sids) + # Coerce to str so that unquoted YAML scalars (e.g. `0` parsed as int) + # match the string-keyed `map_sid_s`. Mirrors `parse_dates`'s `map(str, ...)`. + sids = [str(sid) for sid in ensure_list(sids)] result = [] for sid in sids: if sid not in map_sid_s: @@ -97,7 +99,9 @@ def parse_sids(sids, map_sid_s): return sorted(set(result)) def parse_pids(pids, map_pid_p): - pids = ensure_list(pids) + # Coerce to str so that unquoted YAML scalars (e.g. `0` parsed as int) + # match the string-keyed `map_pid_p`. Mirrors `parse_dates`'s `map(str, ...)`. + pids = [str(pid) for pid in ensure_list(pids)] result = [] for pid in pids: if pid not in map_pid_p: