I solved the repeated requests in the OnStoredInstance event by using the StudyInstanceUID of the instances. Below are the changes I applied to the previous code.
Create a global variable to store studies which had its first instance processed in the OnStoredInstance event
processedStudies = {}
Define your OnStoredInstance with the StudyInstanceUID check logic
def OnStoredInstance(dicom, instanceId):
instance = json.loads(dicom.GetInstanceSimplifiedJson())
studyInstanceUID = instance.get(‘StudyInstanceUID’)
global processedStudies
processedStudy = processedStudies.get(studyInstanceUID)
if not processedStudy:
processedStudies[studyInstanceUID] = True
your custom logic here, to be executed for the first received instance of a study…
Remove the StudyInstanceUID from the global variable in the stable study event
def onStableStudy(resourceId):
study = json.loads(orthanc.RestApiGet(‘/studies/%s’ % resourceId))
statistics = json.loads(orthanc.RestApiGet(‘/studies/%s/statistics’ % resourceId))
series = json.loads(orthanc.RestApiGet(‘/studies/%s/series’ % resourceId))
study.get(‘MainDicomTags’)[‘modalities’] = ‘,’.join(filter(None, set(map(lambda s: s.get(‘MainDicomTags’).get(‘Modality’), series))))
study.get(‘MainDicomTags’)[‘manufacturers’] = ‘,’.join(filter(None, set(map(lambda s: s.get(‘MainDicomTags’).get(‘Manufacturer’), series))))
study.get(‘MainDicomTags’)[‘bodyPartsExamined’] = ‘,’.join(filter(None, set(map(lambda s: s.get(‘MainDicomTags’).get(‘BodyPartExamined’), series))))
orthanc.RestApiPut(f"/studies/{resourceId}/metadata/Stable", “true”)
processedStudies.pop(study.get(‘MainDicomTags’).get(‘StudyInstanceUID’))
body = {
**study,
**statistics
}
response = requests.put(url=“###SISMED_FULL_URL###/api/dicom-exams/stable/” + resourceId, json=body, auth=HTTPBasicAuth(‘###SISMED_ADMIN###’, ‘###SISMED_ADMIN_PASSWORD###’), verify=False)
if response.ok:
orthanc.LogWarning(f"ESTÁVEL: {resourceId}“)
else:
orthanc.LogError(f"ERRO NA REQUISIÇÃO: {resourceId}”)
orthanc.LogError(f"RESPOSTA: {response.text}")
orthanc.LogError(response)
A sexta-feira, 8 de abril de 2022 à(s) 02:14:32 UTC+1, Diego Victor de Jesus escreveu: