Search in sources :

Example 1 with DicomServiceException

use of org.dcm4che3.net.service.DicomServiceException in project karnak by OsiriX-Foundation.

the class CStoreSCPService method store.

@Override
protected void store(Association as, PresentationContext pc, Attributes rq, PDVInputStream data, Attributes rsp) throws IOException {
    Optional<ForwardDicomNode> sourceNode = destinations.keySet().stream().filter(n -> n.getForwardAETitle().equals(as.getCalledAET())).findFirst();
    if (sourceNode.isEmpty()) {
        throw new IllegalStateException("Cannot find the forward AeTitle " + as.getCalledAET());
    }
    ForwardDicomNode fwdNode = sourceNode.get();
    List<ForwardDestination> destList = destinations.get(fwdNode);
    if (destList == null || destList.isEmpty()) {
        throw new IllegalStateException("No DICOM destinations for " + fwdNode);
    }
    DicomNode callingNode = DicomNode.buildRemoteDicomNode(as);
    Set<DicomNode> srcNodes = fwdNode.getAcceptedSourceNodes();
    boolean valid = srcNodes.isEmpty() || srcNodes.stream().anyMatch(n -> n.getAet().equals(callingNode.getAet()) && (!n.isValidateHostname() || n.equalsHostname(callingNode.getHostname())));
    if (!valid) {
        rsp.setInt(Tag.Status, VR.US, Status.NotAuthorized);
        LOGGER.error("Refused: not authorized (124H). Source node: {}. SopUID: {}", callingNode, rq.getString(Tag.AffectedSOPInstanceUID));
        return;
    }
    rsp.setInt(Tag.Status, VR.US, status);
    try {
        Params p = new Params(rq.getString(Tag.AffectedSOPInstanceUID), rq.getString(Tag.AffectedSOPClassUID), pc.getTransferSyntax(), priority, data, as);
        // Update transfer status of destinations
        updateTransferStatus(destList);
        forwardService.storeMultipleDestination(fwdNode, destList, p);
    } catch (Exception e) {
        throw new DicomServiceException(Status.ProcessingFailure, e);
    }
}
Also used : ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) ScheduledFuture(java.util.concurrent.ScheduledFuture) VR(org.dcm4che3.data.VR) Attributes(org.dcm4che3.data.Attributes) ForwardDestination(org.karnak.backend.dicom.ForwardDestination) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) DicomNode(org.weasis.dicom.param.DicomNode) Service(org.springframework.stereotype.Service) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) DestinationRepo(org.karnak.backend.data.repo.DestinationRepo) PDVInputStream(org.dcm4che3.net.PDVInputStream) Logger(org.slf4j.Logger) Params(org.karnak.backend.dicom.Params) Set(java.util.Set) IOException(java.io.IOException) Status(org.dcm4che3.net.Status) ZoneId(java.time.ZoneId) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Association(org.dcm4che3.net.Association) List(java.util.List) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) Tag(org.dcm4che3.data.Tag) BasicCStoreSCP(org.dcm4che3.net.service.BasicCStoreSCP) Optional(java.util.Optional) DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) PresentationContext(org.dcm4che3.net.pdu.PresentationContext) Params(org.karnak.backend.dicom.Params) ForwardDestination(org.karnak.backend.dicom.ForwardDestination) DicomNode(org.weasis.dicom.param.DicomNode) ForwardDicomNode(org.karnak.backend.dicom.ForwardDicomNode) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) IOException(java.io.IOException) DicomServiceException(org.dcm4che3.net.service.DicomServiceException)

Example 2 with DicomServiceException

use of org.dcm4che3.net.service.DicomServiceException in project dcm4chee-arc-light by dcm4che.

the class UPSServiceEJB method updateUPS.

