@@ -135,20 +135,26 @@ async def test_client_save_existing(self):
135
135
136
136
@pytest .mark .asyncio ()
137
137
async def test_client_save_partial_update (self ):
138
- patient = await self .create_patient_model ()
138
+ patient = await self .create_patient_model (
139
+ managingOrganization = Reference (reference = "urn:organization" )
140
+ )
139
141
140
142
patient .identifier = [
141
143
* patient .identifier ,
142
144
Identifier (system = "url" , value = "value" ),
143
145
]
144
146
patient .name [0 ].text = "New patient"
147
+ patient .managingOrganization = None
145
148
146
- updated_patient = await self .client .save (patient , fields = ["identifier" ])
149
+ updated_patient = await self .client .save (
150
+ patient , fields = ["identifier" , "managingOrganization" ]
151
+ )
147
152
148
153
assert isinstance (updated_patient , Patient )
149
154
assert updated_patient .id == patient .id
150
155
assert len (updated_patient .identifier ) == 2 # noqa: PLR2004
151
156
assert updated_patient .name [0 ].text == "My patient"
157
+ assert updated_patient .managingOrganization is None
152
158
153
159
@pytest .mark .asyncio ()
154
160
async def test_client_save_partial_update_fails_without_id (self ):
@@ -408,7 +414,7 @@ async def test_conditional_operations__fail_on_multiple_matches(self):
408
414
)
409
415
410
416
@pytest .mark .asyncio ()
411
- async def test_update_with_params__no_match (self ):
417
+ async def test_conditional_update__no_match (self ):
412
418
patient = await self .create_resource ("Patient" , id = "patient" , active = True )
413
419
414
420
patient_to_update = self .client .resource (
@@ -427,7 +433,7 @@ async def test_update_with_params__no_match(self):
427
433
assert created is True
428
434
429
435
@pytest .mark .asyncio ()
430
- async def test_update_with_params__one_match (self ):
436
+ async def test_conditional_update__one_match (self ):
431
437
patient = await self .create_resource ("Patient" , id = "patient" , active = True )
432
438
433
439
patient_to_update = self .client .resource (
@@ -450,7 +456,7 @@ async def test_update_with_params__one_match(self):
450
456
assert patient .get ("active" ) is None
451
457
452
458
@pytest .mark .asyncio ()
453
- async def test_patch_with_params__no_match (self ):
459
+ async def test_conditional_patch__no_match (self ):
454
460
patient_to_patch = self .client .resource (
455
461
"Patient" ,
456
462
identifier = [{"system" : "http://example.com/env" , "value" : "other" }, self .identifier [0 ]],
@@ -462,7 +468,7 @@ async def test_patch_with_params__no_match(self):
462
468
)
463
469
464
470
@pytest .mark .asyncio ()
465
- async def test_patch_with_params__one_match (self ):
471
+ async def test_conditional_patch__one_match (self ):
466
472
patient = await self .create_resource (
467
473
"Patient" ,
468
474
id = "patient" ,
@@ -494,7 +500,7 @@ async def test_patch_with_params__one_match(self):
494
500
assert patient .get ("managingOrganization" ) is None
495
501
496
502
@pytest .mark .asyncio ()
497
- async def test_patch_with_params__one_match_deprecated (self ):
503
+ async def test_conditional_patch__one_match_deprecated (self ):
498
504
patient = await self .create_resource ("Patient" , id = "patient" , active = True )
499
505
500
506
patient_to_patch = self .client .resource (
@@ -569,7 +575,7 @@ async def test_delete_without_id_failed(self):
569
575
await patient .delete ()
570
576
571
577
@pytest .mark .asyncio ()
572
- async def test_delete_with_params__no_match (self ):
578
+ async def test_conditional_delete__no_match (self ):
573
579
await self .create_resource ("Patient" , id = "patient" )
574
580
575
581
_ , status_code = await self .client .resources ("Patient" ).search (identifier = "other" ).delete ()
@@ -578,7 +584,7 @@ async def test_delete_with_params__no_match(self):
578
584
assert status_code == 204 # noqa: PLR2004
579
585
580
586
@pytest .mark .asyncio ()
581
- async def test_delete_with_params__one_match (self ):
587
+ async def test_conditional_delete__one_match (self ):
582
588
patient = self .client .resource (
583
589
"Patient" ,
584
590
id = "patient" ,
@@ -595,7 +601,7 @@ async def test_delete_with_params__one_match(self):
595
601
assert status_code == 200 # noqa: PLR2004
596
602
597
603
@pytest .mark .asyncio ()
598
- async def test_delete_with_params__multiple_matches (self ):
604
+ async def test_conditional_delete__multiple_matches (self ):
599
605
await self .create_resource ("Patient" , id = "patient-1" )
600
606
await self .create_resource ("Patient" , id = "patient-2" )
601
607
@@ -859,18 +865,42 @@ async def test_save_fields(self):
859
865
active = False ,
860
866
birthDate = "1998-01-01" ,
861
867
name = [{"text" : "Abc" }],
868
+ managingOrganization = {"reference" : "urn:organization" },
862
869
)
863
870
patient ["gender" ] = "male"
864
871
patient ["birthDate" ] = "1998-02-02"
865
872
patient ["active" ] = True
866
873
patient ["name" ] = [{"text" : "Bcd" }]
867
- await patient .save (fields = ["gender" , "birthDate" ])
874
+ patient ["managingOrganization" ] = None
875
+ await patient .save (fields = ["gender" , "birthDate" , "managingOrganization" ])
868
876
869
877
patient_refreshed = await patient .to_reference ().to_resource ()
870
878
assert patient_refreshed ["gender" ] == patient ["gender" ]
871
879
assert patient_refreshed ["birthDate" ] == patient ["birthDate" ]
872
880
assert patient_refreshed ["active" ] is False
873
881
assert patient_refreshed ["name" ] == [{"text" : "Abc" }]
882
+ assert patient_refreshed .get ("managingOrganization" ) is None
883
+
884
+ @pytest .mark .asyncio ()
885
+ async def test_update_patch_without_id (self ):
886
+ patient = self .client .resource (
887
+ "Patient" , identifier = self .identifier , name = [{"text" : "J London" }]
888
+ )
889
+ new_name = [
890
+ {
891
+ "text" : "Jack London" ,
892
+ "family" : "London" ,
893
+ "given" : ["Jack" ],
894
+ }
895
+ ]
896
+ with pytest .raises (TypeError ):
897
+ await patient .update ()
898
+ with pytest .raises (TypeError ):
899
+ await patient .patch (active = True , name = new_name )
900
+ patient ["name" ] = new_name
901
+ with pytest .raises (TypeError ):
902
+ await patient .save (fields = ["name" ])
903
+ await patient .save ()
874
904
875
905
@pytest .mark .asyncio ()
876
906
async def test_update (self ):
@@ -918,27 +948,6 @@ async def test_patch(self):
918
948
assert patient_instance_1_refreshed ["name" ] == new_name
919
949
assert patient_instance_1_refreshed .get ("managingOrganization" ) is None
920
950
921
- @pytest .mark .asyncio ()
922
- async def test_update_without_id (self ):
923
- patient = self .client .resource (
924
- "Patient" , identifier = self .identifier , name = [{"text" : "J London" }]
925
- )
926
- new_name = [
927
- {
928
- "text" : "Jack London" ,
929
- "family" : "London" ,
930
- "given" : ["Jack" ],
931
- }
932
- ]
933
- with pytest .raises (TypeError ):
934
- await patient .update ()
935
- with pytest .raises (TypeError ):
936
- await patient .patch (active = True , name = new_name )
937
- patient ["name" ] = new_name
938
- with pytest .raises (TypeError ):
939
- await patient .save (fields = ["name" ])
940
- await patient .save ()
941
-
942
951
@pytest .mark .asyncio ()
943
952
async def test_refresh (self ):
944
953
patient_id = "refresh-patient-id"
0 commit comments