emr-types
Version:
Comprehensive TypeScript Types Library for Electronic Medical Record (EMR) Applications - Domain-Driven Design with Zod Validation
132 lines • 5.65 kB
JavaScript
/**
* Schemas Exports
*
* Placeholder for Zod validation schemas
*/
// ============================================================================
// SCHEMA EXPORTS
// ============================================================================
// Domain-specific schemas - export only schemas, not types to avoid conflicts
export { UserSchemas, UserIdSchema, EmailSchema, PasswordSchema, UserRoleSchema, UserStatusSchema, CreateUserRequestSchema, UpdateUserRequestSchema, LoginRequestSchema, UserResponseSchema, UserListResponseSchema } from './user-schemas';
export { TenantSchemas, TenantIdSchema, DomainNameSchema, TenantStatusSchema, TenantTypeSchema, CreateTenantRequestSchema, UpdateTenantRequestSchema, TenantResponseSchema, TenantListResponseSchema } from './tenant-schemas';
export { PatientSchemas, PatientIdSchema, PhoneNumberSchema, PatientStatusSchema, GenderSchema, BloodTypeSchema, CreatePatientRequestSchema, UpdatePatientRequestSchema, PatientResponseSchema, PatientListResponseSchema } from './patient-schemas';
export { AppointmentSchemas, AppointmentIdSchema, TimeSlotSchema, DurationSchema, AppointmentStatusSchema, AppointmentTypeSchema, CreateAppointmentRequestSchema, UpdateAppointmentRequestSchema, AppointmentResponseSchema, AppointmentListResponseSchema } from './appointment-schemas';
export { MedicalRecordSchemas, MedicalRecordIdSchema, MedicalRecordStatusSchema, CreateMedicalRecordRequestSchema, UpdateMedicalRecordRequestSchema, MedicalRecordResponseSchema, MedicalRecordListResponseSchema } from './medical-record-schemas';
export { SharedSchemas, IdSchema, TimestampSchema, MoneySchema, StatusSchema, PrioritySchema, PaginationSchema, SortSchema, FilterSchema, SearchSchema, ApiResponseSchema, PaginatedResponseSchema, ErrorResponseSchema } from './shared-schemas';
// ============================================================================
// SCHEMA COLLECTIONS
// ============================================================================
import { UserSchemas } from './user-schemas';
import { TenantSchemas } from './tenant-schemas';
import { PatientSchemas } from './patient-schemas';
import { AppointmentSchemas } from './appointment-schemas';
import { MedicalRecordSchemas } from './medical-record-schemas';
import { SharedSchemas } from './shared-schemas';
export const AllSchemas = {
User: UserSchemas,
Tenant: TenantSchemas,
Patient: PatientSchemas,
Appointment: AppointmentSchemas,
MedicalRecord: MedicalRecordSchemas,
Shared: SharedSchemas
};
// ============================================================================
// VALIDATION UTILITIES
// ============================================================================
export const ValidationUtils = {
User: UserSchemas.ValidationUtils,
Tenant: TenantSchemas.ValidationUtils,
Patient: PatientSchemas.ValidationUtils,
Appointment: AppointmentSchemas.ValidationUtils,
MedicalRecord: MedicalRecordSchemas.ValidationUtils,
Shared: SharedSchemas.ValidationUtils
};
// ============================================================================
// SCHEMA VALIDATION HELPERS
// ============================================================================
export const SchemaValidationHelpers = {
/**
* Validate data against a schema and return detailed error information
*/
validateWithDetails: (schema, data) => {
try {
const result = schema.parse(data);
return { success: true, data: result };
}
catch (error) {
if (error.errors) {
return {
success: false,
errors: error.errors.map((err) => err.message),
details: error.errors
};
}
return {
success: false,
errors: [error.message || 'Validation failed']
};
}
},
/**
* Validate data against a schema and return simple boolean result
*/
isValid: (schema, data) => {
try {
schema.parse(data);
return true;
}
catch {
return false;
}
},
/**
* Safe parse that doesn't throw exceptions
*/
safeParse: (schema, data) => {
try {
const result = schema.parse(data);
return { success: true, data: result };
}
catch (error) {
return { success: false, error: error.message || 'Validation failed' };
}
},
/**
* Transform data using schema (useful for data cleaning)
*/
transform: (schema, data) => {
return schema.parse(data);
}
};
// ============================================================================
// SCHEMA UTILITIES
// ============================================================================
export const SchemaUtils = {
/**
* Get all available schemas
*/
getAllSchemas: () => AllSchemas,
/**
* Get schemas for a specific domain
*/
getDomainSchemas: (domain) => AllSchemas[domain],
/**
* Get validation utils for a specific domain
*/
getDomainValidationUtils: (domain) => ValidationUtils[domain],
/**
* Check if a schema exists
*/
hasSchema: (domain, schemaName) => {
const domainSchemas = AllSchemas[domain];
return domainSchemas && schemaName in domainSchemas;
},
/**
* Get schema by name
*/
getSchema: (domain, schemaName) => {
const domainSchemas = AllSchemas[domain];
return domainSchemas?.[schemaName];
}
};
//# sourceMappingURL=index.js.map