Complete Guide to Medical Archive Digitization: OCR & Full-Text Search for SIMRS Efficiency
N
Back to Blog

Complete Guide to Medical Archive Digitization: OCR & Full-Text Search for SIMRS Efficiency

Tutorial
Nugroho Setiawan · Konsultan IT & Full Stack Developer 10 May 2026 17 min baca 3,676 kata 542 views
This article discusses a practical guide to digitizing medical archives using OCR and full-text search technology, specifically for implementation in SIMRS and clinic environments. Learn concrete steps, technology options, and best practices to improve operational efficiency and data accuracy. Optim

In this fast-paced digital era, stacks of physical archives in hospitals, clinics, or other healthcare institutions often become a major obstacle to operational efficiency. Imagine, a medical records officer has to spend hours just to find a single patient document from thousands of files stored in the archive warehouse. Besides consuming time and space, the risk of damage, loss, or even non-compliance with regulations such as PMK 269/2008 on Medical Records becomes a real threat. This challenge is increasingly complex with the need for data integration into modern hospital management information systems (SIMRS), as well as data exchange standards such as BPJS, SatuSehat, and FHIR R4 that demand fast and accurate availability of digital data. Without the right solution, the potential for medical errors and decreased quality of patient services can increase significantly. This article will guide you in depth on how Optical Character Recognition (OCR) and Full-Text Search technology can be a revolutionary answer to this problem. We will thoroughly examine from basic concepts, technical architecture, code implementation examples, to best practices for building a robust and integrated archive digitization system, ensuring every crucial piece of information can be accessed in seconds.

Basic Concepts of Archive Digitization with OCR and Full-Text Search

Archive digitization is the process of converting physical documents into digital format. Two main pillars in effective digitization, especially for medical archives, are Optical Character Recognition (OCR) and Full-Text Search. OCR is a technology capable of identifying text from images or scanned documents and converting it into editable and searchable text. Imagine you scan a patient medical record containing diagnoses, medication history, and lab results. Without OCR, the document is just a static image. With OCR, the system can extract the text "Diagnosis: Type 2 Diabetes Mellitus" or "Medication: Metformin 500mg" from the image, making it structured and processable data.

After the text is successfully extracted by OCR, the role of Full-Text Search becomes crucial. Full-Text Search is a search method that allows users to search for keywords within the entire content of digital documents, not just in metadata or document titles. For example, you want to find all patient medical records containing the word "hypertension" or "penicillin allergy" within them. With Full-Text Search, the system can scan billions of characters of text from thousands of OCR-processed documents in milliseconds, providing relevant and accurate results. This is a huge leap from manual searching that can take hours or even days.

The main benefits of implementing OCR and Full-Text Search in medical archive digitization are very significant. First, search efficiency increases drastically. Time previously spent searching for physical documents can be redirected to more productive tasks. A study at a hospital showed a reduction in document search time from an average of 15 minutes to less than 5 seconds after implementing the digital system. Second, data accuracy and information availability increase, reducing the risk of medical errors due to missing or misplaced information. Third, substantial physical space savings, because archive warehouses can be reduced or even eliminated. Fourth, regulatory compliance such as PMK 269/2008 on Medical Records and PMK 36/2019 on Health Information Security becomes easier to achieve because digital data is easier to audit, store securely, and access according to authorization. The digitization process generally involves several stages: document acquisition (scanning or uploading), OCR processing for text extraction, indexing of OCR text for Full-Text Search, and finally, a search interface integrated with SIMRS or other systems.

Technical Implementation: Building an Archive Digitization System

Building a robust archive digitization system requires a solid architecture and the right choice of technology. In the context of integration with SIMRS, a commonly used architecture is an API (Application Programming Interface)-based approach that enables interoperability between systems.

Recommended System Architecture:

  • Frontend: For the user interface, it can be an integrated module within the existing SIMRS, or a separate web application built using a modern framework such as React 18.x or Vue.js 3.x. This allows users to upload documents, view OCR results, and perform searches.
  • Backend: We recommend using Laravel 11.x with PHP 8.2+ for robustness and scalability, or Node.js with NestJS 10.x or Express 4.x for high performance in asynchronous processing. This backend will handle business logic, authentication, authorization, file management, and coordination with the OCR engine and search engine.
  • Transactional Database: PostgreSQL 16 is an excellent choice because it supports the `pg_trgm` extension for fuzzy search and the powerful built-in `textsearch` feature, ideal for storing document metadata and OCR result text.
  • Full-Text Search Engine: For scalability and optimal search performance on large data volumes, Elasticsearch 8.x is the best solution. Elasticsearch provides very fast distributed indexing and search capabilities, suitable for billions of documents.
  • OCR Engine: The choice of OCR engine varies. For on-premise and cost-effective solutions, Tesseract 5.x (open-source) is a popular choice, although it requires careful tuning and image preprocessing. For higher accuracy and ease of use, cloud-based APIs such as Google Cloud Vision API or AWS Textract offer superior accuracy, especially for complex documents and handwriting, but with a per-use cost.
  • File Storage: Original documents (images or PDFs) and raw OCR results should be stored in scalable and redundant object storage, such as MinIO (for on-premise) or AWS S3/Google Cloud Storage (for cloud-based).

