-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send diabetes treatment payload to CPHC (#5341)
**Story card:** [sc-11383](https://app.shortcut.com/simpledotorg/story/11383/data-migration-for-pune-and-pimpri-chinchwad) ## Because It was identified earlier that since we have not sent diabetes treatment payloads to CPHC, the patients have not been marked as under treatment in their system. We are fixing this with this current migration. ## This addresses Adds a request to the diabetes treatment api of CPHC
- Loading branch information
1 parent
ab74f49
commit a57beef
Showing
2 changed files
with
131 additions
and
7 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
app/services/one_off/cphc_enrollment/diabetes_treatment_payload.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,65 @@ | ||
class OneOff::CphcEnrollment::DiabetesTreatmentPayload | ||
attr_reader :blood_sugar, :patient, :prescription_drugs, :appointment, :encounter_id | ||
|
||
def initialize(blood_sugar, prescription_drugs, appointment, encounter_id) | ||
@blood_sugar = blood_sugar | ||
@patient = blood_sugar.patient | ||
@prescription_drugs = prescription_drugs | ||
@appointment = appointment | ||
@encounter_id = encounter_id | ||
end | ||
|
||
def payload | ||
medical_history = patient.medical_history | ||
treatment_date = blood_sugar.recorded_at.strftime("%d-%m-%Y") | ||
blood_sugar_payload = OneOff::CphcEnrollment::BloodSugarPayload.new(blood_sugar) | ||
|
||
payload = { | ||
encounterId: encounter_id, | ||
treat: { | ||
reviewIn: { | ||
isProtocolOverriden: false, | ||
facility: "DH", | ||
treatDate: treatment_date, | ||
reviewDate: treatment_date, | ||
conDn: true, | ||
remarks: nil, | ||
removeCurrMedication: true, | ||
treatDateWithTimeStamp: blood_sugar.recorded_at.to_i, | ||
diabetesDiagnosisModel: { | ||
date: treatment_date, | ||
selectedDiagnosis: medical_history.diabetes ? "CONFIRMED" : "NAD" | ||
} | ||
} | ||
} | ||
} | ||
|
||
payload[:treat][:reviewIn].merge!(blood_sugar_payload.blood_sugar_type_payload) | ||
|
||
if appointment.present? | ||
payload[:treat][:docfolUp] = { | ||
followUpDueDate: appointment.scheduled_date.strftime("%d-%m-%Y"), | ||
followUpDuration: "#{appointment.follow_up_days};0;0", | ||
followUpReason: "Clinical Examination" | ||
} | ||
end | ||
|
||
if prescription_drugs.present? | ||
payload[:treat][:reviewIn][:selMeds] = prescription_drugs.map do |prescription_drug| | ||
{ | ||
dose: nil, | ||
freq: "Once a day", | ||
name: prescription_drug.name, | ||
quan: appointment.present? ? appointment.follow_up_days : 30, | ||
dur: appointment.present? ? appointment.follow_up_days : 30 | ||
} | ||
end | ||
end | ||
|
||
payload | ||
end | ||
|
||
def headers | ||
{"Host" => ENV.fetch("CPHC_DIABETES_HOST")} | ||
end | ||
end |
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