emr-types
Version:
Comprehensive TypeScript Types Library for Electronic Medical Record (EMR) Applications - Domain-Driven Design with Zod Validation
126 lines • 3.58 kB
JavaScript
/**
* Domain-Specific Utility Types
*
* Utility types for domain operations and transformations
*/
import { Status } from '../enums/Status';
import { Priority } from '../enums/Priority';
/**
* Domain Validation Utilities
*/
export var ValidationUtils;
(function (ValidationUtils) {
/**
* Composite validation rule
*/
class CompositeValidationRule {
constructor(rules) {
this.rules = rules;
}
validate(value) {
const errors = [];
for (const rule of this.rules) {
const result = rule.validate(value);
if (!result.isValid) {
errors.push(...result.errors);
}
}
return {
isValid: errors.length === 0,
errors
};
}
}
ValidationUtils.CompositeValidationRule = CompositeValidationRule;
})(ValidationUtils || (ValidationUtils = {}));
/**
* Domain Type Guards
*/
export var TypeGuards;
(function (TypeGuards) {
/**
* Check if value is a valid ID
*/
TypeGuards.isValidId = (value) => {
return value && typeof value === 'object' && 'value' in value && 'type' in value;
};
/**
* Check if value is a valid Timestamp
*/
TypeGuards.isValidTimestamp = (value) => {
return value && typeof value === 'object' && 'value' in value && 'date' in value;
};
/**
* Check if value is a valid Money
*/
TypeGuards.isValidMoney = (value) => {
return value && typeof value === 'object' && 'amount' in value && 'currency' in value;
};
/**
* Check if value is a valid Email
*/
TypeGuards.isValidEmail = (value) => {
return value && typeof value === 'object' && 'value' in value && 'localPart' in value;
};
/**
* Check if value is a valid PhoneNumber
*/
TypeGuards.isValidPhoneNumber = (value) => {
return value && typeof value === 'object' && 'value' in value && 'countryCode' in value;
};
/**
* Check if value is a valid Address
*/
TypeGuards.isValidAddress = (value) => {
return value && typeof value === 'object' && 'value' in value && 'street' in value;
};
/**
* Check if value is a valid Status
*/
TypeGuards.isValidStatus = (value) => {
return Object.values(Status).includes(value);
};
/**
* Check if value is a valid Priority
*/
TypeGuards.isValidPriority = (value) => {
return Object.values(Priority).includes(value);
};
})(TypeGuards || (TypeGuards = {}));
/**
* Domain Transformation Utilities
*/
export var TransformUtils;
(function (TransformUtils) {
/**
* Transform entity to DTO
*/
TransformUtils.entityToDTO = (entity) => ({
id: entity.id.value,
createdAt: entity.createdAt.isoString,
updatedAt: entity.updatedAt.isoString
});
/**
* Transform DTO to entity
*/
TransformUtils.dtoToEntity = (dto, entityFactory) => {
return entityFactory(dto);
};
/**
* Transform entity to API response
*/
TransformUtils.entityToResponse = (entity) => ({
success: true,
data: entity,
timestamp: new Date().toISOString()
});
/**
* Transform error to API response
*/
TransformUtils.errorToResponse = (error) => ({
success: false,
error: error.message,
timestamp: new Date().toISOString()
});
})(TransformUtils || (TransformUtils = {}));
//# sourceMappingURL=DomainUtils.js.map