# 13. MOMS System

## 13.1 Overview

MOMS (Medical Office Management System) is a real-world application built on SCIOS and Chaprola. It demonstrates the system's capability for managing patient records, journal entries, and daily operations in a medical office environment.

Several additional Chaprola programs were created specifically for MOMS:

## 13.2 Program JINDX

Creates the file PATINDX.DA (patient index) from JOURNAL.DS (sorted journal master file). PATINDX.DA contains the starting record number in JOURNAL.DS where a particular patient's name can be found.

```
>>? RUN JINDX
? JOURNAL.DS PATINDX.DA
```

**PATINDX.DA format** (record length 14):
- Positions 1--7: Patient ID
- Positions 8--14: Record number in JOURNAL.DS (in F 0 format with a period after the 6th digit; use GET with length 6, not 7)

**Note:** JINDX must be run after MERG2 so that all journal entries are available online.

## 13.3 Program JNAME

Creates three daily incremental files representing the day's activity in MOMS. These files enable system recovery and reconstruction.

```
>>? RUN JNAME
? [new patient file] [journal file] [correction file]
```

Typical usage:
```
? PATIENTX.DA JOURNAL.DA PATIENTS.DC
```

Creates three files named with the Julian date:
- **PYYDDD.DA** -- copy of PATIENTX.DA (new patients for the day)
- **JYYDDD.DA** -- copy of JOURNAL.DA (daily journal entries)
- **CYYDDD.DA** -- copy of PATIENTS.DC (changes/corrections for the day)

Where YYDDD is the Julian date on the day the program is run.

**System recovery:** In case of failure, the MOMS system can be rebuilt by appending these daily files to the appropriate master files.

## 13.4 Program MERG1

A file merge program specifically designed for the MOMS patient data system. Merges two sorted patient files into two output files.

```
>>? RUN MERG1
? [input file 1] [input file 2] [output file 1] [output file 2]
```

**Algorithm:**
1. Read one record from each input file.
2. Discard records with blank last-name fields.
3. If Patient IDs match (tie), discard the record from file 2.
4. Write the lexicographically lesser record to output file 1.
5. If a record is found to be out of sorting order, write it to output file 2 instead.

**Result:** Output file 1 contains the properly merged, sorted records. Output file 2 contains any out-of-order records (empty if both inputs were properly sorted).

## 13.5 Program MERG2

Merges daily journal entries (JOURNAL.DA) with the sorted journal master file (JOURNAL.DX or JOURNAL.DS).

```
>>? RUN MERG2
? JOURNAL.DS JOURNAL.DA TEMP
```

**Pre-requisite:** Sort JOURNAL.DA by patient ID, then by date and time before running MERG2.

**Post-processing:**
1. Delete JOURNAL.DS and rename TEMP to JOURNAL.DS.
2. Run Program JINDX to recreate PATINDX.DA.
3. Append JOURNAL.DA to JOURNAL.DN (non-sorted journal master file).

## 13.6 MOMS File Structure

| File | Description |
|------|-------------|
| PATIENTS.DA | Master patient data file |
| PATIENTX.DA | New patients entered for the day |
| PATIENTS.DC | Patient changes/corrections for the day |
| JOURNAL.DA | Daily journal entries |
| JOURNAL.DS | Sorted journal master file |
| JOURNAL.DN | Non-sorted journal master file |
| PATINDX.DA | Patient index into JOURNAL.DS (record length 14) |
| PYYDDD.DA | Daily patient backup (Julian date) |
| JYYDDD.DA | Daily journal backup (Julian date) |
| CYYDDD.DA | Daily correction backup (Julian date) |

## 13.7 Daily Workflow

1. **During the day:** Use SCIENTRY to enter patient data and journal entries.
2. **End of day:** Run JNAME to create incremental backup files.
3. **Sort** JOURNAL.DA by patient ID, then date/time.
4. **Run MERG2** to merge daily journal entries into the master.
5. **Run JINDX** to rebuild the patient index.
6. **Run MERG1** if patient master file needs updating.

---

*Previous: [Ecosystem Programs](12-ecosystem.md) | Next: [Examples](14-examples.md)*