Implementation Steps:

  1. Document Acquisition: The user uploads a file (for example, a PDF or JPG from a scanner) through the web interface. The file is temporarily stored on the backend server or directly to object storage.
  2. Sending to OCR Engine: The backend receives the file, stores it permanently in object storage, and sends the file to the OCR engine (for example, calling the Google Cloud Vision API or running the Tesseract command). This process is often done asynchronously using a queue (for example, a Redis queue with Laravel Horizon or RabbitMQ) to avoid timeouts on HTTP requests.
  3. Storing Text Results and Metadata: The text results from the OCR engine (along with metadata such as bounding boxes, detected language) are stored in the PostgreSQL database and/or the Elasticsearch index. Important metadata such as patient ID, document date, document type, and original storage path are also stored.
  4. Indexing for Full-Text Search: The OCR result text is indexed into Elasticsearch or a `tsvector` column in PostgreSQL. This indexing process optimizes the data for fast search, including tokenization, stemming, and stop word removal.
  5. API Integration with SIMRS: The backend provides a RESTful API (for example, /api/documents/search?query=diabetes) that can be called by SIMRS to perform document searches. The search results (for example, a list of document IDs, titles, and excerpts) are returned to SIMRS. SIMRS can then display those documents to the user.

Example Code for OCR and Full-Text Search Implementation

The following is an example implementation code for processing documents with OCR using Tesseract in a Laravel environment, as well as an example implementation of Full-Text Search using PostgreSQL 16.

Example Code 1: Processing Documents with Tesseract OCR in Laravel 11.x

In this example, we will create a Job in Laravel that will receive a document ID, retrieve the file from storage, process it with Tesseract, and save the text results back to the database. Assume you have installed `thiagoalessio/tesseract-ocr-for-php` and the Tesseract CLI on your server.

