design setting class property with generated value on save

Hello all!

I am currently implementing a generator in the radiology module for the RadiologyStudy entity which generates a unique DICOM Study Instance UID and sets the RadiologyStudy.studyInstanceUID on creation.

I have looked into the approach of using a SaveHandler or the approach used by the Order with its OrderNumberGenerator

I wanted to ask you, what approach you find best in hindsight ? Pros/Cons?

My goal is to set the RadiologyStudy.studyInstanceUID if it is null before saving the entity so that RadiologyStudy.studyInstanceUID is always unique and set.

I also would like to make the generator pluggable so an implementation could choose a different one than the one I supply with the module.

Which is the other option you had in mind besides saveHandler?

The other option is how Order does it. They implement an interface of the OrderNumberGenerator and use it in saveOrder() to set Order.orderNumber for any new Order’s.

That isn’t really another option, that mechanism is a way to let external code to generate order numbers but not set them, however in your case you need a value to be generated and set.

well it is another option, it is setting the property in the OrderService.saveOrder(). Even with the SaveHandler I will have to call something like the OrderNumberGenerator generating my UID which will be set.

So the 2 options are setting the property of RadiologyStudy.studyInstanceUid either in

  1. RadiologyStudySaveHandler,
  2. or in the RadiologyStudyService.saveRadiologyStudy()

both will make use of a Uid Generator.

I am leaning towards the RadiologyStudyService.saveRadiologyStudy() but am not sure yet.

Well, if the save method is within your module, then you might as well go ahead and do it inside it rather than using a saveHandler

1 Like