Search in sources :

Example 1 with RSOperation

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

the class PamRS method updatePatient.

@PUT
@Path("/patients/{priorPatientID}")
@Consumes("application/dicom+json,application/json")
public void updatePatient(@PathParam("priorPatientID") IDWithIssuer priorPatientID, @QueryParam("merge") @Pattern(regexp = "true|false") @DefaultValue("false") String merge, InputStream in) {
    ArchiveAEExtension arcAE = getArchiveAE();
    PatientMgtContext ctx = patientMgtCtx(in);
    ctx.setArchiveAEExtension(arcAE);
    IDWithIssuer targetPatientID = ctx.getPatientID();
    if (targetPatientID == null)
        throw new WebApplicationException(errResponse("missing Patient ID in message body", Response.Status.BAD_REQUEST));
    boolean mergePatients = Boolean.parseBoolean(merge);
    boolean patientMatch = priorPatientID.equals(targetPatientID);
    if (patientMatch && mergePatients)
        throw new WebApplicationException(errResponse("Circular Merge of Patients not allowed.", Response.Status.BAD_REQUEST));
    RSOperation rsOp = RSOperation.CreatePatient;
    String msgType = "ADT^A28^ADT_A05";
    try {
        if (patientMatch) {
            patientService.updatePatient(ctx);
            if (ctx.getEventActionCode().equals(AuditMessages.EventActionCode.Update)) {
                rsOp = RSOperation.UpdatePatient;
                msgType = "ADT^A31^ADT_A05";
            }
        } else {
            ctx.setPreviousAttributes(priorPatientID.exportPatientIDWithIssuer(null));
            if (mergePatients) {
                msgType = "ADT^A40^ADT_A39";
                rsOp = RSOperation.MergePatient2;
                patientService.mergePatient(ctx);
            } else {
                msgType = "ADT^A47^ADT_A30";
                rsOp = RSOperation.ChangePatientID2;
                patientService.changePatientID(ctx);
            }
        }
        if (ctx.getEventActionCode().equals(AuditMessages.EventActionCode.Read))
            return;
        rsForward.forward(rsOp, arcAE, ctx.getAttributes(), request);
        notifyHL7Receivers(msgType, ctx);
    } catch (PatientAlreadyExistsException | NonUniquePatientException | PatientTrackingNotAllowedException | CircularPatientMergeException e) {
        throw new WebApplicationException(errResponse(e.getMessage(), Response.Status.CONFLICT));
    } catch (PatientMergedException 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) SAXException(org.xml.sax.SAXException) JsonParsingException(javax.json.stream.JsonParsingException) ConfigurationException(org.dcm4che3.conf.api.ConfigurationException) DicomServiceException(org.dcm4che3.net.service.DicomServiceException) ConfigurationNotFoundException(org.dcm4che3.conf.api.ConfigurationNotFoundException) ConnectException(java.net.ConnectException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) RSOperation(org.dcm4chee.arc.conf.RSOperation)

Example 2 with RSOperation

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

the class RSClientImpl method request.

@Override
public Outcome request(String rsOp, String requestURI, String requestQueryString, String webAppName, String patientID, boolean tlsAllowAnyHostname, boolean tlsDisableTrustManager, byte[] content) throws Exception {
    RSOperation rsOperation = RSOperation.valueOf(rsOp);
    WebApplication webApplication;
    Task.Status status = Task.Status.WARNING;
    try {
        webApplication = iWebAppCache.findWebApplication(webAppName);
    } catch (Exception e) {
        LOG.warn(e.getMessage());
        return new Outcome(status, "No such Web Application found: " + webAppName);
    }
    String targetURI = targetURI(rsOperation, requestURI, webApplication, patientID);
    if (targetURI == null)
        return new Outcome(status, "Target URL not available.");
    if (targetURI.equals(requestURI))
        return new Outcome(status, "Target URL same as Source Request URL!");
    if (requestQueryString != null)
        targetURI += "?" + requestQueryString;
    Response response = toResponse(getMethod(rsOperation), targetURI, tlsAllowAnyHostname, tlsDisableTrustManager, content, accessTokenFromWebApp(webApplication));
    Outcome outcome = buildOutcome(Response.Status.fromStatusCode(response.getStatus()), response.getStatusInfo());
    response.close();
    return outcome;
}
Also used : Response(javax.ws.rs.core.Response) Task(org.dcm4chee.arc.entity.Task) Outcome(org.dcm4chee.arc.qmgt.Outcome) RSOperation(org.dcm4chee.arc.conf.RSOperation) WebApplication(org.dcm4che3.net.WebApplication)

Aggregations

RSOperation (org.dcm4chee.arc.conf.RSOperation)2 ConnectException (java.net.ConnectException)1 JsonParsingException (javax.json.stream.JsonParsingException)1 Response (javax.ws.rs.core.Response)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 ConfigurationException (org.dcm4che3.conf.api.ConfigurationException)1 ConfigurationNotFoundException (org.dcm4che3.conf.api.ConfigurationNotFoundException)1 WebApplication (org.dcm4che3.net.WebApplication)1 DicomServiceException (org.dcm4che3.net.service.DicomServiceException)1 ArchiveAEExtension (org.dcm4chee.arc.conf.ArchiveAEExtension)1 Task (org.dcm4chee.arc.entity.Task)1 Outcome (org.dcm4chee.arc.qmgt.Outcome)1 SAXException (org.xml.sax.SAXException)1