npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

emr-types

v0.1.0

Published

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

Readme

emr-types

npm version License: MIT TypeScript

Comprehensive TypeScript Types Library for Electronic Medical Record (EMR) Applications

A comprehensive, type-safe TypeScript library for Electronic Medical Record (EMR) applications. Built with Domain-Driven Design principles, featuring robust type safety, runtime validation with Zod, and excellent developer experience.

🚀 Features

  • 🏥 Healthcare Focus: Complete types for medical records, patients, appointments, and healthcare standards
  • 🛡️ Type Safety: 100% TypeScript strict mode compliance with branded types
  • ✅ Runtime Validation: Comprehensive Zod schema validation for all types
  • 📝 Form System: Type-safe form handling with validation
  • ⏰ Date/Time: Healthcare-specific date/time management
  • 🏗️ Domain-Driven Design: Clear domain boundaries and aggregate roots
  • 🔧 Utilities: Form, validation, and date/time utilities
  • 📊 Performance: Optimized bundle size and compilation

📦 Installation

npm install emr-types
yarn add emr-types
pnpm add emr-types

🏥 Healthcare Standards Support

  • ICD-10/11: International Classification of Diseases codes
  • CPT/HCPCS: Current Procedural Terminology codes
  • NDC/RxNorm: National Drug Codes and RxNorm
  • LOINC: Logical Observation Identifiers Names and Codes
  • HIPAA: Health Insurance Portability and Accountability Act compliance

🎯 Quick Start

Basic Usage

import { 
  User, 
  UserRole, 
  UserStatus,
  validateSchema,
  UserSchemas 
} from 'emr-types';

// Create a user with type safety
const user: User = {
  id: 'user-123' as any, // Branded type
  email: '[email protected]',
  firstName: 'John',
  lastName: 'Doe',
  role: 'doctor',
  status: 'active',
  tenantId: 'tenant-123' as any,
  createdAt: new Date(),
  updatedAt: new Date()
};

// Validate data at runtime
const userData = {
  email: '[email protected]',
  firstName: 'John',
  lastName: 'Doe',
  role: 'doctor',
  tenantId: 'tenant-123'
};

const result = validateSchema(UserSchemas.CreateUserRequest, userData);
if (result.success) {
  console.log('Valid user data:', result.data);
} else {
  console.log('Validation errors:', result.errors);
}

Form Handling

import { 
  FormField, 
  FormFieldType, 
  FormState,
  createFormValidator,
  UserSchemas 
} from 'emr-types';

// Create type-safe form fields
const userForm: FormField[] = [
  {
    name: 'email',
    label: 'Email',
    type: FormFieldType.EMAIL,
    value: '',
    required: true
  },
  {
    name: 'firstName',
    label: 'First Name',
    type: FormFieldType.TEXT,
    value: '',
    required: true
  }
];

// Create form validator
const validateUserForm = createFormValidator(UserSchemas.CreateUserRequest);

// Form state management
const formState: FormState = {
  values: { email: '', firstName: '' },
  errors: {},
  touched: {},
  dirty: {},
  focused: {},
  isValid: false,
  isDirty: false,
  isSubmitting: false,
  isSubmitted: false,
  submitCount: 0
};

Date/Time Management

import { 
  calculateAge, 
  calculateDuration,
  isInBusinessHours,
  AppointmentTimeSlot 
} from 'emr-types';

// Calculate patient age
const birthDate = new Date('1990-01-01');
const age = calculateAge(birthDate);
console.log(`Patient age: ${age.years} years, ${age.months} months`);

// Appointment time slot
const appointment: AppointmentTimeSlot = {
  start: new Date('2024-01-01T09:00:00Z'),
  end: new Date('2024-01-01T10:00:00Z'),
  duration: 60,
  isAvailable: true,
  isBooked: false
};

// Check business hours
const businessHours = {
  start: '09:00',
  end: '17:00',
  daysOfWeek: [1, 2, 3, 4, 5], // Monday to Friday
  timezone: 'America/New_York'
};

const isAvailable = isInBusinessHours(appointment.start, businessHours);

