Class: Mirah::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mirah/client.rb

Overview

A client designed to communicate with the Mirah system in a constrained set of well defined ways. This is a front to the more general Graphql backend which is available.

Patient Methods

Organization Methods

Practitioner Methods

Appointment Methods

Examples:

# Create a new client
client = Mirah::Client.new(host: 'https://api.mirah.com', user_id: 'my_user_id', access_token: 'my_token')

# find a patient
client.find_patient_by_external_id('mrn0001')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, user_id:, access_token:) ⇒ Client

Construct a new Client with the given host and credentials.

Parameters:

  • host (String)

    The host, e.g. 'api.mirah.com'

  • user_id (String)

    Your user id

  • access_token (String)

    Your secret API token.


42
43
44
45
# File 'lib/mirah/client.rb', line 42

def initialize(host:, user_id:, access_token:)
  @client = Graphql.create_client(host: host)
  @client_context = { user_id: user_id, access_token: access_token }
end

Instance Attribute Details

#clientObject (readonly)

Access to the underlying graphql client. You may use this for advanced queries that are not provided as part of the standard library.


49
50
51
# File 'lib/mirah/client.rb', line 49

def client
  @client
end

Instance Method Details

#find_appointment(id) ⇒ Data::Appointment?

Find an appointment by the given Mirah internal UUID. This method should be used if you already know the Mirah identifier. If you wish to query by your own system identifier, you should use #find_appointment_by_external_id

Parameters:

  • id (String)

    Mirah UUID for the appointment

Returns:

Since:

  • 0.1.0


247
248
249
# File 'lib/mirah/client.rb', line 247

def find_appointment(id)
  query_record(Graphql::Queries::AppointmentIdQuery, id, Data::Appointment, 'appointment')
end

#find_appointment_by_external_id(external_id) ⇒ Data::Appointment?

Find an appointment by your external id. This is a convenience method. If you wish to query a list of appointments by external id, please use #query_appointments.

Parameters:

  • external_id (String)

    The identifier of the system of record

Returns:

Since:

  • 0.1.0


257
258
259
260
261
262
# File 'lib/mirah/client.rb', line 257

def find_appointment_by_external_id(external_id)
  query_record_by_external_id(Graphql::Queries::AppointmentExternalIdQuery,
                              external_id,
                              Data::Appointment,
                              'appointmentExternal')
end

#find_organization(id) ⇒ Data::Organization?

Find an organization by the given Mirah internal UUID. This method should be used if you already know the Mirah identifier. If you wish to query by your own system identifier, you should use #find_organization_by_external_id

Parameters:

  • id (String)

    Mirah UUID for the organization

Returns:

Since:

  • 0.1.0


124
125
126
# File 'lib/mirah/client.rb', line 124

def find_organization(id)
  query_record(Graphql::Queries::OrganizationIdQuery, id, Data::Organization, 'organization')
end

#find_organization_by_external_id(external_id) ⇒ Data::Organization?

Find an organization by your external id. This is a convenience method. If you wish to query a list of organizations by external id, please use #query_organizations.

Parameters:

  • external_id (String)

    The identifier of the system of record

Returns:

Since:

  • 0.1.0


134
135
136
137
138
139
# File 'lib/mirah/client.rb', line 134

def find_organization_by_external_id(external_id)
  query_record_by_external_id(Graphql::Queries::OrganizationExternalIdQuery,
                              external_id,
                              Data::Organization,
                              'organizationExternal')
end

#find_patient(id) ⇒ Data::Patient?

Find a patient by the given Mirah internal UUID. This method should be used if you already know the Mirah identifier. If you wish to query by your own system identifier, you should use #find_patient_by_external_id

Parameters:

  • id (String)

    Mirah UUID for the patient

Returns:

  • (Data::Patient, nil)

    the patient, or nil if the record does not exist.

Since:

  • 0.1.0


61
62
63
# File 'lib/mirah/client.rb', line 61

