# Project plan — magalies-pharma-heisenberg-print-server

Evidence date: 2026-10-09.

Source repository: `git@bitbucket.org:overdrive/magalies-pharma-heisenberg-print-server.git`.

Inspected revision: `master` at `07aa3df` (2022-10-19, Nick Thorby, "updated description"). Only remote branch: `master`. `origin/HEAD` points at `master`. History is 59 commits, from `ea73a4b` (2022-07-05, "seperate printers") to `07aa3df`.

This plan describes what the repository contains. It does not decide what the product should become.

There is no prior Silicon Ark directory for this project. The repository README is the heading "Heisenberg Print Server" and nothing else. `package.json` names the package `heisenberg-test-print`. Provenance: **Documented** in `README.md` and `package.json`.

The local scan path named when this task was created (`~/projects/sonar_scan/repos/magalies-pharma-heisenberg-print-server`) was not present on this machine. Evidence below is from a read-only clone of `origin/master`. `sonar-project.properties` and `sonarqube_scan.bat` were listed beside the git files at task creation and are not in git history.

## Product

**Inferred.** A local HTTP service that turns a JSON request into Zebra ZPL and sends it as a raw print job to a named operating-system printer. The name Heisenberg matches the Magalies Pharma API documented in Silicon Ark as `magalies-pharma-heisenberg-serverless`. This repository does not call that API.

**Implemented.** An Express application in `server.js` listens on port 3000. `POST /barcode` and `POST /label` render Handlebars ZPL templates and call `@thiagoelg/node-printer` `printDirect` with `type: "RAW"`.

**Unknown / Requires Confirmation:** whether anyone still runs this process, which host it runs on, and which application posts to it.

## Branch reality

| Line | Tip | Date | What it is |
|---|---|---|---|
| `master` (default; `origin/HEAD`) | `07aa3df` | 2022-10-19 | Only branch on the Bitbucket remote. 59 commits, 2022-07-05 through 2022-10-19 |

No other local or remote branches were present at inspection. Nothing in git is dated after 2022-10-19.

Earlier remotes appear only inside merge commit messages:

- `49c6f3e` (2022-07-26) merges `gitlab.assemble.co.za:magalies-pharma/heisenberg-print-server`.
- `f22c5fc` and `7ec216f` (2022-10-12) merge `ssh://git-codecommit.eu-west-1.amazonaws.com/v1/repos/magalies-pharma-heisenberg-print-server`, including a branch named `testing/local`.

Those remotes and `testing/local` are not on the current Bitbucket repository. Whether the CodeCommit or GitLab copies still exist is **Unknown / Requires Confirmation**.

Authors: Nick Thorby (`nick@exonic.co.za`, also committed as `Nick`) and Jordan Levy (`jordan@exonic.co.za`, and one commit as `jord@Jordans-MacBook-Pro.local`).

## Objectives

No objectives file exists. The behaviour the commits actually introduced, in order:

1. `ea73a4b` (2022-07-05) — Express server, two printer queue names, barcode and label print functions, Handlebars templates `templates/barcodes.hbs` and `templates/labels.hbs`.
2. `4ef494e` (2022-07-26) — templates become ZPL (`templates/barcodes.zpl`, `templates/labels.zpl`, `templates/labels_small.zpl`). `.hbs` files removed.
3. `e6dd1b9`, `474a821`, `31a691d` (2022-07-26 and 2022-08-22) — commit subjects say the codes changed to QR.
4. `b39d737` (2022-08-24) — batch number added to the request, the print functions, and the templates.
5. `f9a9c98` (2022-10-12) — three printer names. `size == 'small'` selects the small queue; every other size selects the large queue.
6. `593ccfa` (2022-10-12, "fixed qr codes ignoring letters") — QR field data gains leading commas (`^FD,,{{barcode}}`) so the value is not parsed as the ZPL mode switches.
7. `231ccd3` (2022-10-19) — queue names change from `XP-TT426B` / `XP-TT426B-2` to `Small-Label-Printer`, `Barcode-Printer`, and `Big-Label-Printer`.
8. `a44f442` (2022-10-19) — barcode body field `barcode` becomes `batch_number`. Label body fields `barcode` and `batch_number` become `medicine_number` and `order_number`. Standard label text swaps "Dispensed By" for prescriber and date.
9. `16e84dc` (2022-10-19, "fixed print loop") — `printLabel` sends one raw job after the loop. Before this commit it called `printDirect` on every iteration, and each call included every label generated so far.
10. `a3fdeb9` (2022-10-19, "fixed missing dash") — medicine QR payload becomes `{medicine_number}-{four digits}`. The previous commit had dropped the dash.
11. `07aa3df` (2022-10-19, "updated description") — JSON field and function parameter `label_description` renamed to `description` in `server.js` and `print.js`.

