Mercurial > hg > orthanc-java
comparison Samples/FHIR/src/main/java/ImagingStudyProvider.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 ca.uhn.fhir.rest.annotation.IdParam; | |
26 import ca.uhn.fhir.rest.annotation.OptionalParam; | |
27 import ca.uhn.fhir.rest.annotation.Read; | |
28 import ca.uhn.fhir.rest.annotation.Search; | |
29 import ca.uhn.fhir.rest.param.ReferenceParam; | |
30 import ca.uhn.fhir.rest.param.StringParam; | |
31 import ca.uhn.fhir.rest.server.IResourceProvider; | |
32 import org.hl7.fhir.r5.model.IdType; | |
33 import org.hl7.fhir.r5.model.ImagingStudy; | |
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 ImagingStudyProvider implements IResourceProvider { | |
42 private IOrthancConnection orthanc; | |
43 | |
44 ImagingStudyProvider(IOrthancConnection orthanc) { | |
45 this.orthanc = orthanc; | |
46 } | |
47 | |
48 @Override | |
49 public Class<ImagingStudy> getResourceType() { | |
50 return ImagingStudy.class; | |
51 } | |
52 | |
53 @Read | |
54 public ImagingStudy getResourceById(@IdParam IdType theId) { | |
55 Map<String, String> tags = new HashMap<>(); | |
56 tags.put(Toolbox.TAG_STUDY_INSTANCE_UID, theId.getIdPart()); | |
57 | |
58 List<OrthancResource> resources = OrthancResource.find(orthanc, be.uclouvain.orthanc.ResourceType.STUDY, 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).getFhirStudy(orthanc); | |
65 } | |
66 } | |
67 | |
68 @Search() | |
69 public List<ImagingStudy> getImagingStudies(@OptionalParam(name = ImagingStudy.SP_IDENTIFIER) StringParam theIdentifier, | |
70 @OptionalParam(name = ImagingStudy.SP_SUBJECT) ReferenceParam theSubject) { | |
71 Map<String, String> tags = new HashMap<>(); | |
72 | |
73 if (theIdentifier != null) { | |
74 tags.put(Toolbox.TAG_STUDY_INSTANCE_UID, theIdentifier.getValue()); | |
75 } | |
76 | |
77 if (theSubject != null) { | |
78 // https://hapifhir.io/hapi-fhir/docs/server_plain/rest_operations_search.html#search-parameters-resource-reference | |
79 tags.put(Toolbox.TAG_PATIENT_ID, theSubject.getValue()); | |
80 } | |
81 | |
82 List<OrthancResource> resources = OrthancResource.find(orthanc, be.uclouvain.orthanc.ResourceType.STUDY, tags, false); | |
83 | |
84 List<ImagingStudy> studies = new ArrayList<>(); | |
85 for (OrthancResource resource : resources) { | |
86 ImagingStudy study = resource.getFhirStudy(orthanc); | |
87 if (study.hasId()) { | |
88 studies.add(study); | |
89 } | |
90 } | |
91 | |
92 return studies; | |
93 } | |
94 } |