UNPKG

emr-types

Version:

Comprehensive TypeScript Types Library for Electronic Medical Record (EMR) Applications - Domain-Driven Design with Zod Validation

184 lines 4.96 kB
import { IdFactory, IdValidator } from '../../shared/value-objects/Id'; // ============================================================================ // APPOINTMENT ID FACTORY // ============================================================================ /** * Factory for creating AppointmentId instances */ export const AppointmentIdFactory = { /** * Create a new AppointmentId with a random UUID */ create() { return IdFactory.create(); }, /** * Create an AppointmentId from a string value */ fromString(value) { return IdFactory.fromString(value); }, /** * Create an AppointmentId from a UUID string */ fromUuid(uuid) { return IdFactory.fromString(uuid); }, /** * Create an AppointmentId from a ULID string */ fromUlid(ulid) { return IdFactory.fromString(ulid); }, /** * Create a custom AppointmentId with specific format */ createCustom(value, format) { return IdFactory.createCustom(value, format); } }; // ============================================================================ // APPOINTMENT ID VALIDATOR // ============================================================================ /** * Validator for AppointmentId instances */ export const AppointmentIdValidator = { /** * Check if an AppointmentId is valid */ isValid(id) { return IdValidator.isValid(id); }, /** * Validate the format of an AppointmentId string */ validateFormat(value) { return IdValidator.validateFormat(value); }, /** * Check if an AppointmentId is empty */ isEmpty(id) { return IdValidator.isEmpty(id); }, /** * Compare two AppointmentId instances for equality */ areEqual(id1, id2) { return IdValidator.areEqual(id1, id2); } }; // ============================================================================ // APPOINTMENT ID UTILITIES // ============================================================================ /** * Utility functions for AppointmentId */ export const AppointmentIdUtils = { /** * Convert AppointmentId to string */ toString(id) { return id.value; }, /** * Get the type of AppointmentId */ getType(id) { return id.type; }, /** * Check if AppointmentId is a UUID */ isUuid(id) { return id.type === 'uuid'; }, /** * Check if AppointmentId is a ULID */ isUlid(id) { return id.type === 'ulid'; }, /** * Check if AppointmentId is a custom ID */ isCustom(id) { return id.type === 'custom'; }, /** * Check if AppointmentId is an auto-increment ID */ isAutoIncrement(id) { return id.type === 'auto-increment'; } }; // ============================================================================ // TYPE GUARDS // ============================================================================ /** * Type guard to check if a value is an AppointmentId */ export function isAppointmentId(value) { return (typeof value === 'object' && value !== null && 'value' in value && 'type' in value && '__brand' in value && value.__brand === 'AppointmentId'); } /** * Type guard to check if a string can be converted to an AppointmentId */ export function isValidAppointmentIdString(value) { return AppointmentIdValidator.validateFormat(value); } // ============================================================================ // CONSTANTS // ============================================================================ /** * Common AppointmentId formats */ export const APPOINTMENT_ID_FORMATS = { UUID: 'uuid', ULID: 'ulid', CUSTOM: 'custom', AUTO_INCREMENT: 'auto-increment' }; /** * Default AppointmentId format */ export const DEFAULT_APPOINTMENT_ID_FORMAT = APPOINTMENT_ID_FORMATS.UUID; // ============================================================================ // EXAMPLES // ============================================================================ /** * Example usage of AppointmentId */ export const AppointmentIdExamples = { /** * Create a new AppointmentId */ createNew: () => AppointmentIdFactory.create(), /** * Create from UUID string */ fromUuid: (uuid) => AppointmentIdFactory.fromUuid(uuid), /** * Create from ULID string */ fromUlid: (ulid) => AppointmentIdFactory.fromUlid(ulid), /** * Create custom AppointmentId */ createCustom: (value, format) => AppointmentIdFactory.createCustom(value, format), /** * Validate AppointmentId */ validate: (id) => AppointmentIdValidator.isValid(id), /** * Convert to string */ toString: (id) => AppointmentIdUtils.toString(id) }; //# sourceMappingURL=AppointmentId.js.map