diff --git a/dcm4chee-arc-entity/src/main/java/org/dcm4chee/arc/entity/Series.java b/dcm4chee-arc-entity/src/main/java/org/dcm4chee/arc/entity/Series.java index c564943bcb..df43f26e29 100644 --- a/dcm4chee-arc-entity/src/main/java/org/dcm4chee/arc/entity/Series.java +++ b/dcm4chee-arc-entity/src/main/java/org/dcm4chee/arc/entity/Series.java @@ -110,6 +110,9 @@ @NamedQuery( name=Series.SET_SERIES_SIZE, query="update Series se set se.size = ?2 where se.pk = ?1"), +@NamedQuery( + name=Series.RESET_SERIES_SIZE_AND_EXTERNAL_RETRIEVE_AET, + query="update Series se set se.size = -1L, se.externalRetrieveAET = null where se.pk = ?1"), @NamedQuery( name=Series.SET_COMPLETENESS, query="update Series ser set ser.completeness = ?3 " + @@ -351,6 +354,7 @@ public class Series { public static final String SERIES_PKS_OF_STUDY_WITH_UNKNOWN_SIZE = "Series.seriesPKsOfStudyWithUnknownSize"; public static final String SIZE_OF_STUDY="Series.sizeOfStudy"; public static final String SET_SERIES_SIZE = "Series.SetSeriesSize"; + public static final String RESET_SERIES_SIZE_AND_EXTERNAL_RETRIEVE_AET = "Series.ResetSeriesSizeAndExternalRetrieveAET"; public static final String SET_COMPLETENESS = "Series.SetCompleteness"; public static final String SET_COMPLETENESS_OF_STUDY = "Series.SetCompletenessOfStudy"; public static final String INCREMENT_FAILED_RETRIEVES = "Series.IncrementFailedRetrieves"; @@ -889,8 +893,16 @@ public void setExternalRetrieveAET(String externalRetrieveAET) { this.externalRetrieveAET = externalRetrieveAET; } - public void resetSize() { + public boolean resetExternalRetrieveAET() { + if (externalRetrieveAET == null) return false; + this.externalRetrieveAET = null; + return true; + } + + public boolean resetSize() { + if (size == -1) return false; this.size = -1L; + return true; } public long getSize() { diff --git a/dcm4chee-arc-entity/src/main/java/org/dcm4chee/arc/entity/Study.java b/dcm4chee-arc-entity/src/main/java/org/dcm4chee/arc/entity/Study.java index aa76e1f0ca..6bb33f6ebf 100644 --- a/dcm4chee-arc-entity/src/main/java/org/dcm4chee/arc/entity/Study.java +++ b/dcm4chee-arc-entity/src/main/java/org/dcm4chee/arc/entity/Study.java @@ -85,6 +85,9 @@ @NamedQuery( name=Study.SET_STUDY_SIZE, query="update Study st set st.size = ?2 where st.pk = ?1"), + @NamedQuery( + name=Study.RESET_STUDY_SIZE_AND_EXTERNAL_RETRIEVE_AET, + query="update Study st set st.size = -1L, st.externalRetrieveAET = null where st.pk = ?1"), @NamedQuery( name=Study.SET_COMPLETENESS, query="update Study st set st.completeness = ?2 " + @@ -174,6 +177,7 @@ public class Study { public static final String FIND_BY_STUDY_IUID_EAGER = "Study.findByStudyIUIDEager"; public static final String UPDATE_ACCESS_TIME = "Study.UpdateAccessTime"; public static final String SET_STUDY_SIZE = "Study.setStudySize"; + public static final String RESET_STUDY_SIZE_AND_EXTERNAL_RETRIEVE_AET = "Study.resetStudySizeAndExternalRetrieve"; public static final String SET_COMPLETENESS = "Study.setCompleteness"; public static final String INCREMENT_FAILED_RETRIEVES = "Study.incrementFailedRetrieves"; public static final String COUNT_STUDIES_OF_PATIENT = "Study.countStudiesOfPatient"; @@ -596,8 +600,16 @@ public void setExternalRetrieveAET(String externalRetrieveAET) { this.externalRetrieveAET = externalRetrieveAET; } - public void resetSize() { + public boolean resetExternalRetrieveAET() { + if (externalRetrieveAET == null) return false; + this.externalRetrieveAET = null; + return true; + } + + public boolean resetSize() { + if (size == -1) return false; this.size = -1L; + return true; } public Collection getProcedureCodes() { diff --git a/dcm4chee-arc-store/src/main/java/org/dcm4chee/arc/store/impl/StoreServiceEJB.java b/dcm4chee-arc-store/src/main/java/org/dcm4chee/arc/store/impl/StoreServiceEJB.java index 1da7cc93c3..013792c732 100644 --- a/dcm4chee-arc-store/src/main/java/org/dcm4chee/arc/store/impl/StoreServiceEJB.java +++ b/dcm4chee-arc-store/src/main/java/org/dcm4chee/arc/store/impl/StoreServiceEJB.java @@ -299,7 +299,6 @@ && getRejectionNote(arcDev, prevInstance.getConceptNameCode()) != null) { deleteQueryAttributes(instance); Series series = instance.getSeries(); Study study = series.getStudy(); - study.resetSize(); if (replaceLocationOnDifferentStorage) { String prevStorageIDs = study.getEncodedStorageIDs(); study.setStorageIDs(queryStorageIDsOfStudy(study).toArray(StringUtils.EMPTY_STRING)); @@ -1018,8 +1017,10 @@ private Study updateStudy(StoreContext ctx, Study study, Date now, String reason updated = attrs.updateSelected(updatePolicy, ctx.getAttributes(), updateInfo.modified, filter.getSelection(false)) || updated; - if (!updated) + if (!updated) { + resetStudySizeAndExternalRetrieveAET(study); return study; + } updateInfo.log(session, study, attrs); study = em.find(Study.class, study.getPk()); @@ -1031,9 +1032,20 @@ private Study updateStudy(StoreContext ctx, Study study, Date now, String reason em.createNamedQuery(Series.SCHEDULE_METADATA_UPDATE_FOR_STUDY) .setParameter(1, study) .executeUpdate(); + study.resetSize(); + study.resetExternalRetrieveAET(); return study; } + private void resetStudySizeAndExternalRetrieveAET(Study study) { + boolean resetSize = study.resetSize(); + boolean resetExternalRetrieveAET = study.resetExternalRetrieveAET(); + if (resetSize || resetExternalRetrieveAET) { + em.createNamedQuery(Study.RESET_STUDY_SIZE_AND_EXTERNAL_RETRIEVE_AET) + .setParameter(1, study.getPk()); + } + } + private boolean supplementIssuer(Attributes attrs, Attributes newAttrs, Attributes modified, int idtag, int seqtag) { String id = attrs.getString(idtag); @@ -1070,8 +1082,10 @@ private Series updateSeries(StoreContext ctx, Series series, Date now, String re Attributes attrs = series.getAttributes(); UpdateInfo updateInfo = new UpdateInfo(attrs); Attributes.unifyCharacterSets(attrs, ctx.getAttributes()); - if (!attrs.updateSelected(updatePolicy, ctx.getAttributes(), updateInfo.modified, filter.getSelection(false))) + if (!attrs.updateSelected(updatePolicy, ctx.getAttributes(), updateInfo.modified, filter.getSelection(false))) { + resetSeriesSizeAndExternalRetrieveAET(series); return series; + } updateInfo.log(session, series, attrs); series = em.find(Series.class, series.getPk()); @@ -1083,9 +1097,20 @@ private Series updateSeries(StoreContext ctx, Series series, Date now, String re series.setInstitutionCode(findOrCreateCode(attrs, Tag.InstitutionCodeSequence)); series.setInstitutionalDepartmentTypeCode(findOrCreateCode(attrs, Tag.InstitutionalDepartmentTypeCodeSequence)); setRequestAttributes(series, attrs, fuzzyStr); + series.resetSize(); + series.resetExternalRetrieveAET(); return series; } + private void resetSeriesSizeAndExternalRetrieveAET(Series series) { + boolean resetSize = series.resetSize(); + boolean resetExternalRetrieveAET = series.resetExternalRetrieveAET(); + if (resetSize || resetExternalRetrieveAET) { + em.createNamedQuery(Series.RESET_SERIES_SIZE_AND_EXTERNAL_RETRIEVE_AET) + .setParameter(1, series.getPk()); + } + } + public void replaceLocation(StoreContext ctx, InstanceLocations inst) { Instance instance = new Instance(); instance.setPk(inst.getInstancePk());