File size: 2,426 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import {
  Controller,
  Get,
  Post,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  Request,
  HttpCode,
  HttpStatus,
  ParseIntPipe,
  Inject,
  forwardRef,
} from "@nestjs/common";
import { SymptomsService } from "./symptoms.service";
import { CreateSymptomDto } from "./dto/create-symptom.dto";
import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard";
import { HealthAssessmentService } from "../care-priority/health-assessment.service";

@Controller("symptoms")
@UseGuards(JwtAuthGuard)
export class SymptomsController {
  constructor(
    private readonly symptomsService: SymptomsService,
    @Inject(forwardRef(() => HealthAssessmentService))
    private readonly healthAssessmentService: HealthAssessmentService
  ) {}

  @Post()
  @HttpCode(HttpStatus.CREATED)
  async create(
    @Request() req: any,
    @Body() createSymptomDto: CreateSymptomDto
  ) {
    const userId = req.user.id;
    const symptom = await this.symptomsService.create(userId, createSymptomDto);

    // Trigger health assessment and notifications
    this.healthAssessmentService.assessAndNotify(userId);

    return symptom;
  }

  /**
   * Get all symptoms for authenticated user
   *
   * @param req - Request with authenticated user
   * @param limit - Optional limit (default: 100)
   * @returns Array of symptom records
   */
  @Get()
  @HttpCode(HttpStatus.OK)
  async getSymptoms(
    @Request() req: any,
    @Query("limit", new ParseIntPipe({ optional: true })) limit?: number
  ) {
    const userId = req.user.id;
    return this.symptomsService.findByUserId(userId, limit);
  }

  /**
   * Get recent symptoms (last 48 hours by default)
   *
   * @param req - Request with authenticated user
   * @param hours - Number of hours to look back
   * @returns Array of recent symptom records
   */
  @Get("recent")
  @HttpCode(HttpStatus.OK)
  async getRecent(
    @Request() req: any,
    @Query("hours", new ParseIntPipe({ optional: true })) hours?: number
  ) {
    const userId = req.user.id;
    return this.symptomsService.getRecentSymptoms(userId, hours);
  }

  /**
   * Delete a symptom record
   *
   * @param req - Request with authenticated user
   * @param id - Symptom record ID
   * @returns Success message
   */
  @Delete(":id")
  @HttpCode(HttpStatus.OK)
  async delete(@Request() req: any, @Param("id") id: string) {
    const userId = req.user.id;
    return this.symptomsService.delete(id, userId);
  }
}