---
title: RTWService
summary: API reference for RTWService.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# RTWService

Implements `IRTWService`, resolving the active return-to-work (RTW) load code assigned to a load user and enforcing that external users can only access RTW claims explicitly assigned to their RTW load code. It depends on `IUnitOfWork` for repository access to `RtwLoadAssignment`/`RTWCase` and on `IUserProfileService` (exposed as a protected field, though not directly used by its current methods).

## Purpose
- Resolves the active (non-expired) RTW load code assigned to a given load user, stripping a `"TEST"` prefix from the user name before lookup.
- Enforces that a user with the `"RTWExternalUpdate"` authorization can only access an RTW claim when it is assigned to the load code passed in; internal/non-restricted users are always permitted.

## Context
- Namespace: `SAIF.Services.Claims.RTW`
- Assembly/package: `SAIF.Services` (packaged inside the `SAIF.SAIFCode.Core` NuGet package)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| RTWService | `public RTWService(IUnitOfWork unitOfWork, IUserProfileService userProfileService)` | Stores the unit-of-work and user-profile collaborators as protected fields for use by derived types and instance methods. |
| GetRTWLoadCode | `public string GetRTWLoadCode(string loadUser)` | Strips a leading `"TEST"` prefix from the load-user name, looks up the matching non-expired `RtwLoadAssignment`, and returns its RTW load code, or an empty string if none is assigned. |
| CanAccessRTWClaim | `public bool CanAccessRTWClaim(long claimId, IApplicationUserProfile currentUser, string rtwLoadCode)` | Returns `true` unconditionally for users without the `"RTWExternalUpdate"` authorization; for authorized-external users, returns `true` only if an `RTWCase` exists for the claim with the matching RTW load code. |

## Behavioral notes
- `GetRTWLoadCode` performs a case-insensitive load-user comparison and requires `ExpirationDate == null` on the assignment, meaning only the currently-active assignment is matched.
- `CanAccessRTWClaim` gates its restrictive check behind `currentUser.IsAuthorized("RTWExternalUpdate")`, implying this authorization identifies external RTW users subject to load-code restriction.*

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- Services/SAIF.Services/Claims/RTW/RTWService.cs