def find_patient(id)
  query_record(Graphql::Queries::PatientIdQuery, id, Data::Patient, 'patient')
end

#find_patient_by_external_id(external_id) ⇒ Data::Patient?

Find a patient by your external id. This is a convenience method. If you wish to query a list of patients by external id, please use #query_patients.

Parameters:

  • external_id (String)

    The identifier of the system of record

Returns:

  • (Data::Patient, nil)

    the patient, or nil if the record does not exist.

Since:

  • 0.1.0


71
72
73
74
75
76
# File 'lib/mirah/client.rb', line 71

def find_patient_by_external_id(external_id)
  query_record_by_external_id(Graphql::Queries::PatientExternalIdQuery,
                              external_id,
                              Data::Patient,
                              'patientExternal')
end

#find_practitioner(id) ⇒ Data::Practitioner?

Find an practitioner by the given Mirah internal UUID. This method should be used if you already know the Mirah identifier. If you wish to query by your own system identifier, you should use #find_practitioner_by_external_id

Parameters:

  • id (String)

    Mirah UUID for the practitioner

Returns:

Since:

  • 0.1.0


182
183
184
# File 'lib/mirah/client.rb', line 182

def find_practitioner(id)
  query_record(Graphql::Queries::PractitionerIdQuery, id, Data::Practitioner, 'practitioner')
end

#find_practitioner_by_external_id(external_id) ⇒ Data::Practitioner?

Find an practitioner by your external id. This is a convenience method. If you wish to query a list of practitioners by external id, please use #query_practitioners.

Parameters:

  • external_id (String)

    The identifier of the system of record

Returns:

Since:

  • 0.1.0


192
193
194
195
196
197
# File 'lib/mirah/client.rb', line 192

def find_practitioner_by_external_id(external_id)
  query_record_by_external_id(Graphql::Queries::PractitionerExternalIdQuery,
                              external_id,
                              Data::Practitioner,
                              'practitionerExternal')
end

#push_appointment(external_id:, status:, **input_values) ⇒ PushResult<Data::Appointment>

Create or update an appointment. You must specify an external identifier, all other parameters are optional, but you may receive errors if you attempt to specify too few parameters for an appointment that does not exist.

Parameters:

  • external_id (String)

    the external identifier for this appointment

  • status (String)

    the status identifier of this appointment, see Data::Appointment#status

  • input_values (Hash)

    a customizable set of options

Options Hash (**input_values):

Returns:

Since:

  • 0.1.0


297
298
299
300
301
# File 'lib/mirah/client.rb', line 297

def push_appointment(external_id:, status:, **input_values)
  mutate(Graphql::Mutations::CreateOrUpdateAppointmentMutation,
         Inputs::AppointmentInput.new(input_values.merge(external_id: external_id, status: status)),
         Data::Appointment, 'createOrUpdateAppointment')
end

#push_organization(external_id:, **input_values) ⇒ PushResult<Data::Organization>

Create or update an organization. You must specify an external identifier, all other parameters are optional, but you may receive errors if you attempt to specify too few parameters for an organization that does not exist.

Parameters:

  • external_id (String)

    the external identifier for this organization

  • input_values (Hash)

    a customizable set of options

Options Hash (**input_values):

  • :name (String, nil)
  • :external_part_of_id (String, nil)

    The external identifier for the parent organization

Returns:

Since:

  • 0.1.0


166
167
168
169
170
# File 'lib/mirah/client.rb', line 166

def push_organization(external_id:, **input_values)
  mutate(Graphql::Mutations::CreateOrUpdateOrganizationMutation,
         Inputs::OrganizationInput.new(input_values.merge(external_id: external_id)),
         Data::Organization, 'createOrUpdateOrganization')
end

#push_patient(external_id:, **input_values) ⇒ PushResult<Data::Patient>

