Mercurial > hg > orthanc-java
comparison Samples/FHIR/src/main/java/PatientProvider.java @ 11:8d876a4f541b
added sample FHIR server
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 21 Oct 2023 09:53:25 +0200 |
parents | |
children | 0dc05fe76bd5 |
comparison
equal
deleted
inserted
replaced
10:6b9433432ee0 | 11:8d876a4f541b |
---|---|
1 /** | |
2 * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium | |
3 * SPDX-License-Identifier: GPL-3.0-or-later | |
4 */ | |
5 | |
6 /** | |
7 * Java plugin for Orthanc | |
8 * Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium | |
9 * | |
10 * This program is free software: you can redistribute it and/or | |
11 * modify it under the terms of the GNU General Public License as | |
12 * published by the Free Software Foundation, either version 3 of the | |
13 * License, or (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, but | |
16 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 * General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
22 **/ | |
23 | |
24 | |
25 import be.uclouvain.orthanc.ResourceType; | |
26 import ca.uhn.fhir.rest.annotation.IdParam; | |
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; | |
31 import ca.uhn.fhir.rest.param.StringParam; | |
32 import ca.uhn.fhir.rest.server.IResourceProvider; | |
33 import org.hl7.fhir.r5.model.IdType; | |
34 import org.hl7.fhir.r5.model.Patient; | |
35 | |
36 import java.util.ArrayList; | |
37 import java.util.HashMap; | |
38 import java.util.List; | |
39 import java.util.Map; | |
40 | |
41 public class PatientProvider implements IResourceProvider { | |
42 private IOrthancConnection orthanc; | |
43 | |
44 PatientProvider(IOrthancConnection orthanc) { | |
45 this.orthanc = orthanc; | |
46 } | |
47 | |
48 @Override | |
49 public Class<Patient> getResourceType() { | |
50 return Patient.class; | |
51 } | |
52 | |
53 @Read() | |
54 public Patient getResourceById(@IdParam IdType theId) { | |
55 Map<String, String> tags = new HashMap<>(); | |
56 tags.put(Toolbox.TAG_PATIENT_ID, theId.getIdPart()); | |
57 | |
58 List<OrthancResource> resources = OrthancResource.find(orthanc, ResourceType.PATIENT, tags, true); | |
59 if (resources.size() == 0) { | |
60 return null; | |
61 } else if (resources.size() > 1) { | |
62 throw new RuntimeException("Too many matching resources"); | |
63 } else { | |
64 return resources.get(0).getFhirPatient(); | |
65 } | |
66 } | |
67 | |
68 @Search() | |
69 public List<Patient> getPatients(@OptionalParam(name = Patient.SP_FAMILY) StringParam theFamilyName, | |
70 @OptionalParam(name = Patient.SP_GIVEN) StringParam theGivenName, | |
71 @OptionalParam(name = Patient.SP_IDENTIFIER) StringParam theIdentifier, | |
72 @OptionalParam(name = Patient.SP_BIRTHDATE) DateParam theBirthDate) { | |
73 Map<String, String> tags = new HashMap<>(); | |
74 | |
75 if (theFamilyName != null && | |
76 theGivenName != null) { | |
77 tags.put(Toolbox.TAG_PATIENT_NAME, "*" + theFamilyName.getValue() + "*" + theGivenName.getValue() + "*"); | |
78 } else if (theFamilyName != null) { | |
79 tags.put(Toolbox.TAG_PATIENT_NAME, "*" + theFamilyName.getValue() + "*"); | |
80 } else if (theGivenName != null) { | |
81 tags.put(Toolbox.TAG_PATIENT_NAME, "*" + theGivenName.getValue() + "*"); | |
82 } | |
83 | |
84 if (theIdentifier != null) { | |
85 tags.put(Toolbox.TAG_PATIENT_ID, theIdentifier.getValue()); | |
86 } | |
87 | |
88 if (theBirthDate != null) { | |
89 tags.put(Toolbox.TAG_PATIENT_BIRTH_DATE, Toolbox.formatDicomDate(theBirthDate.getValue())); | |
90 } | |
91 | |
92 List<OrthancResource> resources = OrthancResource.find(orthanc, ResourceType.PATIENT, tags, false); | |
93 | |
94 List<Patient> patients = new ArrayList<>(); | |
95 for (OrthancResource resource : resources) { | |
96 Patient patient = resource.getFhirPatient(); | |
97 if (patient.hasId()) { | |
98 patients.add(patient); | |
99 } | |
100 } | |
101 | |
102 return patients; | |
103 } | |
104 } |