public void DeleteFromWorklist(string accessionnumber)
{
var keyAttributes = _worklistManager.NewWorklistItem();
keyAttributes.SetAccessionNumber(accessionnumber);
var filteredWorklist = _worklistManager.Find(keyAttributes); //returns worklist with items that matched the attributes
if(filteredWorklist == null)
ShowError(new Exception("Record not found in PACS modality worklist"));
if (filteredWorklist.Count > 0)
{
WorklistItem item = filteredWorklist.item[0]; // we assume that items have unique accessionnumbers
object itemInstanceUID = null;
var ok = item.GetWorklistItemInstanceUID(ref itemInstanceUID); // returns error code "Object not found"
var instanceUID = item.WorklistItemInstanceUID;
_worklistManager.DeleteWorklistItem(itemInstanceUID.ToString());
CheckForErrorCode();
}
}