@@ -46,36 +46,26 @@ public class ComplexObsSaver {
4646 @ Qualifier (AttachmentsConstants .COMPONENT_COMPLEXDATA_HELPER )
4747 protected ComplexDataHelper complexDataHelper ;
4848
49- @ Autowired
50- @ Qualifier (AttachmentsConstants .COMPONENT_VISIT_COMPATIBILITY )
51- protected VisitCompatibility visitCompatibility ;
52-
53- protected Obs obs = new Obs ();
54-
55- protected ConceptComplex conceptComplex ;
56-
57- public Obs getObs () {
58- return obs ;
59- }
60-
61- protected void prepareComplexObs (Visit visit , Person person , Encounter encounter , String fileCaption ,
62- String formFieldNamespace , String formFieldPath ) {
63- obs = new Obs (person , conceptComplex ,
49+ protected Obs prepareComplexObs (Visit visit , Person person , Encounter encounter , String fileCaption ,
50+ String formFieldNamespace , String formFieldPath , ConceptComplex conceptComplex ) {
51+ Obs obs = new Obs (person , conceptComplex ,
6452 visit == null || visit .getStopDatetime () == null ? new Date () : visit .getStopDatetime (),
6553 encounter != null ? encounter .getLocation () : null );
6654 obs .setEncounter (encounter ); // may be null
6755 obs .setComment (fileCaption );
6856 if (StringUtils .isNotBlank (formFieldNamespace ) && StringUtils .isNotBlank (formFieldPath )) {
6957 obs .setFormField (formFieldNamespace , formFieldPath );
7058 }
59+ return obs ;
7160 }
7261
7362 public Obs saveImageAttachment (Visit visit , Person person , Encounter encounter , String fileCaption ,
7463 MultipartFile multipartFile , String instructions , String formFieldNamespace , String formFieldPath )
7564 throws IOException {
7665
77- conceptComplex = context .getConceptComplex (ContentFamily .IMAGE );
78- prepareComplexObs (visit , person , encounter , fileCaption , formFieldNamespace , formFieldPath );
66+ ConceptComplex conceptComplex = context .getConceptComplex (ContentFamily .IMAGE );
67+ Obs obs = prepareComplexObs (visit , person , encounter , fileCaption , formFieldNamespace , formFieldPath ,
68+ conceptComplex );
7969
8070 Object image = multipartFile .getInputStream ();
8171 double compressionRatio = getCompressionRatio (multipartFile .getSize (),
@@ -94,8 +84,9 @@ public Obs saveImageAttachment(Visit visit, Person person, Encounter encounter,
9484 public Obs saveOtherAttachment (Visit visit , Person person , Encounter encounter , String fileCaption ,
9585 MultipartFile multipartFile , String instructions , String formFieldNamespace , String formFieldPath )
9686 throws IOException {
97- conceptComplex = context .getConceptComplex (ContentFamily .OTHER );
98- prepareComplexObs (visit , person , encounter , fileCaption , formFieldNamespace , formFieldPath );
87+ ConceptComplex conceptComplex = context .getConceptComplex (ContentFamily .OTHER );
88+ Obs obs = prepareComplexObs (visit , person , encounter , fileCaption , formFieldNamespace , formFieldPath ,
89+ conceptComplex );
9990
10091 obs .setComplexData (complexDataHelper .build (instructions ,
10192 replacePipeCharactersInFilenameWithUnderscores (multipartFile .getOriginalFilename ()),
0 commit comments