@@ -270,36 +270,102 @@ def problem_list(self) -> List[Condition]:
270270 return self .get_resources ("Condition" )
271271
272272 @problem_list .setter
273- def problem_list (self , conditions : List [Condition ]) -> None :
274- # TODO: should make this behaviour more explicit whether it's adding or replacing
275- """Set problem list in the bundle."""
276- self .add_resources (conditions , "Condition" )
273+ def problem_list (self , value : Union [List [Condition ], Dict [str , Any ]]) -> None :
274+ """
275+ Set problem list in the bundle.
276+
277+ By default, this adds the provided conditions to any existing conditions in the bundle.
278+ To replace existing conditions instead, pass a dictionary with 'resources' and 'replace' keys.
279+
280+ Args:
281+ value: Either a list of Condition resources (adds by default) or a dict with:
282+ - 'resources': List of Condition resources
283+ - 'replace': bool, whether to replace existing resources (default: False)
284+
285+ Examples:
286+ >>> # Add to existing conditions (default behavior)
287+ >>> fhir.problem_list = [condition1, condition2]
288+ >>> # Replace existing conditions
289+ >>> fhir.problem_list = {'resources': [condition1], 'replace': True}
290+ """
291+ if isinstance (value , dict ):
292+ resources = value .get ("resources" , [])
293+ replace = value .get ("replace" , False )
294+ else :
295+ resources = value
296+ replace = False
297+
298+ self .add_resources (resources , "Condition" , replace = replace )
277299
278300 @property
279301 def medication_list (self ) -> List [MedicationStatement ]:
280302 """Get medication list from the bundle."""
281303 return self .get_resources ("MedicationStatement" )
282304
283305 @medication_list .setter
284- def medication_list (self , medications : List [MedicationStatement ]) -> None :
285- """Set medication list in the bundle.
286- Medication statements are stored as MedicationStatement resources in the bundle.
287- See: https://www.hl7.org/fhir/medicationstatement.html
306+ def medication_list (
307+ self , value : Union [List [MedicationStatement ], Dict [str , Any ]]
308+ ) -> None :
288309 """
289- self .add_resources (medications , "MedicationStatement" )
310+ Set medication list in the bundle.
311+
312+ By default, this adds the provided medications to any existing medications in the bundle.
313+ To replace existing medications instead, pass a dictionary with 'resources' and 'replace' keys.
314+
315+ Args:
316+ value: Either a list of MedicationStatement resources (adds by default) or a dict with:
317+ - 'resources': List of MedicationStatement resources
318+ - 'replace': bool, whether to replace existing resources (default: False)
319+
320+ Examples:
321+ >>> # Add to existing medications (default behavior)
322+ >>> fhir.medication_list = [medication1, medication2]
323+ >>> # Replace existing medications
324+ >>> fhir.medication_list = {'resources': [medication1], 'replace': True}
325+ """
326+ if isinstance (value , dict ):
327+ resources = value .get ("resources" , [])
328+ replace = value .get ("replace" , False )
329+ else :
330+ resources = value
331+ replace = False
332+
333+ self .add_resources (resources , "MedicationStatement" , replace = replace )
290334
291335 @property
292336 def allergy_list (self ) -> List [AllergyIntolerance ]:
293337 """Get allergy list from the bundle."""
294338 return self .get_resources ("AllergyIntolerance" )
295339
296340 @allergy_list .setter
297- def allergy_list (self , allergies : List [AllergyIntolerance ]) -> None :
298- """Set allergy list in the bundle.
299- Allergy intolerances are stored as AllergyIntolerance resources in the bundle.
300- See: https://www.hl7.org/fhir/allergyintolerance.html
341+ def allergy_list (
342+ self , value : Union [List [AllergyIntolerance ], Dict [str , Any ]]
343+ ) -> None :
301344 """
302- self .add_resources (allergies , "AllergyIntolerance" )
345+ Set allergy list in the bundle.
346+
347+ By default, this adds the provided allergies to any existing allergies in the bundle.
348+ To replace existing allergies instead, pass a dictionary with 'resources' and 'replace' keys.
349+
350+ Args:
351+ value: Either a list of AllergyIntolerance resources (adds by default) or a dict with:
352+ - 'resources': List of AllergyIntolerance resources
353+ - 'replace': bool, whether to replace existing resources (default: False)
354+
355+ Examples:
356+ >>> # Add to existing allergies (default behavior)
357+ >>> fhir.allergy_list = [allergy1, allergy2]
358+ >>> # Replace existing allergies
359+ >>> fhir.allergy_list = {'resources': [allergy1], 'replace': True}
360+ """
361+ if isinstance (value , dict ):
362+ resources = value .get ("resources" , [])
363+ replace = value .get ("replace" , False )
364+ else :
365+ resources = value
366+ replace = False
367+
368+ self .add_resources (resources , "AllergyIntolerance" , replace = replace )
303369
304370 def get_prefetch_resources (self , key : str ) -> List [Any ]:
305371 """Get resources of a specific type from the prefetch bundle."""
0 commit comments