public UPS updateUPS(UPSContext ctx) throws DicomServiceException {
    ArchiveAEExtension arcAE = ctx.getArchiveAEExtension();
    ArchiveDeviceExtension arcDev = arcAE.getArchiveDeviceExtension();
    UPS ups = findUPS(ctx);
    ctx.setTemplate(isTemplateUpdate(ctx, ups));
    String transactionUID = ctx.getAttributes().getString(Tag.TransactionUID);
    switch(ups.getProcedureStepState()) {
        case SCHEDULED:
            if (transactionUID != null)
                throw new DicomServiceException(Status.UPSNotYetInProgress, "The submitted request is inconsistent with the current state of the UPS Instance.", false);
            break;
        case IN_PROGRESS:
            if (transactionUID == null)
                throw new DicomServiceException(Status.UPSTransactionUIDNotCorrect, "The Transaction UID is missing.", false);
            if (!transactionUID.equals(ups.getTransactionUID()))
                throw new DicomServiceException(Status.UPSTransactionUIDNotCorrect, "The Transaction UID is incorrect.", false);
            break;
        case CANCELED:
        case COMPLETED:
            throw new DicomServiceException(Status.UPSMayNoLongerBeUpdated, "The submitted request is inconsistent with the current state of the UPS Instance.", false);
    }
    AttributeFilter filter = arcDev.getAttributeFilter(Entity.UPS);
    Attributes modified = new Attributes();
    Attributes attrs = ups.getAttributes();
    boolean prevIssuerOfAdmissionID = attrs.containsValue(Tag.IssuerOfAdmissionIDSequence);
    boolean prevWorkitemCode = attrs.containsValue(Tag.ScheduledWorkitemCodeSequence);
    boolean prevStationName = attrs.containsValue(Tag.ScheduledStationNameCodeSequence);
    boolean prevStationClass = attrs.containsValue(Tag.ScheduledStationClassCodeSequence);
    boolean prevStationLocation = attrs.containsValue(Tag.ScheduledStationGeographicLocationCodeSequence);
    boolean prevPerformers = attrs.containsValue(Tag.ScheduledHumanPerformersSequence);
    boolean prevRequest = attrs.containsValue(Tag.ReferencedRequestSequence);
    boolean prevProgressInformation = attrs.containsValue(Tag.ProcedureStepProgressInformationSequence);
    if (!attrs.updateSelected(Attributes.UpdatePolicy.OVERWRITE, ctx.getAttributes(), modified, filter.getSelection())) {
        return ups;
    }
    boolean issuerOfAdmissionIDUpdated = (prevIssuerOfAdmissionID ? modified : attrs).containsValue(Tag.IssuerOfAdmissionIDSequence);
    if (issuerOfAdmissionIDUpdated) {
        ups.setIssuerOfAdmissionID(findOrCreateIssuer(attrs, Tag.IssuerOfAdmissionIDSequence));
    }
    boolean workitemCodeUpdated = (prevWorkitemCode ? modified : attrs).containsValue(Tag.ScheduledWorkitemCodeSequence);
    if (workitemCodeUpdated) {
        ups.setScheduledWorkitemCode(findOrCreateCode(attrs, Tag.ScheduledWorkitemCodeSequence));
    }
    boolean stationNameUpdated = (prevStationName ? modified : attrs).containsValue(Tag.ScheduledStationNameCodeSequence);
    if (stationNameUpdated) {
        ups.setScheduledStationNameCode(findOrCreateCode(attrs, Tag.ScheduledStationNameCodeSequence));
    }
    boolean stationClassUpdated = (prevStationClass ? modified : attrs).containsValue(Tag.ScheduledStationClassCodeSequence);
    if (stationClassUpdated) {
        ups.setScheduledStationClassCode(findOrCreateCode(attrs, Tag.ScheduledStationClassCodeSequence));
    }
    boolean stationLocationUpdated = (prevStationLocation ? modified : attrs).containsValue(Tag.ScheduledStationGeographicLocationCodeSequence);
    if (stationLocationUpdated) {
        ups.setScheduledStationGeographicLocationCode(findOrCreateCode(attrs, Tag.ScheduledStationGeographicLocationCodeSequence));
    }
    boolean performerUpdated = (prevPerformers ? modified : attrs).containsValue(Tag.ScheduledHumanPerformersSequence);
    if (performerUpdated) {
        setHumanPerformerCodes(ups.getHumanPerformerCodes(), attrs.getSequence(Tag.ScheduledHumanPerformersSequence));
    }
    boolean requestUpdated = (prevRequest ? modified : attrs).containsValue(Tag.ReferencedRequestSequence);
    if (requestUpdated) {
        setReferencedRequests(ups.getReferencedRequests(), attrs.getSequence(Tag.ReferencedRequestSequence), arcDev.getFuzzyStr());
    }
    ups.setAttributes(attrs, filter);
    LOG.info("{}: Update {}", ctx, ups);
    List<String> subcribers = subscribersOf(ups);
    if (subcribers.isEmpty()) {
        return ups;
    }
    if (modified.contains(Tag.InputReadinessState)) {
        ctx.addUPSEvent(UPSEvent.Type.StateReport, ups.getUPSInstanceUID(), stateReportOf(attrs), subcribers);
    }
    boolean progressInformationUpdated = (prevProgressInformation ? modified : attrs).containsValue(Tag.ProcedureStepProgressInformationSequence);
    if (progressInformationUpdated) {
        ctx.addUPSEvent(UPSEvent.Type.ProgressReport, ups.getUPSInstanceUID(), progressReportOf(attrs), subcribers);
    }
    for (Attributes eventInformation : assigned(attrs, stationNameUpdated, performerUpdated)) {
        ctx.addUPSEvent(UPSEvent.Type.Assigned, ups.getUPSInstanceUID(), eventInformation, subcribers);
    }
    return ups;
}
Also used : DicomServiceException(org.dcm4che3.net.service.DicomServiceException)