Create or update a patient. You must specify an external identifier, all other parameters are optional, but you may receive errors if you attempt to specify too few parameters for a patient that does not exist.

Parameters:

  • external_id (String)

    the external identifier for this patient

  • input_values (Hash)

    a customizable set of options

Options Hash (**input_values):

Returns:

Since:

  • 0.1.0


108
109
110
111
112
# File 'lib/mirah/client.rb', line 108

def push_patient(external_id:, **input_values)
  mutate(Graphql::Mutations::CreateOrUpdatePatientMutation,
         Inputs::PatientInput.new(input_values.merge(external_id: external_id)),
         Data::Patient, 'createOrUpdatePatient')
end

#push_practitioner(external_id:, **input_values) ⇒ PushResult<Data::Practitioner>

Create or update an practitioner. You must specify an external identifier, all other parameters are optional, but you may receive errors if you attempt to specify too few parameters for an practitioner that does not exist.

Parameters:

  • external_id (String)

    the external identifier for this practitioner

  • input_values (Hash)

    a customizable set of options

Options Hash (**input_values):

Returns:

Since:

  • 0.1.0


231
232
233
234
235
# File 'lib/mirah/client.rb', line 231

def push_practitioner(external_id:, **input_values)
  mutate(Graphql::Mutations::CreateOrUpdatePractitionerMutation,
         Inputs::PractitionerInput.new(input_values.merge(external_id: external_id)),
         Data::Practitioner, 'createOrUpdatePractitioner')
end

#query_appointments(external_id: nil, status: nil) ⇒ Collection<Data::Appointment>

Returns a collection of pageable appointments.

Parameters:

Returns:

Since:

  • 0.1.0


271
272
273
274
275
276
277
278
279
# File 'lib/mirah/client.rb', line 271

def query_appointments(external_id: nil, status: nil)
  query_connection(
    Graphql::Queries::AppointmentQuery,
    Filters::AppointmentFilters.new(external_id: external_id, status: status),
    Filters::Paging.default,
    Data::Appointment,
    'appointments'
  )
end

#query_organizations(external_id: nil, search: nil) ⇒ Collection<Data::Organization>

Returns a collection of pageable organizations.

Parameters:

Returns:

Since:

  • 0.1.0


148
149
150
151
152
153
154
155
156
# File 'lib/mirah/client.rb', line 148

def query_organizations(external_id: nil, search: nil)
  query_connection(
    Graphql::Queries::OrganizationQuery,
    Filters::OrganizationFilters.new(external_id: external_id, search: search),
    Filters::Paging.default,
    Data::Organization,
    'organizations'
  )
end

#query_patients(external_id: nil, search: nil) ⇒ Collection<Data::Patient>

Query for patients. You may specify a set of parameters as defined in Filters::PatientFilters. Results are returned in a paginated format. See Mirah::Collection for how to page results.

Parameters:

Returns:

Since:

  • 0.1.0


85
86
87
88
89
90
91
92
93
# File 'lib/mirah/client.rb', line 85

def query_patients(external_id: nil, search: nil)
  query_connection(
    Graphql::Queries::PatientQuery,
    Filters::PatientFilters.new(external_id: external_id, search: search),
    Filters::Paging.default,
    Data::Patient,
    'patients'
  )
end

#query_practitioners(external_id: nil, search: nil) ⇒ Collection<Data::Practitioner>

Query for practitioners. You may specify a set of parameters as defined in Filters::PractitionerFilters. Results are returned in a paginated format. See Mirah::Collection for how to page results.

Parameters:

Returns:

Since:

  • 0.1.0


206
207
208
209
210
211
212
213
214
# File 'lib/mirah/client.rb', line 206

def query_practitioners(external_id: nil, search: nil)
  query_connection(
    Graphql::Queries::PractitionerQuery,
    Filters::PractitionerFilters.new(external_id: external_id, search: search),
    Filters::Paging.default,
    Data::Practitioner,
    'practitioners'
  )
end