# Smile CDR Tutorial - Custom Operations

This tutorial guides you through the process of adding custom operations to a Smile CDR FHIR Repository. If your operations do not require an underlying FHIR Repository, you should consider using a [Hybrid Providers REST Endpoint Module](/content/docs/hybrid_providers/hybrid_providers_intro.html) instead.

This tutorial adds two operations to a Smile CDR FHIR Repository:

- System level `/$process-message` operation
- Patient level `Patient/id/$calculate-y2k-age` operation

**1\. Install Smile CDR**

Install Smile CDR either [from a tarball](/content/docs/quickstart/smile_quickstart.html) or [using Docker](/content/docs/guide_installation/docker_container_installation.html).

**2\. Build and Install the Custom Operations Demo Project**

Download and unzip the cdr-consent-demoproject using one of the links below.

- [cdr-persistence-custom-operations-demoproject.zip](/content/docs/downloads/cdr-persistence-custom-operations-demoproject.zip)
- [cdr-persistence-custom-operations-demoproject.tar.gz](/content/docs/downloads/cdr-persistence-custom-operations-demoproject.tar.gz)

Make any desired changes to the example custom operations in `src/main/java/com/example/resourceprovider/CustomOperations.java`. E.g. you could add new `@Operation` methods or change the logic in the existing methods. See the [HAPI FHIR documentation](https://hapifhir.io/hapi-fhir/docs/server_plain/rest_operations_operations.html#rest-operations-extended-operations) for more details on how to define new FHIR operations.

Now build the project and install the interceptor jar file in your smilecdr/customerlib directory.

```bash
cd cdr-persistence-custom-operations-demoproject
mvn clean install
cp target/cdr-persistence-custom-operations-demoproject-*.jar path/to/smilecdr/customerlib
```

Copy

**3\. Start Smile CDR**

Start Smile CDR by running the following command:

```bash
$ bin/smilecdr start
```

Copy

**4\. Access the Web Admin Console**

Access the Web Admin Console by navigating to the following URL in your web browser:
[http://localhost:9100](http://localhost:9100/)

Log in with the default credentials "admin", "password".

**5\. Give the Anonymous User FHIR Client Superuser Permissions**

Since this is just a testing sandbox, we will ignore security considerations for now and just give the anonymous user FHIR Client supseruser permissions.

Navigate to `Users & Authorization``User Management`.

Click on `Edit` next to the `ANONYMOUS` user.

Enable the FHIR Client (Superuser) permission (ROLE\_FHIR\_CLIENT\_SUPERUSER).

Click `Save User`.

**6\. Configure the FHIR Endpoint to Use the Custom Operations**

Navigate to `Configuration``Module Config`.

Click on `fhir_endpoint` on the left-hand side.

In the `Resource Providers` section, set `Resource Provider Bean Types` to `com.example.customoperations.CustomOperations`.

Click `Save`.

Click `Restart` to restart the FHIR Endpoint module.

**7\. Test /$process-message**

Using a REST client like Bruno or Postman, test the custom operations.

```http
POST /$process-message?async=false

{
  "resourceType": "Bundle",
  "id": "INPUT-TEST-BUNDLE-ID",
  "type": "message",
  "entry": [\
    {\
      "resource": {\
        "resourceType": "Patient",\
        "name": [\
          {\
            "given": [\
              "Toody"\
            ]\
          }\
        ]\
      }\
    }\
  ]
}
```

Copy

The response will look something like this:

```json
{
  "resourceType": "Bundle",
  "id": "OUTPUT-TEST-BUNDLE-ID"
}
```

Copy

**8\. Test Patient/$calculate-y2k-age**

Start by creating a new patient resource:

```http
PUT /Patient/sally-field

{
  "resourceType": "Patient",
  "id": "sally-field",
  "birthDate": "1946-11-06"
}
```

Copy

Now test the custom operation:

```http
GET /Patient/sally-field/$calculate-y2k-age
```

Copy

This should produce the following response:

```json
{
  "resourceType": "Parameters",
  "parameter": [ {\
    "name": "y2k-age",\
    "valueInteger": 53\
  } ]
}
```

Copy

[Integration Testing Tutorial](/content/docs/guide_tutorials/tutorial_integration_test.html)

Custom Operations Tutorial

Tutorials

[Introduction](/content/docs/guide_tutorials/tutorial_intro.html)
[Integration Testing Tutorial](/content/docs/guide_tutorials/tutorial_integration_test.html)
[Custom Operations Tutorial](/content/docs/guide_tutorials/tutorial_custom_operations.html)
[HL7 v2.x Ingestion Tutorial](/content/docs/guide_tutorials/tutorial_processing_hl7_v2x_feeds.html)
[Federated OAuth2/OIDC Tutorial](/content/docs/guide_tutorials/tutorial_federated_oauth2.html)
[MDM Tutorial](/content/docs/guide_tutorials/tutorial_mdm.html)
[MDM UI Tutorial](/content/docs/guide_tutorials/tutorial_mdm_ui.html)
[MDM First Golden Resource Tutorial](/content/docs/guide_tutorials/first_golden_resource.html)
[MDM Advanced Rule Authoring Tutorial](/content/docs/guide_tutorials/advanced_rule_authoring.html)
[MDM Web UI Admin Setup Tutorial](/content/docs/guide_tutorials/mdm_web_ui_admin_setup.html)
[CDA Import Tutorial](/content/docs/guide_tutorials/tutorial_cda_import.html)
[CDA Export Tutorial](/content/docs/guide_tutorials/tutorial_cda_export.html)
[CDA Export - Custom Narrative Generation Tutorial](/content/docs/guide_tutorials/tutorial_cda_export_narrative_generation.html)
[CDA Import JSON example](/content/docs/guide_tutorials/tutorial_cda_import_json.html)
[CDA Export Template JSON example](/content/docs/guide_tutorials/tutorial_cda_export_json.html)
[Consent Tutorial](/content/docs/guide_tutorials/tutorial_consent.html)
[CMS-0057-F IG Setup Tutorial](/content/docs/guide_tutorials/tutorial_terminology_cms57f.html)

[HL7 v2.x Ingestion Tutorial](/content/docs/guide_tutorials/tutorial_processing_hl7_v2x_feeds.html)
