> ## 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.

# PACS study events relay

> Configure the reusable normalized study-event channel from OIE to HMIS.

## Purpose

`PACS Study Events Relay` is the vendor-neutral inbound boundary. PACS adapters post the same normalized JSON to this channel; the channel authenticates to HMIS using a study-write token.

## Source: HTTP Listener

| Setting                  | Value            |
| ------------------------ | ---------------- |
| Local port               | `6671`           |
| Context path             | `/pacs/studies/` |
| Data type                | Raw              |
| Respond after processing | Yes              |

Add this JavaScript source transformer:

```javascript theme={null}
var rawMessage = String(connectorMessage.getRawData());
var studyEvent = JSON.parse(rawMessage);
var requiredFields = [
    'message_id',
    'pacs_code',
    'external_study_id',
    'study_instance_uid',
    'accession_number',
    'received_at'
];

for (var index = 0; index < requiredFields.length; index++) {
    var field = requiredFields[index];
    if (studyEvent[field] === null || studyEvent[field] === undefined || String(studyEvent[field]) === '') {
        throw new Error(field + ' is required.');
    }
}

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

channelMap.put('study_event_payload', JSON.stringify(studyEvent));
channelMap.put('hmis_study_authorization', 'Bearer ' + String(token));
```

## Destination: HMIS

| Setting      | Value                                             |
| ------------ | ------------------------------------------------- |
| Connector    | HTTP Sender                                       |
| URL          | `http://app/api/v1/radiology/integration/studies` |
| Method       | POST                                              |
| Content type | `application/json`                                |
| Data type    | Text                                              |
| Body         | `${study_event_payload}`                          |

Headers:

| Name            | Value                         |
| --------------- | ----------------------------- |
| `Authorization` | `${hmis_study_authorization}` |
| `Content-Type`  | `application/json`            |
| `Accept`        | `application/json`            |

Use a token with exactly `radiology:studies:write`.

## Outcomes

| HMIS status   | Meaning                                                      |
| ------------- | ------------------------------------------------------------ |
| `processed`   | Study linked to the matching examination                     |
| `duplicate`   | Same message identity and payload already processed          |
| `quarantined` | Message retained but not linked because a safety rule failed |
| `conflict`    | Message identity was reused with a different payload         |

Never treat an HTTP `202` quarantine response as a successfully linked clinical study. Retain the response in OIE message history for reconciliation.
