Initial commit: digital reception monorepo (M1-M11 + demo extensions)

This commit is contained in:
2026-05-25 12:59:54 +05:00
commit b9f88194d9
182 changed files with 20578 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
export interface RecognizeResult {
patient_id: string;
confidence: number;
distance: number;
}
@Injectable()
export class FaceClient {
private readonly logger = new Logger(FaceClient.name);
private readonly baseUrl: string;
constructor(config: ConfigService) {
this.baseUrl = config.getOrThrow<string>('FACE_SERVICE_URL');
}
async recognize(frameBase64: string): Promise<RecognizeResult | null> {
const res = await fetch(`${this.baseUrl}/recognize`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ frame: frameBase64 }),
});
if (!res.ok) {
this.logger.warn(`face-service /recognize failed: ${res.status}`);
return null;
}
const json = (await res.json()) as RecognizeResult | null;
return json;
}
async enrollTrack(trackId: string, patientId: string): Promise<number> {
const res = await fetch(`${this.baseUrl}/enroll`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ track_id: trackId, patient_id: patientId }),
});
if (!res.ok) {
throw new Error(`face-service /enroll failed: ${res.status}`);
}
const json = (await res.json()) as { embeddings_attached: number };
return json.embeddings_attached;
}
async deletePatientEmbeddings(patientId: string): Promise<number> {
const res = await fetch(`${this.baseUrl}/patient/${patientId}/embeddings`, {
method: 'DELETE',
});
if (!res.ok) {
this.logger.warn(`face-service DELETE /patient/.../embeddings failed: ${res.status}`);
return 0;
}
const json = (await res.json()) as { deleted: number };
return json.deleted;
}
async countPatientEmbeddings(patientId: string): Promise<number> {
const res = await fetch(`${this.baseUrl}/patient/${patientId}/count`);
if (!res.ok) return 0;
const json = (await res.json()) as { count: number };
return json.count;
}
}
+9
View File
@@ -0,0 +1,9 @@
import { Global, Module } from '@nestjs/common';
import { FaceClient } from './face.client';
@Global()
@Module({
providers: [FaceClient],
exports: [FaceClient],
})
export class FaceModule {}