66import botocore .exceptions
77import simplejson as json
88from boto3 .dynamodb .conditions import Attr , Key
9+ from fhir .resources .R4B .immunization import Immunization
910
1011from models .errors import (
1112 IdentifierDuplicationError ,
@@ -195,7 +196,7 @@ def setUp(self):
195196
196197 def test_create_immunization (self ):
197198 """it should create Immunization, and return created object unique ID"""
198- imms = create_covid_19_immunization_dict (imms_id = self ._MOCK_CREATED_UUID )
199+ imms = Immunization . parse_obj ( create_covid_19_immunization_dict (imms_id = self ._MOCK_CREATED_UUID ) )
199200
200201 self .table .put_item = MagicMock (return_value = {"ResponseMetadata" : {"HTTPStatusCode" : 200 }})
201202 self .mock_redis_client .hget .return_value = "COVID19"
@@ -208,7 +209,7 @@ def test_create_immunization(self):
208209 "PK" : f"Immunization#{ self ._MOCK_CREATED_UUID } " ,
209210 "PatientPK" : "Patient#9990548609" ,
210211 "PatientSK" : f"COVID19#{ self ._MOCK_CREATED_UUID } " ,
211- "Resource" : json . dumps ( imms ),
212+ "Resource" : imms . json ( ),
212213 "IdentifierPK" : "https://supplierABC/identifiers/vacc#ACME-vacc123456" ,
213214 "Operation" : "CREATE" ,
214215 "Version" : 1 ,
@@ -225,7 +226,9 @@ def test_create_should_catch_dynamo_error(self):
225226
226227 with self .assertRaises (UnhandledResponseError ) as e :
227228 # When
228- self .repository .create_immunization (create_covid_19_immunization_dict ("an-id" ), "Test" )
229+ self .repository .create_immunization (
230+ Immunization .parse_obj (create_covid_19_immunization_dict ("an-id" )), "Test"
231+ )
229232
230233 # Then
231234 self .assertDictEqual (e .exception .response , response )
@@ -251,7 +254,7 @@ def test_create_patient_gsi(self):
251254 self .table .query = MagicMock (return_value = {})
252255
253256 # When
254- _ = self .repository .create_immunization (imms , "Test" )
257+ _ = self .repository .create_immunization (Immunization . parse_obj ( imms ) , "Test" )
255258
256259 # Then
257260 item = self .table .put_item .call_args .kwargs ["Item" ]
@@ -268,7 +271,7 @@ def test_create_patient_with_vaccine_type(self):
268271 self .table .put_item = MagicMock (return_value = {"ResponseMetadata" : {"HTTPStatusCode" : 200 }})
269272
270273 # When
271- _ = self .repository .create_immunization (imms , "Test" )
274+ _ = self .repository .create_immunization (Immunization . parse_obj ( imms ) , "Test" )
272275
273276 # Then
274277 item = self .table .put_item .call_args .kwargs ["Item" ]
@@ -584,12 +587,12 @@ def setUp(self):
584587 def test_decimal_on_create (self ):
585588 """it should create Immunization, and preserve decimal value"""
586589 imms = create_covid_19_immunization_dict (imms_id = "an-id" )
587- imms ["doseQuantity" ] = 0.7477
590+ imms ["doseQuantity" ][ "value" ] = 0.7477
588591
589592 self .table .put_item = MagicMock (return_value = {"ResponseMetadata" : {"HTTPStatusCode" : 200 }})
590593 self .table .query = MagicMock (return_value = {})
591594
592- res_imms = self .repository .create_immunization (imms , "Test" )
595+ res_imms = self .repository .create_immunization (Immunization . parse_obj ( imms ) , "Test" )
593596
594597 self .assertEqual (res_imms , "an-id" )
595598
@@ -599,7 +602,7 @@ def test_decimal_on_create(self):
599602 "PK" : ANY ,
600603 "PatientPK" : ANY ,
601604 "PatientSK" : ANY ,
602- "Resource" : json . dumps (imms , use_decimal = True ),
605+ "Resource" : Immunization . parse_obj (imms ). json ( use_decimal = True ),
603606 "IdentifierPK" : ANY ,
604607 "Operation" : "CREATE" ,
605608 "Version" : 1 ,
@@ -612,7 +615,7 @@ def test_decimal_on_create(self):
612615
613616 resource_from_item = json .loads (item_passed_to_put_item ["Resource" ])
614617 self .assertEqual (
615- resource_from_item ["doseQuantity" ],
618+ resource_from_item ["doseQuantity" ][ "value" ] ,
616619 0.7477 ,
617620 )
618621
0 commit comments