Example 3 with DicomServiceException

use of org.dcm4che3.net.service.DicomServiceException in project dcm4chee-arc-light by dcm4che.

the class UPSServiceEJB method changeUPSState.

public UPS changeUPSState(UPSContext ctx, UPSState upsState, String transactionUID) throws DicomServiceException {
    UPS ups = findUPS(ctx);
    Attributes attrs = ups.getAttributes();
    if (ctx.getMergeAttributes() != null)
        attrs.addAll(ctx.getMergeAttributes());
    switch(upsState) {
        case IN_PROGRESS:
            switch(ups.getProcedureStepState()) {
                case IN_PROGRESS:
                    throw new DicomServiceException(Status.UPSAlreadyInProgress, "The submitted request is inconsistent with the current state of the UPS Instance.", false);
                case CANCELED:
                case COMPLETED:
                    throw new DicomServiceException(Status.UPSMayNoLongerBeUpdated, "The submitted request is inconsistent with the current state of the UPS Instance.", false);
            }
            ups.setTransactionUID(transactionUID);
            ups.setPerformerAET(ctx.getRequesterAET());
            break;
        case CANCELED:
            switch(ups.getProcedureStepState()) {
                case SCHEDULED:
                    throw new DicomServiceException(Status.UPSNotYetInProgress, "The submitted request is inconsistent with the current state of the UPS Instance.", false);
                case CANCELED:
                    ctx.setStatus(Status.UPSAlreadyInRequestedStateOfCanceled);
                    return ups;
                case COMPLETED:
                    throw new DicomServiceException(Status.UPSMayNoLongerBeUpdated, "The submitted request is inconsistent with the current state of the UPS Instance.", false);
            }
            if (!transactionUID.equals(ups.getTransactionUID()))
                throw new DicomServiceException(Status.UPSTransactionUIDNotCorrect, "The Transaction UID is incorrect.", false);
            supplementDiscontinuationReasonCode(ensureProgressInformation(attrs));
            ups.setTransactionUID(null);
            break;
        case COMPLETED:
            switch(ups.getProcedureStepState()) {
                case SCHEDULED:
                    throw new DicomServiceException(Status.UPSNotYetInProgress, "The submitted request is inconsistent with the current state of the UPS Instance.", false);
                case CANCELED:
                    throw new DicomServiceException(Status.UPSMayNoLongerBeUpdated, "The submitted request is inconsistent with the current state of the UPS Instance.", false);
                case COMPLETED:
                    ctx.setStatus(Status.UPSAlreadyInRequestedStateOfCompleted);
                    return ups;
            }
            if (!transactionUID.equals(ups.getTransactionUID()))
                throw new DicomServiceException(Status.UPSTransactionUIDNotCorrect, "The Transaction UID is incorrect.", false);
            if (!meetFinalStateRequirementsOfCompleted(attrs))
                throw new DicomServiceException(Status.UPSNotMetFinalStateRequirements, "The submitted request is inconsistent with the current state of the UPS Instance.", false);
            ups.setTransactionUID(null);
            break;
    }
    attrs.setString(Tag.ProcedureStepState, VR.CS, upsState.toString());
    List<String> subcribers = subscribersOf(ups);
    if (!subcribers.isEmpty()) {
        ctx.addUPSEvent(UPSEvent.Type.StateReport, ctx.getUPSInstanceUID(), stateReportOf(attrs), subcribers);
    }
    ups.setAttributes(attrs, ctx.getArchiveDeviceExtension().getAttributeFilter(Entity.UPS));
    LOG.info("{}: Update {}", ctx, ups);
    return ups;
}
Also used : DicomServiceException(org.dcm4che3.net.service.DicomServiceException)

Example 4 with DicomServiceException

use of org.dcm4che3.net.service.DicomServiceException in project dcm4chee-arc-light by dcm4che.

the class UPSServiceImpl method createUPS.

