# Writing letters in GNUmed

## Theory of Operation

GNUmed uses OpenOffice for writing letters. Letter definitions are stored in the database in the form of an OOo template file (.ott) along with some metadata (see table `ref.paperwork_templates`). When the user selects a certain letter template by name GNUmed exports the corresponding template file, starts OOo and opens the template in it. It searches for known placeholders within the new OOo document and replaces them with values corresponding to the current state of GNUmed (active patient etc). It then sets up a callback in OOo in order to be notified about closing of the document. Eventually, GNUmed imports the document into the document archive under the current patient.

## How to add a new letter template to your GNUmed system

- in OpenOffice open a new document
- design the letter template as you please
- where appropriate include placeholders within the document
  - adding a placeholder can be done via the Insert / Field menu
  - the list of known placeholders is here
  - ask for more placeholders on the mailing list
- save it as an .ott OpenOffice document template
- add a new row to the table `ref.paperwork_templates`
  - set the field `engine` to "O"
- import the .ott file into the `template` field for that row

The new template should now be available from within GNUmed.

Next: Test Result Management