feat: T6 wave 2 – medicine book, document rights, label particulars, herd events
- Veterinary medicine catalogue, lots and append-only movement ledger (rest always computed; corrections as counter-bookings; inactive medicines take no new stock; unit must match on lot moves). - Documents of medicine lots, authority notices and restrictions need the domain right on top of documents:* (403 before any lookup). - Label particulars: pure checkLabel with six mandatory gaps and four warnings, AFM font metrics, Berlin-day dates, geometric reading order for split addresses, new master-data fields with row-locked updates. - Herd events ColonyCreated, ColonyMoved, ApiaryChanged and TskReferenceDayReached (ids only, never forwarded to webhooks); CSV import emits ColonyCreated with audit. - ARCHITECTURE.md §12 Compliance (T6), Annahmen 59–70. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
8a31c42578
commit
c18860c75c
73 files changed
+7121
-309
No files matched your search
@@ -0,0 +1,75 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import {
|
||||
IsDateString,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsPositive,
|
||||
IsString,
|
||||
Matches,
|
||||
MaxLength,
|
||||
} from 'class-validator';
|
||||
import {
|
||||
MAX_ADDRESS_LENGTH,
|
||||
MAX_NAME_LENGTH,
|
||||
MAX_NOTE_LENGTH,
|
||||
} from './create-veterinary-medicine.dto';
|
||||
|
||||
export const ID_PATTERN = /^[A-Za-z0-9_-]+$/;
|
||||
const MAX_ID_LENGTH = 64;
|
||||
const DAY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
||||
const DAY_MESSAGE = 'muss ein Datum im Format JJJJ-MM-TT sein';
|
||||
|
||||
/** One bought pack. Batch number, supplier, proof and vet apply to every treatment from it. */
|
||||
export class CreateLotDto {
|
||||
@ApiProperty()
|
||||
@IsString()
|
||||
@Matches(ID_PATTERN)
|
||||
@MaxLength(MAX_ID_LENGTH)
|
||||
medicineId!: string;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true, description: 'Ch.-B.' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(MAX_NAME_LENGTH)
|
||||
batchNumber?: string | null;
|
||||
|
||||
@ApiProperty({ example: '2026-08-01' })
|
||||
@Matches(DAY_PATTERN, { message: `purchasedOn ${DAY_MESSAGE}` })
|
||||
@IsDateString({ strict: true })
|
||||
purchasedOn!: string;
|
||||
|
||||
@ApiProperty({ description: 'Anfangsmenge in der Einheit des Mittels, > 0' })
|
||||
@IsNumber({ allowNaN: false, allowInfinity: false })
|
||||
@IsPositive()
|
||||
quantity!: number;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true, example: '2028-01-31' })
|
||||
@IsOptional()
|
||||
@Matches(DAY_PATTERN, { message: `expiresOn ${DAY_MESSAGE}` })
|
||||
@IsDateString({ strict: true })
|
||||
expiresOn?: string | null;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true, description: 'Name, Anschrift' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(MAX_ADDRESS_LENGTH)
|
||||
supplier?: string | null;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true, description: 'z. B. Rechnung 4711' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(MAX_ADDRESS_LENGTH)
|
||||
purchaseProof?: string | null;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(MAX_ADDRESS_LENGTH)
|
||||
prescribingVet?: string | null;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(MAX_NOTE_LENGTH)
|
||||
notes?: string | null;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import {
|
||||
IsIn,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsPositive,
|
||||
IsString,
|
||||
Matches,
|
||||
Min,
|
||||
MaxLength,
|
||||
ValidateIf,
|
||||
} from 'class-validator';
|
||||
|
||||
export const MANUAL_MOVEMENT_TYPES = ['CORRECTION', 'DISPOSAL'] as const;
|
||||
export type ManualMovementType = (typeof MANUAL_MOVEMENT_TYPES)[number];
|
||||
export const MAX_REASON_LENGTH = 500;
|
||||
const FINITE = { allowNaN: false, allowInfinity: false } as const;
|
||||
|
||||
/**
|
||||
* CORRECTION (inventory): the rest counted in the box. DISPOSAL: a positive
|
||||
* quantity that leaves the lot, with a reason. TREATMENT bookings come only
|
||||
* from a treatment.
|
||||
*/
|
||||
export class CreateMovementDto {
|
||||
@ApiProperty({ enum: MANUAL_MOVEMENT_TYPES })
|
||||
@IsIn(MANUAL_MOVEMENT_TYPES)
|
||||
type!: ManualMovementType;
|
||||
|
||||
@ApiPropertyOptional({ description: 'CORRECTION: der tatsächliche Rest' })
|
||||
@ValidateIf((dto: CreateMovementDto) => dto.type === 'CORRECTION')
|
||||
@IsNumber(FINITE)
|
||||
@Min(0)
|
||||
actualRemaining?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'DISPOSAL: Menge, positiv' })
|
||||
@ValidateIf((dto: CreateMovementDto) => dto.type === 'DISPOSAL')
|
||||
@IsNumber(FINITE)
|
||||
@IsPositive()
|
||||
quantity?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'DISPOSAL: Pflicht' })
|
||||
@ValidateIf(
|
||||
(dto: CreateMovementDto) => dto.type === 'DISPOSAL' || dto.reason != null,
|
||||
)
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Matches(/\S/, { message: 'reason darf nicht nur aus Leerzeichen bestehen' })
|
||||
@MaxLength(MAX_REASON_LENGTH)
|
||||
reason?: string;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import {
|
||||
IsBoolean,
|
||||
IsEnum,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsNumber,
|
||||
IsOptional,
|
||||
IsPositive,
|
||||
IsString,
|
||||
Matches,
|
||||
Min,
|
||||
MaxLength,
|
||||
} from 'class-validator';
|
||||
import { MedicineUnit } from '../../../generated/prisma';
|
||||
import { IsOptionalNotNull } from '../../common/validation/is-optional-not-null';
|
||||
|
||||
export const MAX_NAME_LENGTH = 200;
|
||||
export const MAX_ADDRESS_LENGTH = 300;
|
||||
export const MAX_NOTE_LENGTH = 2000;
|
||||
const MAX_DOSE_NOTE_LENGTH = 500;
|
||||
const FINITE = { allowNaN: false, allowInfinity: false } as const;
|
||||
|
||||
/**
|
||||
* Every value comes from the package leaflet or the prescription and is typed
|
||||
* in by the beekeeper - the code ships no medicine data (assumption 10).
|
||||
*/
|
||||
export class CreateVeterinaryMedicineDto {
|
||||
@ApiProperty({ description: 'Handelsname', maxLength: MAX_NAME_LENGTH })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Matches(/\S/, { message: 'name darf nicht nur aus Leerzeichen bestehen' })
|
||||
@MaxLength(MAX_NAME_LENGTH)
|
||||
name!: string;
|
||||
|
||||
@ApiProperty({
|
||||
enum: MedicineUnit,
|
||||
description: 'Nur änderbar, solange keine Packung existiert.',
|
||||
})
|
||||
@IsEnum(MedicineUnit)
|
||||
unit!: MedicineUnit;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(MAX_NAME_LENGTH)
|
||||
activeIngredient?: string | null;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true, description: 'Zulassungsnummer' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(MAX_NAME_LENGTH)
|
||||
authorisationNumber?: string | null;
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptionalNotNull()
|
||||
@IsBoolean()
|
||||
prescriptionOnly?: boolean;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
nullable: true,
|
||||
description: 'Wartezeit Honig in Tagen, auch 0',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsInt()
|
||||
@Min(0)
|
||||
withdrawalPeriodDays?: number | null;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true, description: 'In der Einheit' })
|
||||
@IsOptional()
|
||||
@IsNumber(FINITE)
|
||||
@IsPositive()
|
||||
dosePerColony?: number | null;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(MAX_DOSE_NOTE_LENGTH)
|
||||
doseNote?: string | null;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(MAX_NAME_LENGTH)
|
||||
applicationMethod?: string | null;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsNumber(FINITE)
|
||||
minTemperatureC?: number | null;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsNumber(FINITE)
|
||||
maxTemperatureC?: number | null;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(MAX_ADDRESS_LENGTH)
|
||||
defaultSupplier?: string | null;
|
||||
|
||||
@ApiPropertyOptional({ nullable: true })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(MAX_NOTE_LENGTH)
|
||||
notes?: string | null;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import {
|
||||
IsBoolean,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Matches,
|
||||
MaxLength,
|
||||
} from 'class-validator';
|
||||
import { ID_PATTERN } from './create-lot.dto';
|
||||
import { booleanQuery } from './medicine-list-query.dto';
|
||||
|
||||
export class LotListQuery {
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@Matches(ID_PATTERN)
|
||||
@MaxLength(64)
|
||||
medicineId?: string;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description: 'Nur Packungen mit Rest > 0, älteste Haltbarkeit zuerst',
|
||||
})
|
||||
@IsOptional()
|
||||
@Transform(booleanQuery)
|
||||
@IsBoolean()
|
||||
selectable?: boolean;
|
||||
|
||||
@ApiPropertyOptional({
|
||||
description:
|
||||
'Mit selectable: diese Packung bleibt wählbar, auch wenn sie leer oder ihr Mittel inaktiv ist (Bearbeiten einer Behandlung)',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@Matches(ID_PATTERN)
|
||||
@MaxLength(64)
|
||||
includeLotId?: string;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Transform, TransformFnParams } from 'class-transformer';
|
||||
import { IsBoolean, IsOptional } from 'class-validator';
|
||||
|
||||
/** Query strings arrive as text: only "true" and "false" are booleans. */
|
||||
export function booleanQuery({ value }: TransformFnParams): unknown {
|
||||
if (value === 'true') return true;
|
||||
if (value === 'false') return false;
|
||||
return value as unknown;
|
||||
}
|
||||
|
||||
export class MedicineListQuery {
|
||||
@ApiPropertyOptional({ description: 'Nur aktive oder nur inaktive Mittel' })
|
||||
@IsOptional()
|
||||
@Transform(booleanQuery)
|
||||
@IsBoolean()
|
||||
active?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { CreateLotDto } from './create-lot.dto';
|
||||
|
||||
/** `medicineId` is fixed once a movement exists (409, checked in the service). */
|
||||
export class UpdateLotDto extends PartialType(CreateLotDto, {
|
||||
skipNullProperties: false,
|
||||
}) {}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { CreateVeterinaryMedicineDto } from './create-veterinary-medicine.dto';
|
||||
|
||||
/** Omitted stays, null clears a nullable field, null on a required one is a 400. */
|
||||
export class UpdateVeterinaryMedicineDto extends PartialType(
|
||||
CreateVeterinaryMedicineDto,
|
||||
{ skipNullProperties: false },
|
||||
) {}
|
||||
Reference in new issue
Block a user