private DicomObject doNCreate(DicomObject rq, DicomObject data, DicomObject rsp)
     throws DicomServiceException {
   String iuid = rq.getString(Tag.AffectedSOPInstanceUID);
   if (iuid == null) iuid = rsp.getString(Tag.AffectedSOPInstanceUID);
   File f = mkFile(iuid);
   if (f.exists()) {
     throw new DicomServiceException(rq, Status.DuplicateSOPinstance);
   }
   data.initFileMetaInformation(
       UID.ModalityPerformedProcedureStepSOPClass, iuid, UID.ExplicitVRLittleEndian);
   try {
     store(f, data);
     try {
       Context.openSession();
       DicomUtils.updateStudyPerformedStatusByMpps(data);
     } catch (Exception e) {
       debug("Can not update database with");
       debug(data.toString());
       e.printStackTrace();
     } finally {
       Context.closeSession();
     }
   } catch (Exception e) {
     throw new DicomServiceException(rq, Status.ProcessingFailure);
   }
   return null;
 }
 private DicomObject doNSet(DicomObject rq, DicomObject data) throws DicomServiceException {
   final String iuid = rq.getString(Tag.RequestedSOPInstanceUID);
   File f = mkFile(iuid);
   if (!f.exists()) {
     throw new DicomServiceException(rq, Status.NoSuchObjectInstance, iuid);
   }
   try {
     DicomObject mpps = dcmOF.load(f);
     String status = mpps.getString(Tag.PerformedProcedureStepStatus);
     if (!"IN PROGRESS".equals(status)) {
       DicomServiceException ex =
           new DicomServiceException(
               rq,
               Status.ProcessingFailure,
               "Performed Procedure Step Object may no longer be updated");
       ex.setErrorID(0xA710);
       throw ex;
     }
     data.copyTo(mpps);
     store(f, mpps);
     try {
       Context.openSession();
       DicomUtils.updateStudyPerformedStatusByMpps(mpps);
     } catch (Exception e) {
       debug("Can not update database with");
       debug(mpps.toString());
       e.printStackTrace();
     } finally {
       Context.closeSession();
     }
   } catch (DicomServiceException e) {
     throw e;
   } catch (Exception e) {
     throw new DicomServiceException(rq, Status.ProcessingFailure, e.getMessage());
   }
   return null;
 }