Skip to content

Commit

Permalink
Fix dcm4che#458 dcm4che/dcm4chee-arc-light : Sychronize another archi…
Browse files Browse the repository at this point in the history
…ve instances with local changes by IOCM-RS
  • Loading branch information
vrindanayak committed Nov 25, 2016
1 parent 4c280d6 commit 1948891
Showing 1 changed file with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,7 @@ public void deleteStudy(@PathParam("StudyUID") String studyUID) throws Exception
public String createPatient(InputStream in) throws Exception {
logRequest();
try {
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
TeeInputStream tIn = new TeeInputStream(in, bOut);

JSONReader reader = new JSONReader(Json.createParser(new InputStreamReader(tIn, "UTF-8")));
JSONReader reader = new JSONReader(Json.createParser(new InputStreamReader(in, "UTF-8")));
Attributes attrs = reader.readDataset(null);
if (attrs.containsValue(Tag.PatientID))
throw new WebApplicationException(getResponse("Patient ID in message body", Response.Status.BAD_REQUEST));
Expand All @@ -232,11 +229,31 @@ public String createPatient(InputStream in) throws Exception {
ctx.setAttributes(attrs);
ctx.setAttributeUpdatePolicy(Attributes.UpdatePolicy.REPLACE);
patientService.updatePatient(ctx);
forwardRS("PUT", RSOperation.CreatePatient, null, bOut.toByteArray(), IDWithIssuer.pidOf(attrs).toString());
forwardRS("PUT", RSOperation.CreatePatient, null,
getByteArrayOutStream(attrs).toByteArray(), IDWithIssuer.pidOf(attrs).toString());
return IDWithIssuer.pidOf(attrs).toString();
} catch (JsonParsingException e) {
throw new WebApplicationException(
getResponse(e.getMessage() + " at location : " + e.getLocation(), Response.Status.INTERNAL_SERVER_ERROR));
} catch (IOException e) {
throw new WebApplicationException(getResponse(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR));
}
}

private ByteArrayOutputStream getByteArrayOutStream(Attributes attrs) {
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
try {
(new StreamingOutput() {
@Override
public void write(OutputStream out) throws IOException {
JsonGenerator gen = Json.createGenerator(out);
new JSONWriter(gen).write(attrs);
gen.flush();
}
}).write(bOut);
return bOut;
} catch (IOException e) {
throw new WebApplicationException(getResponse(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR));
}
}

Expand Down Expand Up @@ -278,8 +295,8 @@ public void updatePatient(@PathParam("PatientID") IDWithIssuer patientID, InputS
public StreamingOutput updateStudy(InputStream in) throws Exception {
logRequest();
try {
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
TeeInputStream tIn = new TeeInputStream(in, bOut);
ByteArrayOutputStream bOutStream = new ByteArrayOutputStream();
TeeInputStream tIn = new TeeInputStream(in, bOutStream);

JSONReader reader = new JSONReader(Json.createParser(new InputStreamReader(tIn, "UTF-8")));
final Attributes attrs = reader.readDataset(null);
Expand All @@ -292,14 +309,16 @@ public StreamingOutput updateStudy(InputStream in) throws Exception {
throw new WebApplicationException(getResponse("Patient[id=" + patientID + "] does not exists",
Response.Status.NOT_FOUND));

if (!attrs.containsValue(Tag.StudyInstanceUID))
boolean studyIUIDPresent = attrs.containsValue(Tag.StudyInstanceUID);
if (!studyIUIDPresent)
attrs.setString(Tag.StudyInstanceUID, VR.UI, UIDUtils.createUID());

StudyMgtContext ctx = studyService.createStudyMgtContextWEB(request, getApplicationEntity());
ctx.setPatient(patient);
ctx.setAttributes(attrs);
studyService.updateStudy(ctx);
forwardRS("POST", RSOperation.UpdateStudy, null, bOut.toByteArray(), null);
byte[] bOut = studyIUIDPresent ? bOutStream.toByteArray() : getByteArrayOutStream(attrs).toByteArray();
forwardRS("POST", RSOperation.UpdateStudy, null, bOut, null);
return new StreamingOutput() {
@Override
public void write(OutputStream out) throws IOException {
Expand Down

0 comments on commit 1948891

Please sign in to comment.