Tutorial: Creating Automated Official Letter Templates for Hospitals, Clinics, and Institutions
N
Back to Blog

Tutorial: Creating Automated Official Letter Templates for Hospitals, Clinics, and Institutions

Tutorial
Nugroho Setiawan · Konsultan IT & Full Stack Developer 07 Nov 2026 6 min baca 1,228 kata 459 views
A step-by-step guide to building automated official letter templates: unique numbering, PDF rendering, and integration with SIMRS and e-office systems.

In many hospitals and clinics, official letters are still created by copying last month's file, changing the number, then saving again under a different filename. The result is easy to guess: duplicate letter numbers, misspelled recipient names that are only discovered after signing, and digital archives mixed in the folder "Surat 2025 fix final". Yet official letters—assignment letters, leave certificates, official reply letters, external referral letters—follow the same pattern: only 6–8 fields change each time one is issued. This article dissects how to build an automatic official letter template that produces neat PDFs, sequential unique numbers, and indexed archives, using Google Workspace or an open source stack that can be embedded into your SIMRS or e-office.

Map Letter Variables Before Touching Code

The most common mistake is immediately creating a template design. What must be done first is a letter inventory. Take the example of a type C hospital with 220 employees: usually there are 12–16 types of routine official letters, and about 60% of the volume is assignment letters and certificates. If the total issued is 45 letters per week, that means there are 180 letters per month of which 90% can be automated.

From that inventory, extract the variable fields. The minimal data structure I use: nomor_surat, tanggal_surat, tujuan (nama, jabatan, instansi), perihal, isi_ringkas, penandatangan (nama, NIP, jabatan), and tembusan as an array. The number format should follow the agency's official document format, for example 001/RS-BM/XI/2025, with a separate counter per letter type per month—not one global counter, because follow-up letters will make the sequence look messy during an audit.

Place all data in one source: Google Sheets for small scale, or a letter table in the SIMRS database (MySQL 8.0/PostgreSQL 16) for hospital scale. The required columns: id, jenis_surat, nomor, tanggal, tujuan, perihal, status, file_url, created_by. Without the file_url and created_by columns, your e-office will never be able to answer the question "who issued letter number 143 last month".

Inside the template document, use a consistent placeholder convention: {{nomor}}, {{tanggal}}, {{tujuan_nama}}, {{perihal}}, {{isi}}. Do not format Indonesian dates (2 November 2025) inside the template; render the format in code so it is consistent and easy to change when there is a request for a new format.

Automation with Google Docs + Apps Script

For teams already using Google Workspace, the combination of Google Docs and Apps Script (V8 runtime) is the fastest path. Create one template document with placeholders, then one script that duplicates the template, replaces placeholders, exports a PDF, and saves it to Drive. Average processing time is 3–5 seconds per letter.

function buatSurat(d) {
  const tpl = DriveApp.getFileById('TEMPLATE_ID').makeCopy('Surat-' + d.nomor);
  const doc = DocumentApp.openById(tpl.getId());
  const body = doc.getBody();
  ['nomor','tanggal','tujuan_nama','perihal','isi'].forEach(k =>
    body.replaceText('{{' + k + '}}', d[k] || ''));
  doc.saveAndClose();
  DriveApp.getFolderById('FOLDER_PDF').createFile(tpl.getAs('application/pdf'));
  return tpl.getId();
}

For letter numbers, do not rely on counting the last row in the spreadsheet—two users pressing the button at the same time could get the same number. Wrap the counter reading and increment with LockService.getScriptLock(), store the counter value in PropertiesService, and record every used number to the log sheet. This way keeps the sequence unique even if three administrative staff issue letters at the same second.

After the PDF is ready, send a copy to the recipient via GmailApp.sendEmail() with the PDF blob as an attachment, and write metadata to the log sheet. Pay attention to quotas: Apps Script limits execution to 6 minutes and email sending to 1,500 per day for Workspace accounts. For volume above 300 letters per day, split the process into batches with scheduled triggers instead of one long execution.

Open Source Path for SIMRS and E-Office Integration

If employee and patient data must not leave the internal server—a condition increasingly requested since the PDP Law came into effect—use the open source path. Two libraries I use daily: docxtemplater 3.40.x on Node.js 20 for JavaScript-based applications, and docxtpl 0.18 on Python 3.12 for teams that already have a Django or FastAPI backend. Both read .docx templates with {{variabel}} syntax and support loops for cc.

The flow: render .docx, convert to PDF with LibreOffice 7.6 headless (soffice --headless --convert-to pdf), then save to object storage. On a 2 vCPU server, rendering a document takes ±0.4 seconds and PDF conversion ±1.2 seconds, so 100 letters finish in under 3 minutes with one worker. Increase worker parallelism if volume grows.

Its integration into SIMRS/SIM Klinik is just one endpoint, for example POST /api/surat that accepts jenis_surat and id_pegawai, retrieves data from the staffing table, gets a number from the PostgreSQL sequence, renders the document, and returns the PDF URL. This is the pattern we applied when building e-office and ERP modules for clients in Yogyakarta, DIY, and Magelang—official letters, purchase orders, up to warehouse delivery notes use the same template engine.

If your agency already uses certified electronic signatures (BSrE), embed a verification QR and the document's SHA-256 hash into the PDF. That way, printed letters can still be validated for authenticity without needing physical archives.

Best Practices

  1. Separate templates from code. Store .docx/.gdoc in a dedicated folder so administrative staff can edit wording without touching the script.
  2. Use an atomic counter per letter type per period. LockService or a database sequence—never use COUNT(*) + 1.
  3. Log every letter issuance. Record the number, time, creator, and file URL; this is a key asset during internal audits.
  4. Validate required fields before rendering. Reject requests that lack a subject or signatory so that no blank letters are issued by mistake.
  5. Test templates with the longest data. A 45-character recipient name and cc to 6 agencies often break a layout that already looks neat with short sample data.

FAQ

Can it be used without an internet connection?

Yes, with an open-source path (docxtemplater or docxtpl) run on an internal server. Google Docs is only suitable if the institution allows documents to be in the cloud.

How do you handle letters that need a follow-up sequence number?

Provide a number override option for the admin role, but still record it in the log. Do not disable number uniqueness validation—just add a "follow-up" marker in the metadata.

How long does implementation take for 10 letter types?

With data and number formats ready, creating templates plus scripts usually takes 3–5 working days, including testing and adjusting the letterhead.

Can it connect to an existing SIMRS?

Yes, as long as read access to the personnel table or an internal API is available. The safest approach is a separate endpoint that reads data, rather than writing directly to the core SIMRS tables.

Automated official letters are not a big project; the impact is felt quickly because it touches the most frequently repeated daily work. Start with one letter type with the highest volume, measure issuance time before and after, then expand to other types. If you need assistance designing this workflow—or want to integrate it into SIMRS, SIM Klinik, ERP, POS, or an institution's website—our team provides IT consulting and application development for Yogyakarta, DIY, and Magelang. Discuss your needs, and we will map the most suitable templates, numbering workflow, and infrastructure options.

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 E-Office. Need a free consultation?

Terakhir diperbarui 11 Nov 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