changeset 297:64d1ddab8246

Improved PDF creation Pwsh snippet + added Dicom instance upload example with Pwsh + added Windows docker script to generate book
author Benjamin Golinvaux <bgo@osimis.io>
date Mon, 20 Jan 2020 14:43:22 +0100
parents b4b9ceebe64d
children d9adeb40333d
files Sphinx/buildWithDocker.ps1 Sphinx/source/users/advanced-rest.rst Sphinx/source/users/rest.rst
diffstat 3 files changed, 33 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Sphinx/buildWithDocker.ps1	Mon Jan 20 14:43:22 2020 +0100
@@ -0,0 +1,9 @@
+# This has been tested with Docker for Windows CE version 2.0.0.2 (30215)
+# on Windows 10 Pro x64 (10.0.17134) with stock Powershell (5.1)
+
+docker build -t orthanc-book-builder .
+
+$pwdSlash = $pwd.Path.Replace("\","/")
+docker run --rm -v "$($pwdSlash):/app" orthanc-book-builder
+
+docker rmi orthanc-book-builder  # since we rebuild it anyway, no need to keep it -> don't accumulate <none> images
--- a/Sphinx/source/users/advanced-rest.rst	Tue Jan 07 08:37:15 2020 +0100
+++ b/Sphinx/source/users/advanced-rest.rst	Mon Jan 20 14:43:22 2020 +0100
@@ -164,9 +164,9 @@
 They convert the ``HelloWorld2.pdf`` file to base64, then perform a
 ``POST`` request with JSON data containing the converted payload.
 
-.. highlight:: bash
+Using bash:
 
-Using bash::
+.. code-block:: bash
 
     # create the json data, with the BASE64 data embedded in it
     (echo -n '{"Tags" : {"PatientName" : "Benjamino", "Modality" : "CT"},"Content" : "data:application/pdf;base64,'; base64 HelloWorld2.pdf; echo '"}') > /tmp/foo
@@ -174,9 +174,10 @@
     # upload it to Orthanc
     cat /tmp/foo | curl -H "Content-Type: application/json" -d @- http://localhost:8042/tools/create-dicom
 
-.. highlight:: powershell
 
-Using Powershell::
+Using powershell:
+
+.. code-block:: perl
 
     # create the BASE64 string data
     $fileInBase64 = $([Convert]::ToBase64String((gc -Path "HelloWorld2.pdf" -Encoding Byte)))
@@ -184,8 +185,11 @@
     # create the json data
     $params = @{Tags = @{PatientName = "Benjamino";Modality = "CT"};Content= "data:application/pdf;base64,$fileInBase64"}
 
-    # upload it to Orthanc and convert the result to json
-    $reply = Invoke-WebRequest -Uri http://localhost:8042/tools/create-dicom -Method POST -Body ($params|ConvertTo-Json) -ContentType "application/json" | ConvertFrom-Json
+    # disabling progress bar tremendously increases the Invoke-RestMethod call
+    $ProgressPreference = 'SilentlyContinue'
+
+    # upload it to Orthanc
+    $reply = Invoke-RestMethod http://localhost:8042/tools/create-dicom -Method POST -Body ($params|ConvertTo-Json) -ContentType 'application/json'
 
     # display the result
     Write-Host "The instance can be retrieved in PDF at http://localhost:8042$($reply.Path)/pdf"
--- a/Sphinx/source/users/rest.rst	Tue Jan 07 08:37:15 2020 +0100
+++ b/Sphinx/source/users/rest.rst	Mon Jan 20 14:43:22 2020 +0100
@@ -64,6 +64,20 @@
     $ python ImportDicomFiles.py localhost 8042 ~/DICOM/
 
 
+.. highlight:: perl
+
+If you are using Powershell (>= 3.0), you can use the following to send a single
+Dicom instance to Orthanc::
+
+    # disabling progress bar tremendously increases the Invoke-RestMethod call
+    $ProgressPreference = 'SilentlyContinue'
+
+    # upload it to Orthanc
+    $reply = Invoke-RestMethod http://localhost:8042/instances -Method POST -InFile CT.X.1.2.276.0.7230010.dcm
+
+    # display the result
+    Write-Host "The instance can be retrieved at http://localhost:8042$($reply.Path)"
+
 .. _rest-access:
 
 Accessing the content of Orthanc