Search in sources :

Example 16 with ArchiveAEExtension

use of org.dcm4chee.arc.conf.ArchiveAEExtension in project dcm4chee-arc-light by dcm4che.

the class StudyMgtRS method updateSeries.

@PUT
@Path("/studies/{study}/series/{series}")
@Consumes("application/dicom+json,application/json")
@Produces("application/json")
public StreamingOutput updateSeries(@PathParam("study") String studyUID, @PathParam("series") String seriesUID, InputStream in) {
    logRequest();
    ArchiveAEExtension arcAE = getArchiveAE();
    final Attributes attrs = toAttributes(in);
    IDWithIssuer patientID = IDWithIssuer.pidOf(attrs);
    if (patientID == null || !attrs.containsValue(Tag.SeriesInstanceUID))
        throw new WebApplicationException(errResponse("Missing Patient ID or Series Instance UID in request payload", Response.Status.BAD_REQUEST));
    if (!seriesUID.equals(attrs.getString(Tag.SeriesInstanceUID)))
        throw new WebApplicationException(errResponse("Series UID in request does not match Series UID in request payload", Response.Status.BAD_REQUEST));
    Patient patient = patientService.findPatient(patientID);
    if (patient == null)
        throw new WebApplicationException(errResponse("Patient[id=" + patientID + "] does not exist.", Response.Status.NOT_FOUND));
    try {
        StudyMgtContext ctx = studyService.createStudyMgtContextWEB(HttpServletRequestInfo.valueOf(request), arcAE.getApplicationEntity());
        ctx.setPatient(patient);
        ctx.setAttributes(attrs);
        ctx.setStudyInstanceUID(studyUID);
        ctx.setSeriesInstanceUID(seriesUID);
        studyService.updateSeries(ctx);
        rsForward.forward(RSOperation.UpdateSeries, arcAE, attrs, request);
        return out -> {
            try (JsonGenerator gen = Json.createGenerator(out)) {
                arcAE.encodeAsJSONNumber(new JSONWriter(gen)).write(attrs);
            }
        };
    } catch (StudyMissingException e) {
        throw new WebApplicationException(errResponse(e.getMessage(), Response.Status.NOT_FOUND));
    } catch (PatientMismatchException e) {
        throw new WebApplicationException(errResponse(e.getMessage(), Response.Status.BAD_REQUEST));
    } catch (Exception e) {
        throw new WebApplicationException(errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR));
    }
}
Also used : JsonGenerator(javax.json.stream.JsonGenerator) Attributes(org.dcm4che3.data.Attributes) LoggerFactory(org.slf4j.LoggerFactory) NoResultException(javax.persistence.NoResultException) ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) StudyMgtContext(org.dcm4chee.arc.study.StudyMgtContext) Inject(javax.inject.Inject) RSOperation(org.dcm4chee.arc.conf.RSOperation) HttpServletRequest(javax.servlet.http.HttpServletRequest) JSONWriter(org.dcm4che3.json.JSONWriter) JSONReader(org.dcm4che3.json.JSONReader) InvokeValidate(org.dcm4chee.arc.validation.constraints.InvokeValidate) Json(javax.json.Json) StudyMissingException(org.dcm4chee.arc.study.StudyMissingException) DeletionService(org.dcm4chee.arc.delete.DeletionService) RSForward(org.dcm4chee.arc.rs.client.RSForward) StudyNotEmptyException(org.dcm4chee.arc.delete.StudyNotEmptyException) PrintWriter(java.io.PrintWriter) Patient(org.dcm4chee.arc.entity.Patient) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) StringWriter(java.io.StringWriter) ValidValueOf(org.dcm4chee.arc.validation.constraints.ValidValueOf) StudyService(org.dcm4chee.arc.study.StudyService) StreamingOutput(javax.ws.rs.core.StreamingOutput) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) InputStreamReader(java.io.InputStreamReader) StandardCharsets(java.nio.charset.StandardCharsets) Device(org.dcm4che3.net.Device) DateTimeParseException(java.time.format.DateTimeParseException) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) Tag(org.dcm4che3.data.Tag) HttpServletRequestInfo(org.dcm4chee.arc.keycloak.HttpServletRequestInfo) RequestScoped(javax.enterprise.context.RequestScoped) IDWithIssuer(org.dcm4che3.data.IDWithIssuer) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Pattern(javax.validation.constraints.Pattern) StudyNotFoundException(org.dcm4chee.arc.delete.StudyNotFoundException) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) UriInfo(javax.ws.rs.core.UriInfo) JsonParsingException(javax.json.stream.JsonParsingException) org.dcm4chee.arc.patient(org.dcm4chee.arc.patient) InputStream(java.io.InputStream) JSONWriter(org.dcm4che3.json.JSONWriter) IDWithIssuer(org.dcm4che3.data.IDWithIssuer) ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) StudyMgtContext(org.dcm4chee.arc.study.StudyMgtContext) Attributes(org.dcm4che3.data.Attributes) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) Patient(org.dcm4chee.arc.entity.Patient) JsonGenerator(javax.json.stream.JsonGenerator) NoResultException(javax.persistence.NoResultException) StudyMissingException(org.dcm4chee.arc.study.StudyMissingException) StudyNotEmptyException(org.dcm4chee.arc.delete.StudyNotEmptyException) DateTimeParseException(java.time.format.DateTimeParseException) StudyNotFoundException(org.dcm4chee.arc.delete.StudyNotFoundException) JsonParsingException(javax.json.stream.JsonParsingException) StudyMissingException(org.dcm4chee.arc.study.StudyMissingException)

