Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync patients without addresses #5525

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/transformers/api/v3/patient_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,23 @@ def from_nested_request(payload_attributes)
end

def to_nested_response(patient)
Api::V3::Transformer.to_response(patient)
response = Api::V3::Transformer.to_response(patient)
.except("address_id",
"registration_user_id",
"test_data",
"deleted_by_user_id")
.merge(
"address" => Api::V3::Transformer.to_response(patient.address),
"phone_numbers" => patient.phone_numbers.map do |phone_number|
Api::V3::PatientPhoneNumberTransformer.to_response(phone_number)
end,
"business_identifiers" => patient.business_identifiers.map do |business_identifier|
Api::V3::PatientBusinessIdentifierTransformer.to_response(business_identifier)
end
)
response.merge(
"address" => Api::V3::Transformer.to_response(patient.address),
) unless patient.address.nil?
response
end
end
end
4 changes: 4 additions & 0 deletions spec/factories/patients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
reminder_consent { Patient.reminder_consents[:granted] }
medical_history { build(:medical_history, :hypertension_yes, patient_id: id, user: registration_user) }

trait(:without_address) do
association :address, strategy: :null
end

trait(:with_dob) do
date_of_birth { rand(18..80).years.ago }
age { nil }
Expand Down
7 changes: 7 additions & 0 deletions spec/transformers/api/v3/patient_transformer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,12 @@
transformed_nested_patient = Api::V3::PatientTransformer.to_nested_response(patient)
expect(transformed_nested_patient["registration_facility_id"]).to eq(patient.registration_facility.id)
end

context "for patients without addresses" do
it "should be successful" do
patient_without_address = create(:patient, :without_address)
expect { Api::V3::PatientTransformer.to_nested_response(patient_without_address) }.not_to raise_error
end
end
end
end