StoreService { public Instance newInstance(String sourceAET, Attributes data, Attributes modified, StoreContext storeContext) throws DicomServiceException { StoreParam storeParam = storeContext.getStoreParam(); Availability rnAvailability = storeParam.getRejectionNoteAvailability(data); if (rnAvailability != null) { processRejectionNote(data, rnAvailability); } Series series = findOrCreateSeries(sourceAET, data, storeContext); Availability availability = rnAvailability != null ? Availability.availabilityOfRejectedObject(rnAvailability) : storeContext.isRejectedByMPPS() ? Availability.INCORRECT_MODALITY_WORKLIST_ENTRY : storeContext.getAvailability(); coerceAttributes(series, data, modified); if (!modified.isEmpty() && storeParam.isStoreOriginalAttributes()) { Attributes item = new Attributes(4); Sequence origAttrsSeq = data.ensureSequence(Tag.OriginalAttributesSequence, 1); origAttrsSeq.add(item); item.setDate(Tag.AttributeModificationDateTime, VR.DT, new Date()); item.setString(Tag.ModifyingSystem, VR.LO, storeParam.getModifyingSystem()); item.setString(Tag.SourceOfPreviousValues, VR.LO, sourceAET); item.newSequence(Tag.ModifiedAttributesSequence, 1).add(modified); } Instance inst = new Instance(); inst.setSeries(series); inst.setConceptNameCode(singleCode(data, Tag.ConceptNameCodeSequence)); inst.setVerifyingObservers(createVerifyingObservers( data.getSequence(Tag.VerifyingObserverSequence), storeParam.getFuzzyStr())); inst.setContentItems( createContentItems(data.getSequence(Tag.ContentSequence))); inst.setRetrieveAETs(storeParam.getRetrieveAETs()); inst.setExternalRetrieveAET(storeParam.getExternalRetrieveAET()); inst.setAvailability(availability); inst.setAttributes(data, storeParam.getAttributeFilter(Entity.Instance), storeParam.getFuzzyStr()); em.persist(inst); em.flush(); em.detach(inst); return inst; }  FileSystem selectFileSystem(String groupID, String initFileSystemURI); FileRef addFileRef(String sourceAET, Attributes data,
            Attributes modified, File file, String digest, String tsuid,
            StoreContext storeContext); Instance newInstance(String sourceAET, Attributes data,
            Attributes modified, StoreContext storeContext);  }
@Test public void testNewInstance() throws Exception { Attributes mpps_create = load("testdata/mpps-create.xml"); IDWithIssuer pid = IDWithIssuer.pidWithIssuer(mpps_create, null); String sourceAET = mpps_create.getString(Tag.PerformedStationAETitle); clearData(pid); StoreParam storeParam = ParamFactory.createStoreParam(); StoreContext storeContext = new StoreContext(storeParam); PerformedProcedureStep pps = mppsService.createPerformedProcedureStep( MPPS_IUID, mpps_create, storeParam); assertEquals(PerformedProcedureStep.Status.IN_PROGRESS, pps.getStatus()); PPSWithIAN ppsWithIAN = mppsService.updatePerformedProcedureStep( MPPS_IUID, load("testdata/mpps-set.xml"), storeParam); assertEquals(PerformedProcedureStep.Status.COMPLETED, ppsWithIAN.pps.getStatus()); storeParam.setRetrieveAETs("AET_1","AET_2"); storeParam.setExternalRetrieveAET("AET_3"); storeContext.setAvailability(Availability.ONLINE); Attributes modified1 = new Attributes(); Instance ct1 = storeService.newInstance(sourceAET, load("testdata/store-ct-1.xml"), modified1, storeContext); assertTrue(modified1.isEmpty()); storeParam.setRetrieveAETs("AET_2"); storeParam.setExternalRetrieveAET("AET_3"); storeContext.setAvailability(Availability.NEARLINE); Attributes modified2 = new Attributes(); Instance ct2 = storeService.newInstance(sourceAET, load("testdata/store-ct-2.xml"), modified2, storeContext); assertEquals(2, modified2.size()); assertEquals("TEST-REPLACE", modified2.getString(Tag.StudyID)); assertEquals("0", modified2.getString(Tag.SeriesNumber)); storeParam.setRetrieveAETs("AET_1","AET_2"); storeParam.setExternalRetrieveAET("AET_4"); storeContext.setAvailability(Availability.ONLINE); Attributes modified3 = new Attributes(); Instance pr1 = storeService.newInstance(sourceAET, load("testdata/store-pr-1.xml"), modified3, storeContext); assertEquals(1, modified3.size()); assertEquals("TEST-REPLACE", modified3.getString(Tag.StudyID)); List<Attributes> ians = ianQueryService.createIANsforMPPS(storeContext.getCurrentMPPS()); assertEquals(1, ians.size()); Series ctSeries = ct2.getSeries(); Series prSeries = pr1.getSeries(); Study study = prSeries.getStudy(); assertEquals(ct1.getSeries().getPk(), ctSeries.getPk()); assertEquals(ctSeries.getStudy().getPk(), study.getPk()); assertArrayEquals(new String[]{"CT", "PR" }, sort(study.getModalitiesInStudy())); assertArrayEquals( new String[]{ "1.2.840.10008.5.1.4.1.1.11.1", "1.2.840.10008.5.1.4.1.1.2" }, sort(study.getSOPClassesInStudy())); assertArrayEquals(new String[]{"AET_2"}, ctSeries.getRetrieveAETs()); assertArrayEquals(new String[]{"AET_1", "AET_2"}, sort(prSeries.getRetrieveAETs())); assertArrayEquals(new String[]{"AET_2"}, study.getRetrieveAETs()); assertEquals("AET_3", ctSeries.getExternalRetrieveAET()); assertEquals("AET_4", prSeries.getExternalRetrieveAET()); assertNull(study.getExternalRetrieveAET()); assertEquals(Availability.NEARLINE, ctSeries.getAvailability()); assertEquals(Availability.ONLINE, prSeries.getAvailability()); assertEquals(Availability.NEARLINE, study.getAvailability()); }