Example 17 with ArchiveAEExtension

use of org.dcm4chee.arc.conf.ArchiveAEExtension in project dcm4chee-arc-light by dcm4che.

the class StudyMgtRS method deleteStudy.

@DELETE
@Path("/studies/{StudyUID}")
public void deleteStudy(@PathParam("StudyUID") String studyUID, @QueryParam("retainObj") @Pattern(regexp = "true|false") @DefaultValue("false") String retainObj) {
    logRequest();
    ArchiveAEExtension arcAE = getArchiveAE();
    try {
        deletionService.deleteStudy(studyUID, HttpServletRequestInfo.valueOf(request), arcAE, Boolean.parseBoolean(retainObj));
        rsForward.forward(RSOperation.DeleteStudy, arcAE, null, request);
    } catch (StudyNotFoundException e) {
        throw new WebApplicationException(errResponse(e.getMessage(), Response.Status.NOT_FOUND));
    } catch (StudyNotEmptyException e) {
        throw new WebApplicationException(errResponse(e.getMessage(), Response.Status.FORBIDDEN));
    } catch (Exception e) {
        throw new WebApplicationException(errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR));
    }
}
Also used : ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) StudyNotFoundException(org.dcm4chee.arc.delete.StudyNotFoundException) NoResultException(javax.persistence.NoResultException) StudyMissingException(org.dcm4chee.arc.study.StudyMissingException) StudyNotEmptyException(org.dcm4chee.arc.delete.StudyNotEmptyException) DateTimeParseException(java.time.format.DateTimeParseException) StudyNotFoundException(org.dcm4chee.arc.delete.StudyNotFoundException) JsonParsingException(javax.json.stream.JsonParsingException) StudyNotEmptyException(org.dcm4chee.arc.delete.StudyNotEmptyException)

Example 18 with ArchiveAEExtension

use of org.dcm4chee.arc.conf.ArchiveAEExtension in project dcm4chee-arc-light by dcm4che.

the class StudyMgtRS method moveStudyToPatient.

@POST
@Path("/studies/{study}/patient")
public Response moveStudyToPatient(@PathParam("study") String studyUID, @QueryParam("updatePolicy") @ValidValueOf(type = Attributes.UpdatePolicy.class, message = "Invalid attribute update policy") String updatePolicy) {
    logRequest();
    ArchiveAEExtension arcAE = getArchiveAE();
    QueryAttributes queryAttrs = new QueryAttributes(uriInfo, null);
    Attributes queryKeys = queryAttrs.getQueryKeys();
    if (queryKeys.getString(Tag.PatientID) == null)
        return errResponse("Missing Patient ID in query filters", Response.Status.BAD_REQUEST);
    IDWithIssuer pid = IDWithIssuer.pidOf(queryKeys);
    try {
        PatientMgtContext ctx = patientService.createPatientMgtContextWEB(HttpServletRequestInfo.valueOf(request));
        ctx.setAttributeUpdatePolicy(Attributes.UpdatePolicy.REPLACE);
        ctx.setPatientID(pid);
        ctx.setAttributes(queryKeys);
        if (updatePolicy != null)
            ctx.setAttributeUpdatePolicy(Attributes.UpdatePolicy.valueOf(updatePolicy));
        studyService.moveStudyToPatient(studyUID, ctx);
        rsForward.forward(RSOperation.MoveStudyToPatient, arcAE, null, request);
        return Response.noContent().build();
    } catch (StudyMissingException e) {
        return errResponse(e.getMessage(), Response.Status.BAD_REQUEST);
    } catch (NonUniquePatientException e) {
        return errResponse(e.getMessage(), Response.Status.CONFLICT);
    } catch (PatientMergedException e) {
        return errResponse(e.getMessage(), Response.Status.FORBIDDEN);
    } catch (Exception e) {
        return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) IDWithIssuer(org.dcm4che3.data.IDWithIssuer) ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) Attributes(org.dcm4che3.data.Attributes) QueryAttributes(org.dcm4chee.arc.query.util.QueryAttributes) NoResultException(javax.persistence.NoResultException) StudyMissingException(org.dcm4chee.arc.study.StudyMissingException) StudyNotEmptyException(org.dcm4chee.arc.delete.StudyNotEmptyException) DateTimeParseException(java.time.format.DateTimeParseException) StudyNotFoundException(org.dcm4chee.arc.delete.StudyNotFoundException) JsonParsingException(javax.json.stream.JsonParsingException) StudyMissingException(org.dcm4chee.arc.study.StudyMissingException)

