comparison Samples/FHIR/src/main/java/PatientProvider.java @ 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 8d876a4f541b
children 1c407ba1d311
comparison
equal deleted inserted replaced
13:d7a55838d821 14:0dc05fe76bd5
1 /** 1 /**
2 * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium 2 * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
3 * SPDX-License-Identifier: GPL-3.0-or-later 3 * SPDX-License-Identifier: GPL-3.0-or-later
4 */ 4 **/
5 5
6 /** 6 /**
7 * Java plugin for Orthanc 7 * Java plugin for Orthanc
8 * Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium 8 * Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium
9 * 9 *
21 * along with this program. If not, see <http://www.gnu.org/licenses/>. 21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 **/ 22 **/
23 23
24 24
25 import be.uclouvain.orthanc.ResourceType; 25 import be.uclouvain.orthanc.ResourceType;
26 import ca.uhn.fhir.rest.annotation.IdParam; 26 import ca.uhn.fhir.rest.annotation.*;
27 import ca.uhn.fhir.rest.annotation.OptionalParam;
28 import ca.uhn.fhir.rest.annotation.Read;
29 import ca.uhn.fhir.rest.annotation.Search;
30 import ca.uhn.fhir.rest.param.DateParam; 27 import ca.uhn.fhir.rest.param.DateParam;
31 import ca.uhn.fhir.rest.param.StringParam; 28 import ca.uhn.fhir.rest.param.StringParam;
32 import ca.uhn.fhir.rest.server.IResourceProvider; 29 import ca.uhn.fhir.rest.server.IResourceProvider;
33 import org.hl7.fhir.r5.model.IdType; 30 import org.hl7.fhir.r5.model.IdType;
34 import org.hl7.fhir.r5.model.Patient; 31 import org.hl7.fhir.r5.model.Patient;
67 64
68 @Search() 65 @Search()
69 public List<Patient> getPatients(@OptionalParam(name = Patient.SP_FAMILY) StringParam theFamilyName, 66 public List<Patient> getPatients(@OptionalParam(name = Patient.SP_FAMILY) StringParam theFamilyName,
70 @OptionalParam(name = Patient.SP_GIVEN) StringParam theGivenName, 67 @OptionalParam(name = Patient.SP_GIVEN) StringParam theGivenName,
71 @OptionalParam(name = Patient.SP_IDENTIFIER) StringParam theIdentifier, 68 @OptionalParam(name = Patient.SP_IDENTIFIER) StringParam theIdentifier,
72 @OptionalParam(name = Patient.SP_BIRTHDATE) DateParam theBirthDate) { 69 @OptionalParam(name = Patient.SP_BIRTHDATE) DateParam theBirthDate,
70 @Offset Integer theOffset,
71 @Count Integer theCount) {
73 Map<String, String> tags = new HashMap<>(); 72 Map<String, String> tags = new HashMap<>();
74 73
75 if (theFamilyName != null && 74 if (theFamilyName != null &&
76 theGivenName != null) { 75 theGivenName != null) {
77 tags.put(Toolbox.TAG_PATIENT_NAME, "*" + theFamilyName.getValue() + "*" + theGivenName.getValue() + "*"); 76 tags.put(Toolbox.TAG_PATIENT_NAME, "*" + theFamilyName.getValue() + "*" + theGivenName.getValue() + "*");
87 86
88 if (theBirthDate != null) { 87 if (theBirthDate != null) {
89 tags.put(Toolbox.TAG_PATIENT_BIRTH_DATE, Toolbox.formatDicomDate(theBirthDate.getValue())); 88 tags.put(Toolbox.TAG_PATIENT_BIRTH_DATE, Toolbox.formatDicomDate(theBirthDate.getValue()));
90 } 89 }
91 90
92 List<OrthancResource> resources = OrthancResource.find(orthanc, ResourceType.PATIENT, tags, false); 91 final boolean caseSensitive = false;
92
93 List<OrthancResource> resources;
94
95 if (theOffset != null &&
96 theCount != null) {
97 resources = OrthancResource.find(orthanc, ResourceType.PATIENT, tags, caseSensitive, theOffset.intValue(), theCount.intValue());
98 } else if (theCount != null) {
99 resources = OrthancResource.find(orthanc, ResourceType.PATIENT, tags, caseSensitive, 0, theCount.intValue());
100 } else {
101 resources = OrthancResource.find(orthanc, ResourceType.PATIENT, tags, caseSensitive);
102 }
93 103
94 List<Patient> patients = new ArrayList<>(); 104 List<Patient> patients = new ArrayList<>();
95 for (OrthancResource resource : resources) { 105 for (OrthancResource resource : resources) {
96 Patient patient = resource.getFhirPatient(); 106 Patient patient = resource.getFhirPatient();
97 if (patient.hasId()) { 107 if (patient.hasId()) {