Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions core/nurse_scheduling/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,30 @@ 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]
# Map shift type group ID to list of shift type indices
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':
Expand Down
8 changes: 6 additions & 2 deletions core/nurse_scheduling/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Loading