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



249
250
251
# File 'lib/mirah/client.rb', line 249

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



259
260
261
262
263
264
# File 'lib/mirah/client.rb', line 259

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

#find_diagnostic_code(id) ⇒ Data::DiagnosticCode?

Find an diagnostic code 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_diagnostic_code_by_external_id

Parameters:

  • id (String)

    Mirah UUID for the diagnostic code

Returns:

Since:

  • 0.4.0



316
317
318
# File 'lib/mirah/client.rb', line 316

def find_diagnostic_code(id)
  query_record(Graphql::Queries::DiagnosticCodeIdQuery, id, Data::DiagnosticCode, 'diagnosticCode')
end

#find_diagnostic_code_by_external_id(external_id) ⇒ Data::DiagnosticCode?

Find a diagnostic code by your external id. This is a convenience method. If you wish to query a list of codes by external id, please use #query_diagnostic_codes.

Parameters:

  • external_id (String)

    The identifier of the system of record

Returns:

Since:

  • 0.4.0



326
327
328
329
330
331
# File 'lib/mirah/client.rb', line 326

def find_diagnostic_code_by_external_id(external_id)
  query_record_by_external_id(Graphql::Queries::DiagnosticCodeExternalIdQuery,
                              external_id,
                              Data::DiagnosticCode,
                              'diagnosticCodeExternal')
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



126
127
128
# File 'lib/mirah/client.rb', line 126

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



136
137
138
139
140
141
# File 'lib/mirah/client.rb', line 136

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_patient_condition(id) ⇒ Data::PatientCondition?

Find an condition 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_condition_by_external_id

Parameters:

  • id (String)

    Mirah UUID for the condition

Returns:

Since:

  • 0.4.0



375
376
377
# File 'lib/mirah/client.rb', line 375

def find_patient_condition(id)
  query_record(Graphql::Queries::PatientConditionIdQuery, id, Data::PatientCondition, 'patientCondition')
end

#find_patient_condition_by_external_id(external_id) ⇒ Data::PatientCondition?

Find a condition by your external id. This is a convenience method. If you wish to query a list of codes by external id, please use #query_patient_conditions.

Parameters:

  • external_id (String)

    The identifier of the system of record

Returns:

Since:

  • 0.4.0



385
386
387
388
389
390
# File 'lib/mirah/client.rb', line 385

def find_patient_condition_by_external_id(external_id)
  query_record_by_external_id(Graphql::Queries::PatientConditionExternalIdQuery,
                              external_id,
                              Data::PatientCondition,
                              'patientConditionExternal')
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



184
185
186
# File 'lib/mirah/client.rb', line 184

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



194
195
196
197
198
199
# File 'lib/mirah/client.rb', line 194

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



299
300
301
302
303
# File 'lib/mirah/client.rb', line 299

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_diagnostic_code(external_id:, **input_values) ⇒ PushResult<Data::DiagnosticCode>

Create or update a diagnosis code. 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 code

  • input_values (Hash)

    a customizable set of options

Options Hash (**input_values):

Returns:

Since:

  • 0.1.0



358
359
360
361
362
# File 'lib/mirah/client.rb', line 358

def push_diagnostic_code(external_id:, **input_values)
  mutate(Graphql::Mutations::CreateOrUpdateDiagnosticCodeMutation,
         Inputs::DiagnosticCodeInput.new(input_values.merge(external_id: external_id)),
         Data::DiagnosticCode, 'createOrUpdateDiagnosticCode')
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



168
169
170
171
172
# File 'lib/mirah/client.rb', line 168

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



110
111
112
113
114
# File 'lib/mirah/client.rb', line 110

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_patient_condition(external_id:, **input_values) ⇒ PushResult<Data::PatientCondition>

Create or update a condition. 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 code

  • input_values (Hash)

    a customizable set of options

Options Hash (**input_values):

  • :name (String, nil)

    see Data::PatientCondition#name

  • :code (String, nil)

    see Data::PatientCondition#code

Returns:

Since:

  • 0.1.0



416
417
418
419
420
# File 'lib/mirah/client.rb', line 416

def push_patient_condition(external_id:, **input_values)
  mutate(Graphql::Mutations::CreateOrUpdatePatientConditionMutation,
         Inputs::PatientConditionInput.new(input_values.merge(external_id: external_id)),
         Data::PatientCondition, 'createOrUpdatePatientCondition')
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



233
234
235
236
237
# File 'lib/mirah/client.rb', line 233

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



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

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_diagnostic_codes(external_id: nil, search: nil) ⇒ Collection<Data::Appointment>

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

Parameters:

Returns:

Since:

  • 0.4.0



340
341
342
343
344
345
346
347
348
# File 'lib/mirah/client.rb', line 340

def query_diagnostic_codes(external_id: nil, search: nil)
  query_connection(
    Graphql::Queries::DiagnosticCodeQuery,
    Filters::DiagnosticCodeFilters.new(external_id: external_id, search: search),
    Filters::Paging.default,
    Data::DiagnosticCode,
    'diagnosticCodes'
  )
end

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

Returns a collection of pageable organizations.

Parameters:

Returns:

Since:

  • 0.1.0



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

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_patient_conditions(external_id: nil) ⇒ Collection<Data::Appointment>

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

Parameters:

Returns:

Since:

  • 0.4.0



398
399
400
401
402
403
404
405
406
# File 'lib/mirah/client.rb', line 398

def query_patient_conditions(external_id: nil)
  query_connection(
    Graphql::Queries::PatientConditionQuery,
    Filters::PatientConditionFilters.new(external_id: external_id),
    Filters::Paging.default,
    Data::PatientCondition,
    'patientConditions'
  )
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



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

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