How yokenzan/receiptisan works
This project, receiptisan, is a command-line Ruby application aimed at parsing and previewing electronic receipt files (specifically for inpatient “出来高レセプト”) from a standardized input file (RECEIPTC.UKE). The tool uses a mix of CSV master files and configuration files (organized by year) to manage parsing rules such as abbreviations and tagging, and it offers various output formats (SVG, YAML, JSON) for the receipt preview.
Main Components
• Command-Line Interface (CLI)
– Entry point provided by files such as exe/receiptisan and the bin scripts.
– This layer manages the user commands (e.g., “--preview”) and delegates to lower-level modules.
• Parser Module
– Located within lib/receiptisan/model/receipt_computer/digitalized_receipt and its parser subdirectories.
– Responsible for interpreting the receipt file’s content, handling buffer, context, and producing an internal representation.
• Master Data & Configuration Management
– The “config” and “csv/master” directories indicate that the application supports multiple years and different configuration files (e.g., abbrev and tag files).
– The modules under lib/receiptisan/model/receipt_computer/master handle the lookup of diagnosis, treatment, and other master data.
• Output/Preview Generation
– Implemented in lib/receiptisan/output/preview.
– This component takes processed data and generates preview outputs (HTML with embedded SVG, YAML or JSON for internal data).
• Utility & Helper Components
– Contains utility functions, formatting, date manipulation, and common IO-handling.
– Found under lib/receiptisan/util and related subdirectories.
• Testing & CI Integration
– The “spec” and “.github/workflows” directories indicate automated tests and continuous integration processes (via workflows such as release.yml and ruby.yml).
Relationships and Interactions
• The CLI layer receives user input and calls the core engine.
• The core engine uses the parser module to read input receipt files.
• The parser interfaces with configuration and CSV master data modules to correctly interpret the content.
• After processing, the output module then generates the preview in the specified format.
• Utility modules support all above components with common functionality such as formatting and encoding.
• The testing suite validates the behavior relations through unit tests structured in the “spec” directories.
Architectural Patterns and Design Principles
• Separation of Concerns: Each main component (CLI, Parser, Master/Config, Output) is isolated to enhance maintainability.
• Modular Design: The directory structure clearly separates functional modules (e.g., digitalized_receipt, master, output preview).
• Layered Architecture: Input flows from the CLI layer down through the model (with parsing and business logic) then up to the output layer.
• Extensibility: The design allows for future expansion (e.g., extending support beyond inpatient receipts or adding new formats) by keeping responsibilities separate.
Additional Elements to Incorporate
• For every component, add a label (e.g., “CLI – Entry Point”, “Parser – Digital Receipt Parser”, “Master – Configuration & Lookup”, “Output – Preview Renderer”).
• User Input → CLI → Parser.
• Parser → Master Data Module (for lookup/config).
• Parser → Output Module (for generating previews).