🏗️ Architecture

Domain-Driven Design

The library follows Domain-Driven Design principles with clear bounded contexts:

  • User Domain: User management, roles, and authentication
  • Tenant Domain: Multi-tenant support and configuration
  • Patient Domain: Patient management and medical history
  • Appointment Domain: Appointment scheduling and management
  • Medical Record Domain: Medical records, diagnoses, and procedures
  • Shared Domain: Common types and utilities

Type Safety

  • Branded Types: Secure ID types with branded strings
  • Union Types: Flexible union types for enums and status values
  • Generic Types: Comprehensive generic type system
  • Conditional Types: Advanced conditional type logic

Runtime Validation

  • Zod Schemas: Complete schema definitions for all types
  • Custom Validation: Healthcare-specific validation rules
  • Error Handling: Detailed error messages and field-specific errors
  • Batch Validation: Batch validation capabilities

📚 API Reference

Core Types

// User Domain
import { User, UserRole, UserStatus } from 'emr-types';

// Tenant Domain
import { Tenant, TenantType, TenantStatus } from 'emr-types';

// Patient Domain
import { Patient, Gender, BloodType } from 'emr-types';

// Appointment Domain
import { Appointment, AppointmentType, AppointmentStatus } from 'emr-types';

// Medical Record Domain
import { MedicalRecord, Diagnosis, Prescription } from 'emr-types';

Validation

import { 
  validateSchema, 
  safeParse, 
  isValid,
  UserSchemas,
  TenantSchemas,
  PatientSchemas 
} from 'emr-types';

// Validate user data
const result = validateSchema(UserSchemas.CreateUserRequest, userData);

// Safe parse with error handling
const parsed = safeParse(UserSchemas.User, userData);

// Quick validation check
const isValidUser = isValid(UserSchemas.User, userData);

Form Utilities

import { 
  FormField, 
  FormState, 
  FormFieldType,
  createFormValidator,
  isFormValid,
  isFormDirty 
} from 'emr-types';

// Create form validator
const validateForm = createFormValidator(UserSchemas.CreateUserRequest);

// Check form state
const isValid = isFormValid(formState);
const isDirty = isFormDirty(formState);

Date/Time Utilities

import { 
  calculateAge, 
  calculateDuration,
  toISODateString,
  parseISODateString,
  isInBusinessHours 
} from 'emr-types';

// Age calculation
const age = calculateAge(birthDate);

// Duration calculation
const duration = calculateDuration(startDate, endDate);

// ISO date handling
const isoDate = toISODateString(date);
const parsedDate = parseISODateString('2024-01-01');

🧪 Testing

Type Testing

import { expectType } from 'tsd';
import { User, UserRole } from 'emr-types';

// Test type inference
expectType<User>({
  id: 'user-123' as any,
  email: '[email protected]',
  firstName: 'John',
  lastName: 'Doe',
  role: 'admin',
  status: 'active',
  tenantId: 'tenant-123' as any,
  createdAt: new Date(),
  updatedAt: new Date()
});

// Test enum values
expectType<UserRole>('admin');

Runtime Testing

import { UserSchemas, validateSchema } from 'emr-types';

describe('User Validation', () => {
  it('should validate valid user data', () => {
    const userData = {
      email: '[email protected]',
      firstName: 'John',
      lastName: 'Doe',
      role: 'doctor',
      tenantId: 'tenant-123'
    };
    
    const result = validateSchema(UserSchemas.CreateUserRequest, userData);
    expect(result.success).toBe(true);
  });
});

📊 Performance

  • Bundle Size: <50KB gzipped
  • Compilation Time: <10 seconds
  • Type Inference: >98% accuracy
  • IDE Performance: <5% impact

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

# Clone the repository
git clone https://github.com/qkit-emr/emr-monorepo.git
cd emr-monorepo/libs/types

# Install dependencies
npm install

# Run type checking
npm run typecheck

# Run tests
npm test

# Build the library
npm run build

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Support

🔗 Related


Built with ❤️ by the QKIT EMR Team