/**
  * Gets the document as input stream.
  *
  * @param docEntry the doc entry
  * @return the document as input stream
  */
 private InputStream getDocumentAsInputStream(DocumentEntryType docEntry) {
   DocumentRequest documentRequest =
       new DocumentRequest(
           docEntry.getRepositoryUniqueId(),
           affinityDomain.getRepositoryDestination().getUri(),
           docEntry.getEntryUUID());
   ConvenienceCommunicationCh convComm = new ConvenienceCommunicationCh(affinityDomain);
   XDSRetrieveResponseType rrt = convComm.retrieveDocument(documentRequest);
   try {
     if ((rrt.getErrorList() != null)) {
       logger.error(
           "error retriveing doc "
               + docEntry.getEntryUUID()
               + " - "
               + rrt.getErrorList().getHighestSeverity().getName());
     }
     if ((rrt.getAttachments() == null) || rrt.getAttachments().size() != 1) {
       logger.error("document not downloaded or more than one");
       return null;
     }
     return rrt.getAttachments().get(0).getStream();
   } finally {
     convComm.clearDocuments();
   }
 }
 @Override
 public List<CdaChVacd> getDocuments(org.ehealth_connector.common.Patient ehcPatient) {
   List<CdaChVacd> ret = new ArrayList<>();
   List<DocumentEntryType> entryTypes = getAllPatientDocumentEntryTypes(ehcPatient);
   try {
     for (DocumentEntryType documentEntryType : entryTypes) {
       if (documentEntryType.getAvailabilityStatus() != null
           && documentEntryType.getAvailabilityStatus()
               == AvailabilityStatusType.APPROVED_LITERAL) {
         if ("text/xml".equals(documentEntryType.getMimeType())) {
           InputStream documentStream = getDocumentAsInputStream(documentEntryType);
           if (documentStream != null) {
             Optional<CdaChVacd> vacdocOpt = vacdocService.loadVacdocDocument(documentStream);
             vacdocOpt.ifPresent(d -> ret.add(d));
           }
         }
       }
     }
   } catch (Exception e) {
     logger.error("Could not load CdaChVacd", e);
     e.printStackTrace(System.err);
   }
   return ret;
 }