> ## Documentation Index
> Fetch the complete documentation index at: https://hmis-docs.derrickmugabwa.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Worklist lookup and publication

> Configure OIE to retrieve an HMIS accession and create a PACS worklist item.

## Channel identity

| Setting       | Value                            |
| ------------- | -------------------------------- |
| Channel name  | `HMIS Radiology Worklist Lookup` |
| Source        | HTTP Listener                    |
| Destination 1 | HTTP Sender to HMIS              |
| Destination 2 | HTTP Sender to the demo PACS     |
| Data type     | Raw                              |

## Source: HTTP Listener

| Setting         | Value                                          |
| --------------- | ---------------------------------------------- |
| Local interface | `0.0.0.0`                                      |
| Local port      | `6670`                                         |
| Context path    | `/radiology/worklist/`                         |
| Response        | Destination 1 or an appropriate final response |
| Authentication  | None on the internal Compose network           |

HMIS automatically publishes this minimal body after an examination becomes `open`:

```json theme={null}
{
  "pacs_code": "HMIS-PACS",
  "accession_number": "ACC000123"
}
```

Add a JavaScript source-transformer step:

```javascript theme={null}
var request = JSON.parse(String(connectorMessage.getRawData()));

if (!request.pacs_code || !request.accession_number) {
    throw new Error('pacs_code and accession_number are required.');
}

var token = configurationMap.get('hmis_radiology_worklist_token');
if (token === null || String(token) === '') {
    throw new Error('Configure hmis_radiology_worklist_token in the OIE Configuration Map.');
}

channelMap.put('pacs_code', String(request.pacs_code));
channelMap.put('accession_number', String(request.accession_number));
channelMap.put('hmis_worklist_authorization', 'Bearer ' + String(token));
```

## Destination 1: HMIS worklist API

| Setting          | Value                                              |
| ---------------- | -------------------------------------------------- |
| Connector        | HTTP Sender                                        |
| URL              | `http://app/api/v1/radiology/integration/worklist` |
| Method           | GET                                                |
| Body             | Empty                                              |
| Response content | Plain Body                                         |

Query parameters:

| Name               | Value                 |
| ------------------ | --------------------- |
| `pacs_code`        | `${pacs_code}`        |
| `accession_number` | `${accession_number}` |

Headers:

| Name            | Value                            |
| --------------- | -------------------------------- |
| `Authorization` | `${hmis_worklist_authorization}` |
| `Accept`        | `application/json`               |

<Warning>
  Press `Enter` or `Tab` after editing every OIE table cell. An active cell can look populated but lose its value when the channel is saved.
</Warning>

## Destination 1 response transformer

Add a JavaScript response-transformer step that converts the normalized HMIS response to the Orthanc worklist REST shape:

```javascript theme={null}
var responseBody = String(connectorMessage.getResponseData());
var response = JSON.parse(responseBody);

if (response.status !== 'available' || !response.worklist) {
    throw new Error('HMIS did not return an available radiology worklist.');
}

var worklist = response.worklist;
var patient = worklist.patient || {};
var procedure = worklist.procedure || {};

function dicomDate(value) {
    return String(value || '').replace(/-/g, '');
}

function dicomPatientName(value) {
    return String(value || '').trim().replace(/\s+/g, '^');
}

function dicomPriority(value) {
    var priority = String(value || 'routine').toUpperCase();
    return priority === 'URGENT' ? 'HIGH' : priority;
}

var orthancPayload = {
    Tags: {
        PatientID: String(patient.identifier || ''),
        PatientName: dicomPatientName(patient.name),
        PatientBirthDate: dicomDate(patient.date_of_birth),
        PatientSex: String(patient.sex || '').substring(0, 1).toUpperCase(),
        AccessionNumber: String(worklist.accession_number),
        RequestedProcedureID: String(procedure.service_code || worklist.requisition_number),
        RequestedProcedureDescription: String(procedure.service_name || ''),
        RequestedProcedurePriority: dicomPriority(procedure.priority),
        ScheduledProcedureStepSequence: [
            {
                Modality: String(procedure.modality || 'OT'),
                ScheduledProcedureStepID: String(worklist.accession_number),
                ScheduledProcedureStepDescription: String(procedure.service_name || '')
            }
        ]
    }
};

channelMap.put('orthanc_worklist_payload', JSON.stringify(orthancPayload));
```

If your OIE build exposes the response body through `msg` rather than `connectorMessage.getResponseData()`, replace the first line with:

```javascript theme={null}
var responseBody = String(msg);
```

## Destination 2: Orthanc worklist API

| Setting      | Value                                  |
| ------------ | -------------------------------------- |
| Connector    | HTTP Sender                            |
| URL          | `http://orthanc:8042/worklists/create` |
| Method       | POST                                   |
| Content type | `application/json`                     |
| Data type    | Text                                   |
| Body         | `${orthanc_worklist_payload}`          |

This destination is Orthanc-specific. Replace it with the corresponding API, database connector, HL7 order channel, or vendor adapter when using another PACS.

## Verification

After the HMIS queue processes the publication, query DICOM MWL from the mock modality. The accession should appear without requiring a manual `curl` request.
