namespace Pluto.Api {
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using RemObjects.SDK;
    using RemObjects.SDK.Types;
    using RemObjects.SDK.Server;
    using RemObjects.SDK.Server.ClassFactories;
    using PlutoServer.PracticeChoice;

    [RemObjects.SDK.Server.ClassFactories.StandardClassFactory()]
    [RemObjects.SDK.Server.Service(Name = "Patient", InvokerClass = typeof(Patient_Invoker), ActivatorClass = typeof(Patient_Activator))]
    public class Patient : RemObjects.SDK.Server.Service, IPatient {
        private System.ComponentModel.Container components = null;
        public Patient() :
            base() {
            this.InitializeComponent();
        }
        private void InitializeComponent() {
        }
        protected override void Dispose(bool aDisposing) {
            if(aDisposing) {
                if((this.components != null)) {
                    this.components.Dispose();
                }
            }
            base.Dispose(aDisposing);
        }

        #region IPatient Members

        public virtual PrescribedMedicationInfo1[] GetMedications(string apiKey, int chartId) {
            if(Utility.IsAPIKeyValid(apiKey)){
                var authToken = (string)this.Session[SessionKeys.AuthToken];
                var patient = new PlutoServer.PracticeChoice.Core.Patient();
                var medsList = patient.GetMedications(authToken, chartId);
                return medsList.ToArray();
            }else{
                return null;
            }
        }

        public virtual AllergyInfo1[] GetAllergies(string apiKey, int chartId) {
            if(Utility.IsAPIKeyValid(apiKey)) {
                var authToken = (string)this.Session[SessionKeys.AuthToken];
                var patient = new PlutoServer.PracticeChoice.Core.Patient();
                var allergyList = patient.GetAllergies(authToken, chartId);
                return allergyList.ToArray();
            } else {
                return null;
            }
        }

        public ProblemInfo1[] GetProblems(string apiKey, int chartId) {
            if(Utility.IsAPIKeyValid(apiKey)) {
                var authToken = (string)this.Session[SessionKeys.AuthToken];
                var patient = new PlutoServer.PracticeChoice.Core.Patient();
                var problemList = patient.GetProblems(authToken, chartId);
                return problemList.ToArray();
            } else {
                return null;
            }
        }

        public ChartInfo1 GetChart(string apiKey, int patientId, int chartId) {
            if(Utility.IsAPIKeyValid(apiKey)) {
                var authToken = (string)this.Session[SessionKeys.AuthToken];
                var patient = new PlutoServer.PracticeChoice.Core.Patient();
                var chartInfo = patient.GetChart(authToken, patientId, chartId);
                return chartInfo;
            } else {
                return null;
            }
        }

        public VitalSignInfo1[] GetVitalSigns(string apiKey, int patientId, int chartId) {
            if(Utility.IsAPIKeyValid(apiKey)) {
                var authToken = (string)this.Session[SessionKeys.AuthToken];
                var patient = new PlutoServer.PracticeChoice.Core.Patient();
                var vsList = patient.GetVitalSigns(authToken, chartId, patientId);
                return vsList.ToArray();
            } else {
                return null;
            }
        }

        public void AddNote(string apiKey, int patientId, int chartId, PatientNoteInfo1 patientNote) {
            if(Utility.IsAPIKeyValid(apiKey)) {
                var authToken = (string)this.Session[SessionKeys.AuthToken];
                var patient = new PlutoServer.PracticeChoice.Core.Patient();
                patient.AddPatientNote(authToken, patientId, chartId, patientNote);
            }
        }

        public PatientNoteInfo1[] GetNotes(string apiKey, int patientId, int chartId) {
            if(Utility.IsAPIKeyValid(apiKey)) {
                var authToken = (string)this.Session[SessionKeys.AuthToken];
                var patient = new PlutoServer.PracticeChoice.Core.Patient();
                var notes = patient.GetNotes(authToken, patientId, chartId);
                return notes.ToArray();
            } else {
                return null;
            }
        }

        public ProcedureInfo1[] GetProcedures(string apiKey, int chartId) {
            if(Utility.IsAPIKeyValid(apiKey)) {
                var authToken = (string)this.Session[SessionKeys.AuthToken];
                var patient = new PlutoServer.PracticeChoice.Core.Patient();
                var procedures = patient.GetProcedures(authToken, chartId);
                return procedures.ToArray();
            } else {
                return null;
            }
        }

        #endregion
    }
}
