Skip to content
Open
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
90 changes: 8 additions & 82 deletions backend/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { RidersModule } from './riders/riders.module';
import { DispatchModule } from './dispatch/dispatch.module';
import { MapsModule } from './maps/maps.module';
import { NotificationsModule } from './notifications/notifications.module';
import { MedicalRecordsModule } from './medical-records/medical-records.module';
import { BullModule } from '@nestjs/bullmq';
import { JwtAuthGuard } from './auth/guards/jwt-auth.guard';
import { PermissionsGuard } from './auth/guards/permissions.guard';
Expand Down Expand Up @@ -59,6 +60,7 @@ import { PermissionsGuard } from './auth/guards/permissions.guard';
}),
}),
NotificationsModule,
MedicalRecordsModule,
],
controllers: [AppController],
providers: [
Expand Down
27 changes: 16 additions & 11 deletions backend/src/auth/enums/permission.enum.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,65 @@
export enum Permission {
// ── Orders ──────────────────────────────────────────────────────────
// Orders
CREATE_ORDER = 'create:order',
VIEW_ORDER = 'view:order',
UPDATE_ORDER = 'update:order',
CANCEL_ORDER = 'cancel:order',
DELETE_ORDER = 'delete:order',

// ── Riders ──────────────────────────────────────────────────────────
// Riders
VIEW_RIDERS = 'view:riders',
CREATE_RIDER = 'create:rider',
UPDATE_RIDER = 'update:rider',
DELETE_RIDER = 'delete:rider',
MANAGE_RIDERS = 'manage:riders',

// ── Hospitals ────────────────────────────────────────────────────────
// Hospitals
VIEW_HOSPITALS = 'view:hospitals',
CREATE_HOSPITAL = 'create:hospital',
UPDATE_HOSPITAL = 'update:hospital',
DELETE_HOSPITAL = 'delete:hospital',

// ── Inventory ────────────────────────────────────────────────────────
// Inventory
VIEW_INVENTORY = 'view:inventory',
CREATE_INVENTORY = 'create:inventory',
UPDATE_INVENTORY = 'update:inventory',
DELETE_INVENTORY = 'delete:inventory',

// ── Blood Units ──────────────────────────────────────────────────────
// Blood Units
VIEW_BLOODUNIT_TRAIL = 'view:bloodunit:trail',
REGISTER_BLOOD_UNIT = 'register:bloodunit',
TRANSFER_CUSTODY = 'transfer:custody',
LOG_TEMPERATURE = 'log:temperature',

// ── Dispatch ─────────────────────────────────────────────────────────
// Dispatch
VIEW_DISPATCH = 'view:dispatch',
CREATE_DISPATCH = 'create:dispatch',
UPDATE_DISPATCH = 'update:dispatch',
DELETE_DISPATCH = 'delete:dispatch',
MANAGE_DISPATCH = 'manage:dispatch',

// ── Users ─────────────────────────────────────────────────────────────
// Users
VIEW_USERS = 'view:users',
MANAGE_USERS = 'manage:users',
DELETE_USER = 'delete:user',

// ── Notifications ────────────────────────────────────────────────────
// Notifications
VIEW_NOTIFICATIONS = 'view:notifications',
MANAGE_NOTIFICATIONS = 'manage:notifications',

// ── Maps ─────────────────────────────────────────────────────────────
// Maps
VIEW_MAPS = 'view:maps',

// ── Blockchain / Soroban ──────────────────────────────────────────────
// Blockchain / Soroban
MANAGE_SOROBAN = 'manage:soroban',
VIEW_BLOCKCHAIN = 'view:blockchain',

// ── Admin ─────────────────────────────────────────────────────────────
// Medical Record Templates
CREATE_TEMPLATE = 'create:template',
VIEW_TEMPLATES = 'view:templates',
CREATE_RECORD_FROM_TEMPLATE = 'create:record:from-template',

// Admin
ADMIN_ACCESS = 'admin:access',
MANAGE_ROLES = 'manage:roles',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IsObject, IsOptional } from 'class-validator';

export class CreateRecordFromTemplateDto {
@IsObject()
@IsOptional()
data?: Record<string, unknown>;
}
18 changes: 18 additions & 0 deletions backend/src/medical-records/dto/create-template.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IsString, IsBoolean, IsObject, IsNotEmpty, IsOptional } from 'class-validator';