<?php namespace App\Jobs; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use App\Models\Document; use thiagoalessio\TesseractOCR\TesseractOCR; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Log; class ProcessDocumentForOcr implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; protected $documentId; public function __construct(int $documentId) { $this->documentId = $documentId; } public function handle(): void { $document = Document::findOrFail($this->documentId); $filePath = Storage::disk('local')->path($document->file_path); // Pastikan path file benar try { $ocrText = (new TesseractOCR($filePath)) ->lang('ind', 'eng') // Mendukung Bahasa Indonesia dan Inggris ->psm(3) // Page segmentation mode: Assume a single column of text ->dpi(300) // Resolusi gambar untuk akurasi lebih baik ->run(); $document->ocr_text_content = $ocrText; $document->ocr_processed_at = now(); $document->save(); Log::info("OCR processing successful for document {$document->id}"); // Opsional: Dispatch job untuk indexing ke Elasticsearch if (class_exists('\App\Jobs\IndexDocumentForSearch')) { \App\Jobs\IndexDocumentForSearch::dispatch($document->id); } } catch (\Exception $e) { Log::error("OCR processing failed for document {$document->id}: " . $e->getMessage()); // Tambahkan logika penanganan error, misalnya retry atau notifikasi admin $this->fail($e); } } }

Code Explanation: The `ProcessDocumentForOcr` job will run asynchronously. It retrieves the document file path from the `Document` model, then uses the `TesseractOCR` object to extract text. The `lang('ind', 'eng')` parameter ensures Tesseract attempts to detect text in Indonesian and English, which is important for bilingual medical documents. `psm(3)` is the default page segmentation mode suitable for most single documents. The resulting text is then saved to the `ocr_text_content` column on the `Document` model. If there is a separate Full-Text Search indexing process (e.g., to Elasticsearch), that job can be invoked here.

Code Example 2: Full-Text Search with PostgreSQL 16

PostgreSQL has a built-in Full-Text Search feature that is very powerful and efficient, especially when combined with a GIN index. Below are the steps and an example SQL query.

-- 1. Add a tsvector column to the documents table to store the search index ALTER TABLE documents ADD COLUMN searchable_text TSVECTOR; -- 2. Create a GIN index on the searchable_text column for fast search performance CREATE INDEX documents_searchable_text_gin ON documents USING GIN (searchable_text); -- 3. Create a trigger function to automatically update the searchable_text column when data changes CREATE OR REPLACE FUNCTION update_document_searchable_text() RETURNS TRIGGER AS $$ BEGIN NEW.searchable_text := to_tsvector('indonesian', NEW.title || ' ' || NEW.ocr_text_content || ' ' || NEW.excerpt); RETURN NEW; END; $$ LANGUAGE plpgsql; -- 4. Attach the trigger to the documents table for INSERT or UPDATE operations CREATE TRIGGER update_documents_searchable_text BEFORE INSERT OR UPDATE ON documents FOR EACH ROW EXECUTE FUNCTION update_document_searchable_text(); -- 5. Example search query to find documents containing 'diabetes' AND 'mellitus' SELECT id, title, excerpt, ocr_text_content FROM documents WHERE searchable_text @@ to_tsquery('indonesian', 'diabetes & mellitus'); -- Another example: search for 'asma' OR 'bronchitis' SELECT id, title, excerpt, ocr_text_content FROM documents WHERE searchable_text @@ to_tsquery('indonesian', 'asma | bronchitis'); -- Phrase search example: search for 'tekanan darah tinggi' (with the <- operator) SELECT id, title, excerpt, ocr_text_content FROM documents WHERE searchable_text @@ to_tsquery('indonesian', 'tekanan <-> darah <-> tinggi');

Code Explanation: First, a `searchable_text` column of type `TSVECTOR` is added to the `documents` table. Then, a GIN index is created on this column to speed up searches. The `update_document_searchable_text` function and its accompanying trigger ensure that the `searchable_text` column is updated automatically whenever a new document is added or an existing document is modified. `to_tsvector('indonesian', ...)` converts text into `tsvector` format using the Indonesian dictionary, performing tokenization and stemming. `to_tsquery('indonesian', ...)` converts the search string into a query format that can be matched. The `&` operator means AND, `|` means OR, and `<->` means phrase search (consecutive words).

Example Data Payload and Error Handling

In implementing an archive digitization system, understanding the data structure produced by the OCR engine and how to handle potential errors is key to success. Below is an example of a realistic JSON payload from an OCR API and common error handling scenarios.

Example JSON Payload from Google Cloud Vision API

When you send a document image to a cloud-based OCR service such as Google Cloud Vision API, the response received will contain the extracted text along with detailed metadata, including the location (bounding box) of each word. This data is very valuable for further analysis or for highlighting text in the user interface.

{ "responses": [ { "fullTextAnnotation": { "pages": [ { "text": "REKAM MEDIS PASIEN\nNama: Budi Santoso\nTanggal Lahir: 01-01-1980\nDiagnosis: Diabetes Mellitus Tipe 2\nRiwayat Alergi: Penisilin\nObat Saat Ini: Metformin 500mg (2x sehari)\n...", "blocks": [ { "boundingBox": { "vertices": [{"x":10, "y":10}, {"x":200, "y":10}, {"x":200, "y":30}, {"x":10, "y":30}] }, "paragraphs": [ { "words": [ {"symbols": [{"text":"R"},{"text":"E"},{"text":"K"},{"text":"A"},{"text":"M"}], "boundingBox": {"vertices":[...]} }, {"symbols": [{"text":"M"},{"text":"E"},{"text":"D"},{"text":"I"},{"text":"S"}], "boundingBox": {"vertices":[...]} } ] } ] } ] }, { "textAnnotations": [ { "description": "REKAM MEDIS PASIEN\nNama: Budi Santoso\nTanggal Lahir: 01-01-1980\nDiagnosis: Diabetes Mellitus Tipe 2\nRiwayat Alergi: Penisilin\nObat Saat Ini: Metformin 500mg (2x sehari)\n...", "locale": "id", "boundingBox": {"vertices":[...]} }, { "description": "REKAM", "locale": "id", "boundingBox": {"vertices":[...]} }, { "description": "MEDIS", "locale": "id", "boundingBox": {"vertices":[...]} } ] } ] }

Payload Explanation: The `fullTextAnnotation` object contains all the text extracted from the document, broken down into pages (`pages`), blocks (`blocks`), paragraphs (`paragraphs`), and words (`words`). Each of these elements has a `boundingBox` indicating its location coordinates on the original image. `textAnnotations` provides a more structured list of text, with the first entry often containing the entire document text. From this payload, we can take `fullTextAnnotation.text` to store as `ocr_text_content` in the database and index it for search.

Example Error Message and How to Handle It

One common error in the OCR process is timeout, especially when processing large documents or ones with low image quality. Example error message from Tesseract CLI:

Error: OCR engine timed out after 300 seconds.

Error Scenario: This error occurs when Tesseract takes longer than the specified timeout (for example, 300 seconds or 5 minutes) to process an image. This can be caused by:

  • Very Large File Size: High-resolution images or PDFs with many pages.
  • Document Complexity: Documents with complicated layouts, many images, or hard-to-read handwriting.
  • Insufficient Server Resources: The server runs out of CPU or RAM during the OCR process.
  • Tesseract Configuration Issues: Tesseract gets stuck or cannot find the appropriate language.

How to Handle It:

  1. Extend the Timeout: Adjust the OCR process timeout in your application configuration. However, this is only a temporary solution and does not address the root cause of the performance problem.
  2. Document Preprocessing: Before sending to OCR, perform image preprocessing. This includes image compression, conversion to grayscale, binarization (converting the image to pure black and white), denoising, and deskewing (straightening tilted images). Libraries such as OpenCV or ImageMagick can be used for this.
  3. Split Large Documents: For PDFs with many pages, split them into per-page images and process them in parallel or sequentially. This reduces the load on a single OCR process.
  4. Queue System: Use a queue system (for example, Redis Queue, RabbitMQ, Apache Kafka) to process documents asynchronously. This prevents HTTP requests from timing out and allows the system to retry the process if a temporary failure occurs. Configure a retry mechanism with exponential backoff.
  5. Logging and Notifications: Ensure every error is logged in detail (for example, using Sentry or the ELK Stack) and notifications are sent to the IT administrator for quick action.
  6. Fall-back to Manual Review: For documents that fail OCR processing after several attempts, flag those documents for manual review by staff.
  7. Resource Monitoring: Monitor CPU, RAM, and disk usage on the OCR server. If resources become a bottleneck, consider upgrading the server specifications or performing scaling out (adding more OCR servers).

Best Practices for Archive Digitization with OCR and Full-Text Search

  1. Optimal Image Preprocessing: OCR accuracy depends heavily on the quality of the input image. Perform preprocessing such as binarization, denoising, deskewing, and cropping empty margins before sending the image to the OCR engine. For example, for medical documents that are often photocopies or old scans, using contrast enhancement algorithms can significantly improve accuracy by up to 10-15%. References can be found in the documentation of libraries such as OpenCV or ImageMagick for these techniques.
  2. Choosing the Right OCR Engine: Evaluate OCR engines based on accuracy, language support (including Indonesian), speed, and cost. Tesseract 5.x is suitable for on-premise solutions with low cost, but requires intensive tuning and preprocessing. For the highest accuracy on complex documents or handwriting, Google Cloud Vision API or AWS Textract may be more suitable, although with per-use costs. For medical documents, an OCR accuracy of at least 95% is crucial, especially for patient identity data and diagnoses.
  3. Efficient Indexing Strategy: For fast searches on large data volumes, use the inverted index provided by search engines such as Elasticsearch 8.x. If using PostgreSQL 16, be sure to create a GIN index on the `tsvector` column for optimal performance. Also consider indexing important metadata (such as patient ID, date of birth, document type) as separate fields for faster structured searches.
  4. Strict Data Security: Medical data is sensitive data. Ensure all data is encrypted in transit (HTTPS/TLS 1.2+) and at rest (at rest encryption). Implement strict Role-Based Access Control (RBAC), in accordance with PMK 36/2019 on Health Information Security and the Personal Data Protection Law (UU PDP). A complete audit trail must be recorded for every access and modification of documents.
  5. Scalability Planning from the Start: Design the system to be able to handle an ever-increasing volume of documents over time. Use a microservices-based architecture to separate the OCR, indexing, and search processes so they can be scaled independently. Leverage message queues (for example, Kafka or RabbitMQ) for asynchronous processing and load balancing.
  6. Validation and Quality Control of OCR Results: OCR accuracy, especially for handwriting, is never 100%. Implement "human-in-the-loop" to validate critical data (for example, patient name, medical record number, drug dosage, primary diagnosis) before that data is fully integrated into the SIMRS. The system can highlight parts that have low OCR confidence levels for manual verification.
  7. Comprehensive Backup and Disaster Recovery Strategy: Ensure all digital data, both original documents and OCR result text, is backed up regularly and stored in a separate location (offsite or cloud). Implement a 3-2-1 backup strategy (3 copies of data, on 2 different media, with 1 offsite copy). Perform restoration tests periodically to ensure data can be recovered quickly and accurately in the event of an incident.

FAQ about Archive Digitalization with OCR and Full-Text Search

  1. What is the difference between OCR and Full-Text Search?

    OCR (Optical Character Recognition) is a technology that focuses on the process of converting images of text (for example, from scanned documents or photos) into text that can be edited and searched by a computer. This is the first step in creating a digital archive from physical documents. Meanwhile, Full-Text Search is a search method that allows users to search for keywords within the entire contents of digital documents that are already in text form, not just in the metadata or document title. So, OCR is a tool for obtaining text, and Full-Text Search is a tool for searching within that text.

  2. How accurate is OCR for handwritten medical documents?

    OCR accuracy for handwriting is still a significant challenge and is generally much lower than for printed text. For neat handwriting, accuracy may reach 70-80%, but for unclear or non-standard handwriting, accuracy can be below 50%. Therefore, for handwritten medical documents containing critical information, it is highly recommended to combine OCR with manual validation by medical personnel or to use a specialized Machine Learning model trained with a medical handwriting dataset to improve accuracy.

  3. Can this system be integrated with an existing SIMRS?

    Yes, this archive digitalization system is designed to be integrated with an existing SIMRS through a RESTful API. SIMRS can send scanned documents to be processed by OCR and indexed via the API, or SIMRS can call the search API to get a list of relevant documents based on keywords. This integration allows SIMRS to display digital document search results directly in the user interface, providing a seamless experience for medical staff.

  4. How much does it cost to implement an archive digitalization system like this?

    Implementation costs vary greatly depending on the project scale, document volume, technology choices, and integration complexity. For a medium-sized hospital with tens of thousands to hundreds of thousands of documents, costs can range from tens of millions to hundreds of millions of rupiah. This includes software licenses (if any), cloud API costs (if used), custom development, server infrastructure, and maintenance costs. Open-source solutions such as Tesseract and PostgreSQL can reduce initial licensing costs, but may require more investment in development and tuning.

  5. What about the legality aspect of digital archives in Indonesia?

    Based on the Electronic Information and Transactions Law (UU ITE) Number 11 of 2008 (and its amendments) as well as the Minister of Health Regulation (PMK) Number 36 of 2019 concerning Health Information Security, digital archives are considered valid and have the same legal force as physical archives, provided they meet the requirements of authentication, integrity, and availability. It is important to ensure that the archive digitalization system has audit trail features, digital signatures (if needed), and strict access controls to maintain the validity and security of data in accordance with applicable regulations.

  6. Is there a risk to patient data privacy with this digitalization?

    There is certainly a privacy risk, but it can be managed well. Digitalizing medical archives does increase the potential risk of data leaks if not implemented with adequate security. To mitigate this risk, it is mandatory to implement comprehensive data encryption (both at rest and in transit), strict role-based access control (RBAC), audit trails for every data access and modification activity, and full compliance with PMK 36/2019 and the PDP Law. In addition, regular training for staff on the importance of data privacy is also crucial to prevent unintentional violations.

Archive digitalization with OCR and Full-Text Search is no longer merely an option, but an urgent need for healthcare institutions that want to remain competitive and provide the best service. The benefits of operational efficiency, better data accuracy, regulatory compliance, and long-term cost savings are very real. However, successful implementation requires careful planning, selection of the right technology, and meticulous execution. Do not let piles of physical archives hinder your institution's potential. If you need professional assistance in designing, developing, or implementing an archive digitalization solution integrated with SIMRS, SIM Klinik, or other enterprise systems, do not hesitate to contact Nugroho Setiawan. With our extensive experience in various health and enterprise information systems, we are ready to help you realize modern, efficient, and secure document management. Let's improve the quality of healthcare together!

This article is part of the knowledge base of Nugroho Setiawan, an IT consultant in Jogja (Yogyakarta). Related solutions: SIMRS (Hospital Information System) Clinic Management System SatuSehat Integration. Need a free consultation?

Terakhir diperbarui 18 Oct 2026

Komentar

Komentar ditinjau sebelum tampil.

Belum ada komentar. Jadilah yang pertama!

Butuh bantuan implementasi atau dashboard data?

Saya membantu konsultasi IT, pengembangan aplikasi, dan visualisasi data untuk rumah sakit, klinik, dan bisnis di Yogyakarta (DIY), Magelang, dan sekitarnya.

WhatsApp Jasa Visualisasi Data Demo VizStudio
Produk & Solusi SIMRS ERP Portfolio Konsultasi Gratis