## Scope

### In scope of `master` at `07aa3df`

1. `server.js` — HTTP routes and printer queue names.
2. `print.js` — ZPL render and raw print.
3. `templates/barcodes.zpl`, `templates/labels.zpl`, `templates/labels_small.zpl`.
4. `package.json` and `package-lock.json` — npm manifest and lockfileVersion 2.
5. `README.md` — title only.
6. `.gitignore` — ignores `node_modules`.
7. `.DS_Store` and `.print.js.swp` — tracked, not application code. The swap file was added in `b7319b4` (2022-09-21, "Label changes made locally").

11 tracked files. `node_modules` is not tracked.

### Out of scope / not in this repository

- A Heisenberg front end, the serverless API, a database, or a user account store.
- Dockerfile, CI pipeline, environment file, process manager, or install notes.
- Tests. `npm test` is `echo "Error: no test specified" && exit 1`.
- `index.js`. `package.json` `main` is `index.js`, and that file is not in the tree.
- `sonar-project.properties` and `sonarqube_scan.bat`. Listed by the onboarding scan. Not in git history.
- The operating-system print queues and the physical printers. The code only stores queue name strings.

## Architecture

```text
HTTP client (not in this repo)
  POST /barcode or POST /label, JSON body
    -> server.js (Express, port 3000, cors(), body-parser JSON)
      -> print.js
        -> Handlebars compile of a ZPL template loaded at startup
        -> one RAW job via @thiagoelg/node-printer printDirect
          -> OS printer queue named in server.js
```

There is no database, queue, worker, or outbound HTTP client in this repository.

The barcode string this service prints is `{batch_number}-{four digits}`. The medicine label QR is `{medicine_number}-{four digits}`. Silicon Ark's `magalies-pharma-heisenberg-serverless` PRD says the pack-scan handler treats the substring before the first `-` as the batch number or the catalogue medicine number. This print repository does not mention that API. The match is **Inferred** and **Requires Confirmation**.

## Milestones

No milestone list is in the repository. The commit dates are the only schedule:

| Window | What landed |
|---|---|
| 2022-07-05 | First commit: two routes, two printer names, Handlebars templates |
| 2022-07-26 | ZPL templates, small label, QR field data |
| 2022-08-22 to 2022-09-27 | Batch fields, label copy, on-site template edits |
| 2022-10-04 to 2022-10-12 | `testing/local` merged from CodeCommit; three printers; QR comma fix |
| 2022-10-19 | Queue rename, field rename, print-loop fix, dash fix, `description` rename. Last commit |

No later milestone is written down.

## Implementation plan

There is no open plan in git. The tree at `07aa3df` is the whole implementation. Changing it would mean editing `server.js`, `print.js`, and the three ZPL files, then running the process with `node server.js` on a machine where the named print queues exist. That run command is **Inferred**: there is no `start` script, and `server.js` is the file that calls `app.listen`.

## Dependencies known from the repository

| Dependency | Pinned by lockfile | Role |
|---|---|---|
| `express` 4.18.1 | yes | HTTP server |
| `body-parser` 1.20.0 | yes | JSON body |
| `cors` 2.8.5 | yes | `app.use(cors())` with no options |
| `handlebars` 4.7.7 | yes | ZPL templates. Required as `handlebars/lib` |
| `@thiagoelg/node-printer` 0.5.6 | yes | Raw print. Required as `@thiagoelg/node-printer/lib`. Lockfile sets `hasInstallScript` and depends on `nan` and `prebuild-install` |

Node.js version is not declared in `package.json`. The native printer module has to match the machine that prints. **Unknown / Requires Confirmation** which Node version that machine uses.

## Current status

**Implemented** and unchanged in git since 2022-10-19. No deploy record is in the repository. Whether the process is still in use is **Unknown / Requires Confirmation**.

## Human confirmation

- Is this process still running, and on which computer?
- Do the operating-system queues still use the names `Small-Label-Printer`, `Barcode-Printer`, and `Big-Label-Printer`?
- The queue names before `231ccd3` were `XP-TT426B` and `XP-TT426B-2` (and, briefly, `Xprinter XP-TT426B`). Is that still the printer model?
- Which program calls port 3000?
- Is the `{id}-{four digits}` QR meant to be scanned by the Heisenberg pack-scan API?
- Were `sonar-project.properties` and `sonarqube_scan.bat` only on the scan host?
- Does the CodeCommit or GitLab remote still hold history that Bitbucket does not?
