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

astm-nestjs-module

v1.0.0

Published

NestJS Module nhận và xử lý kết quả từ các máy xét nghiệm thông qua giao thức ASTM

Readme

ASTM NestJS Module

Module NestJS nhận và xử lý kết quả từ các máy xét nghiệm thông qua giao thức ASTM và các protocol khác.

Tính năng

  • Multi-Protocol Support: ASTM, HL7, LIS2A2, Raw data
  • Real-time Communication: WebSocket gateway cho real-time monitoring
  • MongoDB Logging: Tự động log tất cả dữ liệu vào MongoDB
  • Device Management: Tự động nhận dạng thiết bị dựa trên IP/Port mapping
  • Session Logging: Tạo log file riêng cho mỗi session kết nối
  • Error Handling: Xử lý lỗi và response tự động cho các protocol

Cài đặt

# Install dependencies
npm install

# Build project
npm run build

# Start development server
npm run start:dev

# Start production server
npm run start:prod

Cấu hình

Tạo file .env hoặc cấu hình environment variables:

PORT=1008
HOST=0.0.0.0
DEBUG=true
TIMEOUT=30000
LOG_DIRECTORY=./logs
MONGODB_URI=mongodb://localhost:27017/astm-lab-data
MONGODB_DB_NAME=astm-lab-data

Cấu trúc dự án

src/
├── common/
│   ├── interfaces/          # Interfaces chung
│   └── utils/              # Utilities
├── config/
│   └── app.config.ts       # Cấu hình ứng dụng
├── gateway/
│   └── protocol.gateway.ts # WebSocket gateway cho TCP server
├── modules/
│   ├── mongodb/            # MongoDB service
│   └── protocol/           # Protocol handlers
│       ├── handlers/       # Các protocol handlers
│       ├── interfaces/     # Protocol interfaces
│       └── dto/           # Data Transfer Objects
├── app.module.ts          # Root module
└── main.ts               # Bootstrap file

Protocol Handlers

ASTM Protocol

  • Xử lý ENQ/ACK handshake
  • Parse STX/ETX frames với checksum
  • Tự động response ACK/NAK

HL7 Protocol

  • Parse HL7 messages và segments
  • Tạo ACK/NACK responses
  • Hỗ trợ MSH segment parsing

LIS2A2 Protocol

  • Xử lý SOH/EOT messages
  • STX/ETX frame với sequence numbers
  • Checksum validation

Raw Protocol

  • Phân tích raw data
  • Detect encoding và characteristics
  • Protocol detection hints

Device Mapping

Cấu hình mapping thiết bị trong app.config.ts:

labDeviceMapping: [
  { ip: '192.168.25.107', name: 'Máy XN HbA1c AdamA1C', port: 10001 },
  { ip: '192.168.25.107', name: 'Máy Cobas6000 số 1', port: 10008 },
  // ...thêm các thiết bị khác
]

WebSocket Events

Client có thể lắng nghe các events:

  • server_started - Server đã khởi động
  • client_connected - Thiết bị kết nối
  • protocol_detected - Phát hiện protocol
  • data_processed - Dữ liệu đã được xử lý
  • client_disconnected - Thiết bị ngắt kết nối
  • server_error - Lỗi server

Logs

  • Session Logs: File log riêng cho mỗi kết nối tại ./logs/
  • MongoDB Logs: Tất cả dữ liệu được log vào collection lab_data_logs
  • Console Logs: Real-time logging với NestJS Logger

Scripts

# Development
npm run start:dev

# Production build và start
npm run build
npm run start:prod

# Testing
npm run test
npm run test:watch
npm run test:cov

# Linting và formatting
npm run lint
npm run format

Migration từ phiên bản cũ

Dự án này được convert từ Node.js thuần sang NestJS architecture:

  • Modular Structure: Tách thành modules rõ ràng
  • Dependency Injection: Sử dụng DI container của NestJS
  • Type Safety: Full TypeScript với interfaces
  • Testing Support: Built-in testing framework
  • Configuration Management: Centralized config với validation
  • WebSocket Integration: Real-time communication capability

Môi trường phát triển

  • Node.js >= 16.0.0
  • TypeScript
  • NestJS Framework
  • MongoDB
  • Socket.io (cho WebSocket)