emr-types
Version:
Comprehensive TypeScript Types Library for Electronic Medical Record (EMR) Applications - Domain-Driven Design with Zod Validation
184 lines • 4.77 kB
JavaScript
import { IdFactory, IdValidator } from '../../shared/value-objects/Id';
// ============================================================================
// PATIENT ID FACTORY
// ============================================================================
/**
* Factory for creating PatientId instances
*/
export const PatientIdFactory = {
/**
* Create a new PatientId with a random UUID
*/
create() {
return IdFactory.create();
},
/**
* Create a PatientId from a string value
*/
fromString(value) {
return IdFactory.fromString(value);
},
/**
* Create a PatientId from a UUID string
*/
fromUuid(uuid) {
return IdFactory.fromString(uuid);
},
/**
* Create a PatientId from a ULID string
*/
fromUlid(ulid) {
return IdFactory.fromString(ulid);
},
/**
* Create a custom PatientId with specific format
*/
createCustom(value, format) {
return IdFactory.createCustom(value, format);
}
};
// ============================================================================
// PATIENT ID VALIDATOR
// ============================================================================
/**
* Validator for PatientId instances
*/
export const PatientIdValidator = {
/**
* Check if a PatientId is valid
*/
isValid(id) {
return IdValidator.isValid(id);
},
/**
* Validate the format of a PatientId string
*/
validateFormat(value) {
return IdValidator.validateFormat(value);
},
/**
* Check if a PatientId is empty
*/
isEmpty(id) {
return IdValidator.isEmpty(id);
},
/**
* Compare two PatientId instances for equality
*/
areEqual(id1, id2) {
return IdValidator.areEqual(id1, id2);
}
};
// ============================================================================
// PATIENT ID UTILITIES
// ============================================================================
/**
* Utility functions for PatientId
*/
export const PatientIdUtils = {
/**
* Convert PatientId to string
*/
toString(id) {
return id.value;
},
/**
* Get the type of PatientId
*/
getType(id) {
return id.type;
},
/**
* Check if PatientId is a UUID
*/
isUuid(id) {
return id.type === 'uuid';
},
/**
* Check if PatientId is a ULID
*/
isUlid(id) {
return id.type === 'ulid';
},
/**
* Check if PatientId is a custom ID
*/
isCustom(id) {
return id.type === 'custom';
},
/**
* Check if PatientId is an auto-increment ID
*/
isAutoIncrement(id) {
return id.type === 'auto-increment';
}
};
// ============================================================================
// TYPE GUARDS
// ============================================================================
/**
* Type guard to check if a value is a PatientId
*/
export function isPatientId(value) {
return (typeof value === 'object' &&
value !== null &&
'value' in value &&
'type' in value &&
'__brand' in value &&
value.__brand === 'PatientId');
}
/**
* Type guard to check if a string can be converted to a PatientId
*/
export function isValidPatientIdString(value) {
return PatientIdValidator.validateFormat(value);
}
// ============================================================================
// CONSTANTS
// ============================================================================
/**
* Common PatientId formats
*/
export const PATIENT_ID_FORMATS = {
UUID: 'uuid',
ULID: 'ulid',
CUSTOM: 'custom',
AUTO_INCREMENT: 'auto_increment'
};
/**
* Default PatientId format
*/
export const DEFAULT_PATIENT_ID_FORMAT = PATIENT_ID_FORMATS.UUID;
// ============================================================================
// EXAMPLES
// ============================================================================
/**
* Example usage of PatientId
*/
export const PatientIdExamples = {
/**
* Create a new PatientId
*/
createNew: () => PatientIdFactory.create(),
/**
* Create from UUID string
*/
fromUuid: (uuid) => PatientIdFactory.fromUuid(uuid),
/**
* Create from ULID string
*/
fromUlid: (ulid) => PatientIdFactory.fromUlid(ulid),
/**
* Create custom PatientId
*/
createCustom: (value, format) => PatientIdFactory.createCustom(value, format),
/**
* Validate PatientId
*/
validate: (id) => PatientIdValidator.isValid(id),
/**
* Convert to string
*/
toString: (id) => PatientIdUtils.toString(id)
};
//# sourceMappingURL=PatientId.js.map