We need to improve our StudyInstanceUid generation.
Currently when we save a Study we do this
so we save it twice and use the studyId generated by the DB to construct the studyInstanceUid. Thus, on DB level the column study_instance_uid does not enforce a not null constraint, which is bad. A Study without StudyInstanceUid should not exist. Plus the db column is a varchar(250) although DICOM max is 64.
Maybe we need something like the OrderNumberGenerator thats implemented in the core, which generates a studyInstanceUid for every new Study, without relying on the DB.
And we need to adhere to http://dicom.nema.org/dicom/2013/output/chtml/part05/chapter_9.html
also see an implementation example https://github.com/darcymason/pydicom/blob/master/pydicom/uid.py#L164