As part of the Relativity Services API (RSAPI) Deprecation, content on this page referring to the RSAPI and the Patient Tracker application is in the process of being deprecated and will no longer be supported. For more information and alternative APIs, see RSAPI deprecation process.

Advanced custom page code sample

You can develop a unique UI for your applications by creating custom pages. This advanced sample code illustrates how to create a custom page by using the Model-View-Controller (MVC) architectural pattern. The implementation of this custom page uses MVC 4 ASP.NET. It includes files for the data domain, business logic, and the UI elements.

This page contains the following information:

Model code sample

The code sample for the model includes objects representing your data.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PatientTracker.CustomPages.Models
{
    public class PatientModel
    {
        public Int32 PatientArtifactID { get; set; }
        public String FirstName { get; set; }
        public String LastName { get; set; }
        public DateTime DateOfBirth { get; set; }
        public String PatientNotes { get; set; }
        public String PicturePath { get; set; }
    }
}

View code sample

The code sample for the view includes elements that appear in the UI.

@model PatientTracker.CustomPages.Models.PatientModel

@{
    ViewBag.Title = "Patient";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Patient Profile</h2>

<fieldset>
    <legend>Patient</legend>

    <img src="@Model.PicturePath" style="margin-top:15px;margin-bottom:15px;border:5px solid #5A9BC7;display:block;" />

    <div class="display-label">
        First Name: 
    </div>
    <div class="display-field">
            @Html.DisplayFor(model => model.FirstName)
     </div>
    <div class="display-label">
        Last Name: 
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.LastName)
    </div>

    <div class="display-label">
        Date of Birth: 
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.DateOfBirth)
    </div>

    <div class="display-label">
        Notes: 
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.PatientNotes)
    </div>
</fieldset>

Controller code sample

The code sample for the controller includes the business logic for retrieving and displaying data.

Note: For more information about using helpers to connect to the Services API, see Connect to the Services API with the client-side proxy and Using Relativity API Helpers.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace PatientTracker.CustomPages.Controllers
{
    /// <summary>
    /// This custom page shows how to use a patient artifactID and current workspace artifactID to retrieve information from the RSAPI, and then display a profile page for the patient.
    /// </summary>
    public class PatientController : Controller
    {
        public static readonly Guid PATIENT_RDO_GUID = new Guid("EDC3AF33-7D25-4897-8285-6E36EA1D4AAE");

        public static readonly Guid FIRST_NAME_FIELD_GUID = new Guid("EB024552-3A1B-40C1-B4DC-5815C3DD3AD3");
        public static readonly Guid LAST_NAME_FIELD_GUID = new Guid("DA73E11E-9D02-4D29-9D3C-F84E66223B2A");
        public static readonly Guid GENDER_FIELD_GUID = new Guid("04E5F293-A4E1-4DF4-8816-F1E6645AE001");
        public static readonly Guid DATE_OF_BIRTH_FIELD_GUID = new Guid("96BC22AF-F2F6-4C92-AD96-CF08BF9AAB4D");
        public static readonly Guid PATIENT_NOTES_FIELD_GUID = new Guid("5702F31B-48AC-4E2A-9000-A48B3E3ABDBF");
        public static readonly Guid PICTURE_FIELD_GUID = new Guid("006F21C0-66C8-46E0-94B2-EF37C6478C2D");

        public ActionResult Index(Int32 patientArtifactID, Int32 workspaceArtifactID)
        {
            PatientTracker.CustomPages.Models.PatientModel patient = new Models.PatientModel();
            kCura.Relativity.Client.DTOs.RDO patientRDO = null;

            try
            {
                //Create an instance of the RSAPIClient so we can pull back information about the patient.
                using (kCura.Relativity.Client.IRSAPIClient client = Relativity.CustomPages.ConnectionHelper.Helper().GetServicesManager().CreateProxy<kCura.Relativity.Client.IRSAPIClient>(Relativity.API.ExecutionIdentity.System))
                {
                    //Set the workspace artifactID.
                    client.APIOptions.WorkspaceID = workspaceArtifactID;

                    //Create an instance of the RDO with the Patient RDO GUID and the patient artifactID.
                    patientRDO = new kCura.Relativity.Client.DTOs.RDO(patientArtifactID);
                    patientRDO.ArtifactTypeGuids.Add(PATIENT_RDO_GUID);
                    patientRDO.Fields = kCura.Relativity.Client.DTOs.FieldValue.AllFields;

                    //Get the patient RDO from the RSAPI.
                    patientRDO = client.Repositories.RDO.Read(patientRDO).Results[0].Artifact;

                    //Set properties on the patient model.
                    patient.FirstName = patientRDO.Fields.Where(x => x.Guids.Contains(FIRST_NAME_FIELD_GUID)).Single().ValueAsFixedLengthText;
                    patient.LastName = patientRDO.Fields.Where(x => x.Guids.Contains(LAST_NAME_FIELD_GUID)).Single().ValueAsFixedLengthText;
                    patient.DateOfBirth = patientRDO.Fields.Where(x => x.Guids.Contains(DATE_OF_BIRTH_FIELD_GUID)).Single().ValueAsDate.Value;
                    patient.PatientNotes = patientRDO.Fields.Where(x => x.Guids.Contains(PATIENT_NOTES_FIELD_GUID)).Single().ValueAsLongText;

                    //Construct a download request used to get a proper download url for the file to be downloaded.
                    kCura.Relativity.Client.DownloadURLRequest pictureFieldDownloadRequest = new kCura.Relativity.Client.DownloadURLRequest(client.APIOptions);
                    Uri currentUrl = Request.Url;
                    pictureFieldDownloadRequest.BaseURI = new Uri(String.Format("{0}://{1}/", currentUrl.Scheme, currentUrl.Host));
                    pictureFieldDownloadRequest.Target.FieldGuid = PICTURE_FIELD_GUID;
                    pictureFieldDownloadRequest.Target.ObjectArtifactId = patientArtifactID;

                    //Set the picture file path on the patient model.
                    patient.PicturePath = client.Repositories.RDO.GetFileFieldDownloadURL(pictureFieldDownloadRequest).URL;
                }
            }
            catch (System.Exception ex)
            {
                patient.PatientNotes = "EXCEPTION: " + ex.ToString();
            }

            return View(patient);
        }

    }
}

Additional Resources

DevHelp Community GitHub Release Notes NuGet

Share knowledge with the Relativity developer community.

Access tools and resources to build an application.

Review the most recent product release notes.

Create .NET Apps faster with NuGet.