Changing PatientID at the Study Level

I have a python script that changes a set of tags for an existing study. That isn’t needed that often, but there are cases when I would want to do that. e.g. Patient is a “John Doe” or is unable to be registered in the RIS / MWL before performing the study. In such cases, I’d like to edit a number of dicom tags for the study, updated from a MWL.

That all works, but the issue I am having is with modifying the PatientID. Kind of wondering also what “True” should be. “True”, “true”, True or true, or any of those. If so, what other options are there if I want to change the PatientID ?

The JSON below is an example body for the command in /studies/id/modify. That all works if I omit the PatientID, but I get a “HttpError” : “Internal Server Error”, “HttpStatus” : 500, “Message” error when I try to change the PatientID. I take it the Force option does not work for that ? I am using the latest Osimis Docker images / mainline.

{
“Force”: True,
“Replace”: {
“OperatorsName”: “1:SDS”,
“AccessionNumber”: “DEVACC00000069”,
“AdditionalPatientHistory”: “Daily QC”,
“AdmittingDiagnosesDescription”: “”,
“Allergies”: “”,
“ImageComments”: “ImageComments”,
“MedicalAlerts”: “”,
“Modality”: “MR”,
“Occupation”: “”,
“PatientAddress”: “^^^^^US”,
“PatientBirthDate”: “19571116”,
“PatientComments”: “”,
“PatientID”: “test”,
“PatientName”: “S^S^”,
“PatientSex”: “M”,
“PatientTelecomInformation”: “-^WPN^PH^”,
“PatientWeight”: “”,
“ReferringPhysicianIdentificationSequence”: [{
“InstitutionName”: “xx”,
“PersonIdentificationCodeSequence”: [{
“CodeMeaning”: “Local Code”,
“CodeValue”: “0003”,
“CodingSchemeDesignator”: “L”
}],
“PersonTelephoneNumbers”: “xx”
}],
“StudyDescription”: “MRI BRAIN / BRAIN STEM - WITHOUT CONTRAST”
}
}

The error message in the Orthanc log is:

E0619 19:40:01.267128 OrthancException.cpp:57] Bad request: When modifying a study, the parent PatientID cannot be manually modified
I0619 19:40:01.267908 JobsRegistry.cpp:475] Job has completed with failure: 34428617-8d5a-4d8d-b781-67d12d1be5f0

Seems to be related to the following in DicomModification.cpp

// Sanity checks at the study level
if (level_ == ResourceType_Study && isReplacedPatientId)
{
throw OrthancException(ErrorCode_BadRequest,
“When modifying a study, the parent PatientID cannot be manually modified”);
}

This is explained in the Orthanc Book in the following section:
https://book.orthanc-server.com/users/anonymization.html#modification-of-patients

To preserve the consistency of the DICOM model of the real world, modification of “PatientID” can only be done at the “patient” level. In your case, you were using “/studies/{…}/modify” instead of “/patients/{…}/modify”, which prevents the modification of the patient-related tag “PatientID”.

Also, if you want to bypass all the safety checks done by Orthanc, you could consider using “/instances/{id}/modify” to modify instance by instance, which returns the modified DICOM file without storing it back into Orthanc, without trying to preserve the patient/study/series/instance hierarchy.

Regarding your question about Booleans, the body of most POST/PUT requests to the REST API of Orthanc must be formatted in the JSON format. Here is what the JSON standard says about Booleans:
https://en.wikipedia.org/wiki/JSON#Data_types

So, the correct syntax is to use the “true” or “false” value (without the surrounding quotes). Also, have a look at the OpenAPI documentation of Orthanc, which describes the expected body for each route:
https://api.orthanc-server.com/

Thank you. I think modifying each instance will work in my case since it is something that will not be done that often.