changeset 14:0dc05fe76bd5

implemented paging in Patient and ImagingStudy resources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 21 Oct 2023 16:41:59 +0200
parents d7a55838d821
children b69bc09e2969
files Samples/FHIR/src/main/java/EndpointProvider.java Samples/FHIR/src/main/java/FhirConfiguration.java Samples/FHIR/src/main/java/FhirRequestHandler.java Samples/FHIR/src/main/java/IOrthancConnection.java Samples/FHIR/src/main/java/ImagingStudyProvider.java Samples/FHIR/src/main/java/Main.java Samples/FHIR/src/main/java/OrthancPluginConnection.java Samples/FHIR/src/main/java/OrthancResource.java Samples/FHIR/src/main/java/PatientProvider.java Samples/FHIR/src/main/java/Toolbox.java
diffstat 10 files changed, 70 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/Samples/FHIR/src/main/java/EndpointProvider.java	Sat Oct 21 10:41:01 2023 +0200
+++ b/Samples/FHIR/src/main/java/EndpointProvider.java	Sat Oct 21 16:41:59 2023 +0200
@@ -1,7 +1,7 @@
 /**
  * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
  * SPDX-License-Identifier: GPL-3.0-or-later
- */
+ **/
 
 /**
  * Java plugin for Orthanc
--- a/Samples/FHIR/src/main/java/FhirConfiguration.java	Sat Oct 21 10:41:01 2023 +0200
+++ b/Samples/FHIR/src/main/java/FhirConfiguration.java	Sat Oct 21 16:41:59 2023 +0200
@@ -1,7 +1,7 @@
 /**
  * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
  * SPDX-License-Identifier: GPL-3.0-or-later
- */
+ **/
 
 /**
  * Java plugin for Orthanc
--- a/Samples/FHIR/src/main/java/FhirRequestHandler.java	Sat Oct 21 10:41:01 2023 +0200
+++ b/Samples/FHIR/src/main/java/FhirRequestHandler.java	Sat Oct 21 16:41:59 2023 +0200
@@ -1,7 +1,7 @@
 /**
  * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
  * SPDX-License-Identifier: GPL-3.0-or-later
- */
+ **/
 
 /**
  * Java plugin for Orthanc
--- a/Samples/FHIR/src/main/java/IOrthancConnection.java	Sat Oct 21 10:41:01 2023 +0200
+++ b/Samples/FHIR/src/main/java/IOrthancConnection.java	Sat Oct 21 16:41:59 2023 +0200
@@ -1,7 +1,7 @@
 /**
  * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
  * SPDX-License-Identifier: GPL-3.0-or-later
- */
+ **/
 
 /**
  * Java plugin for Orthanc
--- a/Samples/FHIR/src/main/java/ImagingStudyProvider.java	Sat Oct 21 10:41:01 2023 +0200
+++ b/Samples/FHIR/src/main/java/ImagingStudyProvider.java	Sat Oct 21 16:41:59 2023 +0200
@@ -1,7 +1,7 @@
 /**
  * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
  * SPDX-License-Identifier: GPL-3.0-or-later
- */
+ **/
 
 /**
  * Java plugin for Orthanc
@@ -22,10 +22,8 @@
  **/
 
 
-import ca.uhn.fhir.rest.annotation.IdParam;
-import ca.uhn.fhir.rest.annotation.OptionalParam;
-import ca.uhn.fhir.rest.annotation.Read;
-import ca.uhn.fhir.rest.annotation.Search;
+import be.uclouvain.orthanc.ResourceType;
+import ca.uhn.fhir.rest.annotation.*;
 import ca.uhn.fhir.rest.param.ReferenceParam;
 import ca.uhn.fhir.rest.param.StringParam;
 import ca.uhn.fhir.rest.server.IResourceProvider;
