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);
}
}
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;
}
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;
}
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);
}
}
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);
}
}
Aggregations