-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e35fae4
commit 94c2411
Showing
8 changed files
with
785 additions
and
0 deletions.
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
app/services/one_off/opensrp_export/appointment_exporter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
require "fhir_models" | ||
|
||
module OneOff | ||
module OpenSRP | ||
class AppointmentExporter | ||
attr_reader :appointment | ||
|
||
def initialize(appointment) | ||
@appointment = appointment | ||
end | ||
|
||
def export | ||
FHIR::Appointment.new( | ||
meta: meta, | ||
status: appointment_status_code, | ||
start: appointment.scheduled_date.beginning_of_day.iso8601, | ||
created: appointment.device_created_at.iso8601, | ||
serviceType: FHIR::CodeableConcept.new( | ||
coding: [ | ||
FHIR::Coding.new( | ||
system: "http://terminology.hl7.org/CodeSystem/service-type", | ||
code: "335" | ||
) | ||
] | ||
), | ||
appointmentType: FHIR::CodeableConcept.new( | ||
coding: [ | ||
FHIR::Coding.new( | ||
system: "http://terminology.hl7.org/CodeSystem/service-type", | ||
code: "335" | ||
) | ||
] | ||
), | ||
participant: [ | ||
FHIR::Appointment::Participant.new( | ||
actor: FHIR::Reference.new(reference: "Patient/#{appointment.patient_id}"), | ||
status: participant_status | ||
) | ||
], | ||
id: appointment.id, | ||
identifier: [ | ||
FHIR::Identifier.new( | ||
value: appointment.id | ||
) | ||
] | ||
) | ||
end | ||
|
||
def export_encounter | ||
FHIR::Encounter.new( | ||
meta: meta, | ||
status: encounter_status_code, | ||
id: Digest::UUID.uuid_v5(Digest::UUID::DNS_NAMESPACE, appointment.id), | ||
identifier: [ | ||
FHIR::Identifier.new( | ||
value: Digest::UUID.uuid_v5(Digest::UUID::DNS_NAMESPACE, appointment.id) | ||
) | ||
], | ||
class: FHIR::Coding.new( | ||
system: "http://terminology.hl7.org/CodeSystem/v3-ActCode", | ||
code: "AMB" | ||
), | ||
type: [ | ||
FHIR::CodeableConcept.new( | ||
coding: FHIR::Coding.new( | ||
system: "TODO", | ||
code: "TODO" | ||
) | ||
) | ||
], | ||
serviceType: FHIR::CodeableConcept.new( | ||
coding: [ | ||
FHIR::Coding.new( | ||
system: "http://terminology.hl7.org/CodeSystem/service-type", | ||
code: "335" | ||
) | ||
] | ||
), | ||
subject: FHIR::Reference.new(reference: "Patient/#{appointment.patient_id}"), | ||
appointment: FHIR::Reference.new(reference: "Appointment/#{appointment.id}"), | ||
period: FHIR::Period.new(start: appointment.scheduled_date.iso8601), # TODO: we don't store end period | ||
reasonCode: [ | ||
FHIR::CodeableConcept.new( | ||
coding: [ | ||
FHIR::Coding.new( | ||
system: "http://snomed.info/sct", | ||
code: "TODO" # TODO | ||
) | ||
] | ||
) | ||
], | ||
diagnosis: nil, | ||
location: nil, | ||
serviceProvider: FHIR::Reference.new(reference: "Organization/#{appointment.facility_id}"), | ||
partOf: nil | ||
) | ||
end | ||
|
||
def meta | ||
FHIR::Meta.new( | ||
lastUpdated: appointment.device_updated_at.iso8601, | ||
tag: [ | ||
FHIR::Coding.new( | ||
system: "https://smartregister.org/app-version", | ||
code: "Not defined", | ||
display: "Application Version" | ||
), | ||
FHIR::Coding.new( | ||
system: "https://smartregister.org/location-tag-id", | ||
code: appointment.facility.region.id, | ||
display: "Practitioner Location" | ||
), | ||
FHIR::Coding.new( | ||
system: "https://smartregister.org/organisation-tag-id", | ||
code: "TODO", # TODO | ||
display: "Practitioner Organization" | ||
), | ||
FHIR::Coding.new( | ||
system: "https://smartregister.org/practitioner-tag-id", | ||
code: "TODO", # TODO | ||
display: "Practitioner" | ||
), | ||
FHIR::Coding.new( | ||
system: "https://smartregister.org/care-team-tag-id", | ||
code: "TODO", # TODO | ||
display: "Practitioner CareTeam" | ||
) | ||
] | ||
) | ||
end | ||
|
||
def participant_status | ||
case appointment.agreed_to_visit | ||
when true then "accepted" | ||
when false then "declined" | ||
else "needs-action" | ||
end | ||
end | ||
|
||
def appointment_status_code | ||
case appointment.status | ||
when "scheduled" then "pending" | ||
when "visited" then "fulfilled" | ||
when "cancelled" then "cancelled" | ||
else raise "Invalid appointment status: #{appointment.status}" | ||
end | ||
end | ||
|
||
def encounter_status_code | ||
case appointment.status | ||
when "scheduled" then "planned" | ||
when "visited" then "finished" | ||
when "cancelled" then "cancelled" | ||
else raise "Invalid appointment status: #{appointment.status}" | ||
end | ||
end | ||
end | ||
end | ||
end |
127 changes: 127 additions & 0 deletions
127
app/services/one_off/opensrp_export/blood_pressure_exporter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
require "fhir_models" | ||
|
||
module OneOff | ||
module OpenSRP | ||
class BloodPressureExporter | ||
attr_reader :blood_pressure | ||
|
||
def initialize(blood_pressure) | ||
@blood_pressure = blood_pressure | ||
end | ||
|
||
def export | ||
FHIR::Observation.new( | ||
identifier: [ | ||
FHIR::Identifier.new( | ||
value: blood_pressure.id | ||
) | ||
], | ||
code: FHIR::CodeableConcept.new( | ||
coding: FHIR::Coding.new( | ||
system: "TODO", | ||
code: "TODO" | ||
) | ||
), | ||
component: [ | ||
observation_component("TODO", blood_pressure.systolic), | ||
observation_component("TODO", blood_pressure.diastolic) | ||
], | ||
subject: FHIR::Reference.new( | ||
identifier: FHIR::Identifier.new( | ||
value: blood_pressure.patient_id | ||
) | ||
), | ||
meta: FHIR::Meta.new( | ||
lastUpdated: blood_pressure.device_updated_at.iso8601, | ||
createdAt: blood_pressure.recorded_at.iso8601 | ||
), | ||
performer: FHIR::Reference.new( | ||
identifier: FHIR::Identifier.new( | ||
value: blood_pressure.facility_id # TODO: should this be a user? | ||
) | ||
), | ||
status: "final", | ||
category: [ | ||
FHIR::CodeableConcept.new( | ||
coding: [ | ||
FHIR::Coding.new( | ||
system: "http://terminology.hl7.org/CodeSystem/observation-category", | ||
code: "vital-signs", | ||
display: "Vital Signs" | ||
) | ||
] | ||
) | ||
] | ||
) | ||
end | ||
|
||
def observation_component(code, value) | ||
FHIR::Observation::Component.new( | ||
code: FHIR::CodeableConcept.new( | ||
coding: [ | ||
FHIR::Coding.new( | ||
system: "TODO", | ||
code: code | ||
) | ||
] | ||
), | ||
valueQuantity: FHIR::Quantity.new( | ||
value: value, | ||
unit: "mmHg", | ||
system: "http://unitsofmeasure.org", | ||
code: "mm[Hg]" | ||
) | ||
) | ||
end | ||
|
||
def export_encounter | ||
FHIR::Encounter.new( | ||
meta: meta, | ||
status: encounter_status_code, | ||
id: Digest::UUID.uuid_v5(Digest::UUID::DNS_NAMESPACE, blood_pressure.id), | ||
identifier: [ | ||
FHIR::Identifier.new( | ||
value: Digest::UUID.uuid_v5(Digest::UUID::DNS_NAMESPACE, blood_pressure.id) | ||
) | ||
], | ||
class: FHIR::Coding.new( | ||
system: "http://terminology.hl7.org/CodeSystem/v3-ActCode", | ||
code: "AMB" | ||
), | ||
type: [ | ||
FHIR::CodeableConcept.new( | ||
coding: FHIR::Coding.new( | ||
system: "TODO", | ||
code: "TODO" | ||
) | ||
) | ||
], | ||
serviceType: FHIR::CodeableConcept.new( | ||
coding: [ | ||
FHIR::Coding.new( | ||
system: "http://terminology.hl7.org/CodeSystem/service-type", | ||
code: "335" | ||
) | ||
] | ||
), | ||
subject: FHIR::Reference.new(reference: "Patient/#{blood_pressure.patient_id}"), | ||
period: FHIR::Period.new(start: blood_pressure.recorded_at.iso8601), # TODO: we don't store end period | ||
reasonCode: [ | ||
FHIR::CodeableConcept.new( | ||
coding: [ | ||
FHIR::Coding.new( | ||
system: "http://snomed.info/sct", | ||
code: "TODO" # TODO | ||
) | ||
] | ||
) | ||
], | ||
diagnosis: nil, | ||
location: nil, | ||
serviceProvider: FHIR::Reference.new(reference: "Organization/#{blood_pressure.facility_id}"), | ||
partOf: nil | ||
) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.