File size: 1,845 Bytes
f78b36a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import {
  Controller,
  Get,
  UseGuards,
  Request,
  HttpCode,
  HttpStatus,
} from "@nestjs/common";
import { CarePriorityService } from "./care-priority.service";
import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard";

/**
 * Care Priority Controller
 *
 * ENDPOINT:
 * - GET /care-priority - Get current care priority (authenticated, read-only)
 *
 * CLINICAL SAFETY:
 * - Read-only endpoint (no POST/PUT/DELETE)
 * - Returns priority level and safe next step message
 * - Non-diagnostic language only
 * - No explanation of medical reasoning
 * - Template-based messaging
 *
 * RESPONSE FORMAT:
 * {
 *   priority: 'ROUTINE' | 'INCREASED_MONITORING' | 'URGENT_REVIEW' | 'EMERGENCY',
 *   message: 'Safe next step message',
 *   reasons: ['Factor 1', 'Factor 2'],
 *   timestamp: '2024-01-01T00:00:00.000Z'
 * }
 */

@Controller("care-priority")
@UseGuards(JwtAuthGuard)
export class CarePriorityController {
  constructor(private readonly carePriorityService: CarePriorityService) {}

  /**
   * Get current care priority for authenticated user
   *
   * CONSTRAINTS:
   * - Read-only operation
   * - Calculates priority based on latest data
   * - Returns predefined safe message
   * - No diagnostic information
   *
   * @param req - Request with authenticated user
   * @returns Care priority result with safe message
   */
  @Get()
  @HttpCode(HttpStatus.OK)
  async getCarePriority(@Request() req: any) {
    const userId = req.user.id;

    // Calculate care priority
    const result = await this.carePriorityService.calculateCarePriority(userId);

    // Get safe next step message
    const message = this.carePriorityService.getSafeNextStepMessage(
      result.priority
    );

    return {
      priority: result.priority,
      message,
      reasons: result.reasons,
      timestamp: result.timestamp,
    };
  }
}