@Override
public UPS createUPS(UPSContext ctx) throws DicomServiceException {
    Attributes attrs = ctx.getAttributes();
    ValidationResult validate = attrs.validate(ctx.isTemplate() ? CREATE_TEMPLATE_IOD : CREATE_IOD);
    if (!validate.isValid()) {
        throw DicomServiceException.valueOf(validate, attrs);
    }
    if (ctx.isGlobalSubscription()) {
        throw new DicomServiceException(Status.DuplicateSOPinstance, "Cannot create UPS Global Subscription SOP Instance", false);
    }
    if (!"SCHEDULED".equals(attrs.getString(Tag.ProcedureStepState))) {
        throw new DicomServiceException(Status.UPSNotScheduled, "The provided value of UPS State was not SCHEDULED");
    }
    if (!attrs.containsValue(Tag.WorklistLabel)) {
        attrs.setString(Tag.WorklistLabel, VR.LO, ctx.getArchiveAEExtension().upsWorklistLabel());
    }
    try {
        UPS ups = ejb.createUPS(ctx);
        fireUPSEvents(ctx);
        return ups;
    } catch (Exception e) {
        if (upsExists(ctx))
            throw new DicomServiceException(Status.DuplicateSOPinstance, "The UPS already exists.", false);
        throw new DicomServiceException(Status.ProcessingFailure, e);
    }
}
Also used : QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) UPS(org.dcm4chee.arc.entity.UPS) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) EJBException(javax.ejb.EJBException) SAXException(org.xml.sax.SAXException) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) ConfigurationNotFoundException(org.dcm4che3.conf.api.ConfigurationNotFoundException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException)

Example 5 with DicomServiceException

use of org.dcm4che3.net.service.DicomServiceException in project dcm4chee-arc-light by dcm4che.

the class UPSServiceImpl method changeUPSState.

@Override
public UPS changeUPSState(UPSContext ctx) throws DicomServiceException {
    Attributes attrs = ctx.getAttributes();
    String transactionUID = attrs.getString(Tag.TransactionUID);
    if (transactionUID == null)
        throw new DicomServiceException(Status.InvalidArgumentValue, "The Transaction UID is missing.", false);
    UPSState upsState;
    try {
        upsState = UPSState.fromString(attrs.getString(Tag.ProcedureStepState));
    } catch (NullPointerException e) {
        throw new DicomServiceException(Status.InvalidArgumentValue, "The Procedure Step State is missing.", false);
    } catch (IllegalArgumentException e) {
        throw new DicomServiceException(Status.InvalidArgumentValue, "The Procedure Step State is invalid.", false);
    }
    if (upsState == UPSState.SCHEDULED) {
        throw new DicomServiceException(Status.UPSStateMayNotChangedToScheduled, "The submitted request is inconsistent with the current state of the UPS Instance.", false);
    }
    try {
        UPS ups = ejb.changeUPSState(ctx, upsState, transactionUID);
        fireUPSEvents(ctx);
        if (upsState == UPSState.COMPLETED)
            onUPSCompleted(ctx, ups);
        return ups;
    } catch (DicomServiceException e) {
        throw e;
    } catch (Exception e) {
        throw new DicomServiceException(Status.ProcessingFailure, e);
    }
}
Also used : QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) UPS(org.dcm4chee.arc.entity.UPS) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) EJBException(javax.ejb.EJBException) SAXException(org.xml.sax.SAXException) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) ConfigurationNotFoundException(org.dcm4che3.conf.api.ConfigurationNotFoundException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException)

Aggregations

DicomServiceException (org.dcm4che3.net.service.DicomServiceException)70 IOException (java.io.IOException)28 Attributes (org.dcm4che3.data.Attributes)21 UPSContext (org.dcm4chee.arc.ups.UPSContext)16 ConfigurationException (org.dcm4che3.conf.api.ConfigurationException)10 StoreSession (org.dcm4chee.arc.store.StoreSession)10 EJBException (javax.ejb.EJBException)8 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)8 ConfigurationNotFoundException (org.dcm4che3.conf.api.ConfigurationNotFoundException)8 QueryAttributes (org.dcm4chee.arc.query.util.QueryAttributes)8 SAXException (org.xml.sax.SAXException)8 ArchiveAEExtension (org.dcm4chee.arc.conf.ArchiveAEExtension)7 ArchiveDeviceExtension (org.dcm4chee.arc.conf.ArchiveDeviceExtension)5 UPS (org.dcm4chee.arc.entity.UPS)5 QueryContext (org.dcm4chee.arc.query.QueryContext)5 File (java.io.File)4 DicomOutputStream (org.dcm4che3.io.DicomOutputStream)4 QueryOption (org.dcm4che3.net.QueryOption)4 InstanceLocations (org.dcm4chee.arc.store.InstanceLocations)4 Association (org.dcm4che3.net.Association)3