export class CreateTemplateDto {
@IsString()
@IsNotEmpty()
name: string;

@IsString()
@IsNotEmpty()
recordType: string;

@IsObject()
schemaJson: Record<string, unknown>;

@IsBoolean()
@IsOptional()
isPublic?: boolean;
}
31 changes: 31 additions & 0 deletions backend/src/medical-records/entities/medical-record.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';

@Entity('medical_records')
export class MedicalRecordEntity {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ name: 'provider_id' })
providerId: string;

@Column({ name: 'template_id', nullable: true, type: 'varchar' })
templateId: string | null;

@Column({ name: 'record_type', length: 100 })
recordType: string;

@Column({ type: 'jsonb' })
data: Record<string, unknown>;

@CreateDateColumn({ name: 'created_at' })
createdAt: Date;

@UpdateDateColumn({ name: 'updated_at' })
updatedAt: Date;
}
34 changes: 34 additions & 0 deletions backend/src/medical-records/entities/record-template.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm';

@Entity('record_templates')
export class RecordTemplateEntity {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ name: 'provider_id' })
providerId: string;

@Column({ length: 255 })
name: string;

@Column({ name: 'record_type', length: 100 })
recordType: string;

@Column({ name: 'schema_json', type: 'jsonb' })
schemaJson: Record<string, unknown>;

@Column({ name: 'is_public', default: false })
isPublic: boolean;

@CreateDateColumn({ name: 'created_at' })
createdAt: Date;

@UpdateDateColumn({ name: 'updated_at' })
updatedAt: Date;
}
13 changes: 13 additions & 0 deletions backend/src/medical-records/medical-records.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RecordTemplateEntity } from './entities/record-template.entity';
import { MedicalRecordEntity } from './entities/medical-record.entity';
import { TemplatesService } from './templates.service';
import { TemplatesController } from './templates.controller';

@Module({
imports: [TypeOrmModule.forFeature([RecordTemplateEntity, MedicalRecordEntity])],
controllers: [TemplatesController],
providers: [TemplatesService],
})
export class MedicalRecordsModule {}
44 changes: 44 additions & 0 deletions backend/src/medical-records/templates.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
Body,
Controller,
Get,
Param,
Post,
Req,
} from '@nestjs/common';
import { TemplatesService } from './templates.service';
import { CreateTemplateDto } from './dto/create-template.dto';
import { CreateRecordFromTemplateDto } from './dto/create-record-from-template.dto';
import { RequirePermissions } from '../auth/decorators/require-permissions.decorator';
import { Permission } from '../auth/enums/permission.enum';

interface AuthRequest extends Request {
user: { id: string; email: string; role: string };
}

@Controller()
export class TemplatesController {
constructor(private readonly templatesService: TemplatesService) {}

@RequirePermissions(Permission.CREATE_TEMPLATE)
@Post('templates')
createTemplate(@Req() req: AuthRequest, @Body() dto: CreateTemplateDto) {
return this.templatesService.createTemplate(req.user.id, dto);
}

@RequirePermissions(Permission.VIEW_TEMPLATES)
@Get('templates')
listTemplates(@Req() req: AuthRequest) {
return this.templatesService.listTemplates(req.user.id);
}

@RequirePermissions(Permission.CREATE_RECORD_FROM_TEMPLATE)
@Post('records/from-template/:templateId')
createRecordFromTemplate(
@Req() req: AuthRequest,
@Param('templateId') templateId: string,
@Body() dto: CreateRecordFromTemplateDto,
) {
return this.templatesService.createRecordFromTemplate(req.user.id, templateId, dto);
}
}
Loading