Skip to content

Commit 07e3057

Browse files
authored
Merge pull request #5825 from nhsuk/external-missing-practitioner-mav-3104
Handle external or missing practitioner user
2 parents 380c180 + 6d0292e commit 07e3057

2 files changed

Lines changed: 34 additions & 9 deletions

File tree

app/lib/fhir_mapper/vaccination_record.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def initialize(vaccination_record)
1818
def fhir_record
1919
immunisation = FHIR::Immunization.new(id: nhs_immunisations_api_id)
2020

21-
if performed_by_user.present?
22-
immunisation.contained << performed_by_user.fhir_practitioner(
23-
reference_id: "Practitioner1"
24-
)
21+
if performed_by.present?
22+
immunisation.contained << FHIRMapper::User.new(
23+
performed_by
24+
).fhir_practitioner(reference_id: "Practitioner1")
2525
end
2626

2727
immunisation.contained << patient.fhir_record(reference_id: "Patient1")
@@ -44,10 +44,12 @@ def fhir_record
4444
immunisation.site = fhir_site
4545
immunisation.route = fhir_route
4646
immunisation.doseQuantity = fhir_dose_quantity
47-
immunisation.performer = [
48-
fhir_user_performer(reference_id: "Practitioner1"),
49-
fhir_org_performer
50-
]
47+
if performed_by.present?
48+
immunisation.performer << fhir_user_performer(
49+
reference_id: "Practitioner1"
50+
)
51+
end
52+
immunisation.performer << fhir_org_performer
5153
immunisation.reasonCode = [fhir_reason_code]
5254
immunisation.protocolApplied = [fhir_protocol_applied]
5355

spec/lib/fhir_mapper/vaccination_record_spec.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,32 @@
6262
end
6363

6464
describe "contained performing practitioner" do
65-
subject { immunisation_fhir.contained.find { it.id == "Practitioner1" } }
65+
subject(:contained_practitioner) do
66+
immunisation_fhir.contained.find { it.id == "Practitioner1" }
67+
end
6668

6769
it { should eq user.fhir_practitioner(reference_id: "Practitioner1") }
70+
71+
context "when the performing professional is not a local user" do
72+
subject(:name) { contained_practitioner.name.first }
73+
74+
before do
75+
vaccination_record.update(
76+
performed_by_user: nil,
77+
performed_by_given_name: "John",
78+
performed_by_family_name: "Howie"
79+
)
80+
end
81+
82+
its(:given) { should eq ["John"] }
83+
its(:family) { should eq "Howie" }
84+
end
85+
86+
context "when the performing professional is missing" do
87+
before { vaccination_record.update(performed_by_user: nil) }
88+
89+
it { should be_nil }
90+
end
6891
end
6992

7093
describe "performing practitioner" do

0 commit comments

Comments
 (0)