@@ -67,7 +65,9 @@
 
     @Search()
     public List<ImagingStudy> getImagingStudies(@OptionalParam(name = ImagingStudy.SP_IDENTIFIER) StringParam theIdentifier,
-                                                @OptionalParam(name = ImagingStudy.SP_SUBJECT) ReferenceParam theSubject) {
+                                                @OptionalParam(name = ImagingStudy.SP_SUBJECT) ReferenceParam theSubject,
+                                                @Offset Integer theOffset,
+                                                @Count Integer theCount) {
         Map<String, String> tags = new HashMap<>();
 
         if (theIdentifier != null) {
@@ -79,7 +79,18 @@
             tags.put(Toolbox.TAG_PATIENT_ID, theSubject.getValue());
         }
 
-        List<OrthancResource> resources = OrthancResource.find(orthanc, be.uclouvain.orthanc.ResourceType.STUDY, tags, false);
+        final boolean caseSensitive = false;
+
+        List<OrthancResource> resources;
+
+        if (theOffset != null &&
+                theCount != null) {
+            resources = OrthancResource.find(orthanc, ResourceType.STUDY, tags, caseSensitive, theOffset.intValue(), theCount.intValue());
+        } else if (theCount != null) {
+            resources = OrthancResource.find(orthanc, ResourceType.STUDY, tags, caseSensitive, 0, theCount.intValue());
+        } else {
+            resources = OrthancResource.find(orthanc, ResourceType.STUDY, tags, false);
+        }
 
         List<ImagingStudy> studies = new ArrayList<>();
         for (OrthancResource resource : resources) {
--- a/Samples/FHIR/src/main/java/Main.java	Sat Oct 21 10:41:01 2023 +0200
+++ b/Samples/FHIR/src/main/java/Main.java	Sat Oct 21 16:41:59 2023 +0200
@@ -1,7 +1,7 @@
 /**
  * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
  * SPDX-License-Identifier: GPL-3.0-or-later
- */
+ **/
 
 /**
  * Java plugin for Orthanc
--- a/Samples/FHIR/src/main/java/OrthancPluginConnection.java	Sat Oct 21 10:41:01 2023 +0200
+++ b/Samples/FHIR/src/main/java/OrthancPluginConnection.java	Sat Oct 21 16:41:59 2023 +0200
@@ -1,7 +1,7 @@
 /**
  * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
  * SPDX-License-Identifier: GPL-3.0-or-later
- */
+ **/
 
 /**
  * Java plugin for Orthanc
--- a/Samples/FHIR/src/main/java/OrthancResource.java	Sat Oct 21 10:41:01 2023 +0200
+++ b/Samples/FHIR/src/main/java/OrthancResource.java	Sat Oct 21 16:41:59 2023 +0200
@@ -1,7 +1,7 @@
 /**
  * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
  * SPDX-License-Identifier: GPL-3.0-or-later
- */
+ **/
 
 /**
  * Java plugin for Orthanc
@@ -119,10 +119,13 @@
         }
     }
 
-    public static List<OrthancResource> find(IOrthancConnection connection,
-                                             ResourceType type,
-                                             Map<String, String> tags,
-                                             boolean caseSensitive) {
+    private static List<OrthancResource> find(IOrthancConnection connection,
+                                              ResourceType type,
+                                              Map<String, String> tags,
+                                              boolean caseSensitive,
+                                              boolean hasPaging,
+                                              int since,
+                                              int limit) {
         JSONObject query = new JSONObject();
         for (Map.Entry<String, String> entry : tags.entrySet()) {
             query.put(entry.getKey(), entry.getValue());
@@ -134,6 +137,11 @@
         request.put("Short", true);
         request.put("CaseSensitive", caseSensitive);
 
+        if (hasPaging) {
+            request.put("Since", since);
+            request.put("Limit", limit);
+        }
+
         switch (type) {
             case PATIENT:
                 request.put("Level", "Patient");
@@ -163,6 +171,21 @@
         return result;
     }
 
+    public static List<OrthancResource> find(IOrthancConnection connection,
+                                             ResourceType type,
+                                             Map<String, String> tags,
+                                             boolean caseSensitive,
+                                             int since,
+                                             int limit) {
+        return find(connection, type, tags, caseSensitive, true, since, limit);
+    }
+
+    public static List<OrthancResource> find(IOrthancConnection connection,
+                                             ResourceType type,
+                                             Map<String, String> tags,
+                                             boolean caseSensitive) {
+        return find(connection, type, tags, caseSensitive, false, 0, 0);
+    }
 
     public Patient getFhirPatient() {
         if (type != ResourceType.PATIENT) {
--- a/Samples/FHIR/src/main/java/PatientProvider.java	Sat Oct 21 10:41:01 2023 +0200
+++ b/Samples/FHIR/src/main/java/PatientProvider.java	Sat Oct 21 16:41:59 2023 +0200
@@ -1,7 +1,7 @@
 /**
  * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
  * SPDX-License-Identifier: GPL-3.0-or-later
- */
+ **/
 
 /**
  * Java plugin for Orthanc
@@ -23,10 +23,7 @@
 
 
 import be.uclouvain.orthanc.ResourceType;
-import ca.uhn.fhir.rest.annotation.IdParam;
-import ca.uhn.fhir.rest.annotation.OptionalParam;
-import ca.uhn.fhir.rest.annotation.Read;
-import ca.uhn.fhir.rest.annotation.Search;
+import ca.uhn.fhir.rest.annotation.*;
 import ca.uhn.fhir.rest.param.DateParam;
 import ca.uhn.fhir.rest.param.StringParam;
 import ca.uhn.fhir.rest.server.IResourceProvider;
@@ -69,7 +66,9 @@
     public List<Patient> getPatients(@OptionalParam(name = Patient.SP_FAMILY) StringParam theFamilyName,
                                      @OptionalParam(name = Patient.SP_GIVEN) StringParam theGivenName,
                                      @OptionalParam(name = Patient.SP_IDENTIFIER) StringParam theIdentifier,
-                                     @OptionalParam(name = Patient.SP_BIRTHDATE) DateParam theBirthDate) {
+                                     @OptionalParam(name = Patient.SP_BIRTHDATE) DateParam theBirthDate,
+                                     @Offset Integer theOffset,
+                                     @Count Integer theCount) {
         Map<String, String> tags = new HashMap<>();
 
         if (theFamilyName != null &&
@@ -89,7 +88,18 @@
             tags.put(Toolbox.TAG_PATIENT_BIRTH_DATE, Toolbox.formatDicomDate(theBirthDate.getValue()));
         }
 
-        List<OrthancResource> resources = OrthancResource.find(orthanc, ResourceType.PATIENT, tags, false);
+        final boolean caseSensitive = false;
+
+        List<OrthancResource> resources;
+
+        if (theOffset != null &&
+                theCount != null) {
+            resources = OrthancResource.find(orthanc, ResourceType.PATIENT, tags, caseSensitive, theOffset.intValue(), theCount.intValue());
+        } else if (theCount != null) {
+            resources = OrthancResource.find(orthanc, ResourceType.PATIENT, tags, caseSensitive, 0, theCount.intValue());
+        } else {
+            resources = OrthancResource.find(orthanc, ResourceType.PATIENT, tags, caseSensitive);
+        }
 
         List<Patient> patients = new ArrayList<>();
         for (OrthancResource resource : resources) {
--- a/Samples/FHIR/src/main/java/Toolbox.java	Sat Oct 21 10:41:01 2023 +0200
+++ b/Samples/FHIR/src/main/java/Toolbox.java	Sat Oct 21 16:41:59 2023 +0200
@@ -1,7 +1,7 @@
 /**
  * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
  * SPDX-License-Identifier: GPL-3.0-or-later
- */
+ **/
 
 /**
  * Java plugin for Orthanc