Example 19 with ArchiveAEExtension

use of org.dcm4chee.arc.conf.ArchiveAEExtension in project dcm4chee-arc-light by dcm4che.

the class ApplyRetentionPolicy method applyRetentionPolicy.

@POST
@Path("/series")
@Produces("application/json")
public Response applyRetentionPolicy() {
    ApplicationEntity ae = device.getApplicationEntity(aet, true);
    if (ae == null || !ae.isInstalled())
        return errResponse("No such Application Entity: " + aet, Response.Status.NOT_FOUND);
    try {
        int count;
        ArchiveAEExtension arcAE = ae.getAEExtensionNotNull(ArchiveAEExtension.class);
        QueryContext ctx = queryContext(ae);
        try (Query query = queryService.createQuery(ctx)) {
            int queryMaxNumberOfResults = ctx.getArchiveAEExtension().queryMaxNumberOfResults();
            if (queryMaxNumberOfResults > 0 && !ctx.containsUniqueKey() && query.fetchCount() > queryMaxNumberOfResults)
                return errResponse("Request entity too large", Response.Status.BAD_REQUEST);
            ExpireSeries es = new ExpireSeries(ae, query);
            runInTx.execute(es);
            count = es.getCount();
        }
        rsForward.forward(RSOperation.ApplyRetentionPolicy, arcAE, null, request);
        return Response.ok("{\"count\":" + count + '}').build();
    } catch (Exception e) {
        return errResponseAsTextPlain(exceptionAsString(e), Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) Query(org.dcm4chee.arc.query.Query) ApplicationEntity(org.dcm4che3.net.ApplicationEntity) QueryContext(org.dcm4chee.arc.query.QueryContext)

Example 20 with ArchiveAEExtension

use of org.dcm4chee.arc.conf.ArchiveAEExtension in project dcm4chee-arc-light by dcm4che.

the class HL7PSUScheduler method onStore.

public void onStore(@Observes StoreContext ctx) {
    if (ctx.getException() != null || ctx.getLocations().isEmpty() || ctx.getRejectionNote() != null)
        return;
    StoreSession session = ctx.getStoreSession();
    ArchiveAEExtension arcAE = session.getArchiveAEExtension();
    if (arcAE.hl7PSUOnStudy() && arcAE.hl7PSUConditions().match(session.getRemoteHostName(), session.getCallingAET(), session.getLocalHostName(), session.getCalledAET(), ctx.getAttributes())) {
        try {
            ejb.createOrUpdateHL7PSUTaskForStudy(arcAE, ctx);
        } catch (Exception e) {
            LOG.warn("{}: Failed to create or update HL7PSUTask:\n", ctx, e);
        }
    }
}
Also used : ArchiveAEExtension(org.dcm4chee.arc.conf.ArchiveAEExtension) StoreSession(org.dcm4chee.arc.store.StoreSession)

Aggregations

ArchiveAEExtension (org.dcm4chee.arc.conf.ArchiveAEExtension)40 DicomServiceException (org.dcm4che3.net.service.DicomServiceException)17 JsonParsingException (javax.json.stream.JsonParsingException)15 ConfigurationException (org.dcm4che3.conf.api.ConfigurationException)11 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)10 ConnectException (java.net.ConnectException)9 ConfigurationNotFoundException (org.dcm4che3.conf.api.ConfigurationNotFoundException)9 QueryAttributes (org.dcm4chee.arc.query.util.QueryAttributes)9 SAXException (org.xml.sax.SAXException)9 Attributes (org.dcm4che3.data.Attributes)8 ArchiveDeviceExtension (org.dcm4chee.arc.conf.ArchiveDeviceExtension)7 StudyNotEmptyException (org.dcm4chee.arc.delete.StudyNotEmptyException)7 StudyNotFoundException (org.dcm4chee.arc.delete.StudyNotFoundException)7 DateTimeParseException (java.time.format.DateTimeParseException)6 NoResultException (javax.persistence.NoResultException)6 ApplicationEntity (org.dcm4che3.net.ApplicationEntity)6 Patient (org.dcm4chee.arc.entity.Patient)6 Inject (javax.inject.Inject)5 QueryContext (org.dcm4chee.arc.query.QueryContext)5 IOException (java.io.IOException)4