• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.healthconnect.cts.phr.utils;
18 
19 /**
20  * Helper class for building FHIR data related to encounters, including <a
21  * href="https://www.hl7.org/fhir/encounter.html">Encounter</a> (see {@link #encounter}), <a
22  * href="https://www.hl7.org/fhir/location.html">Location</a> (see {@link #location}), and <a
23  * href="https://www.hl7.org/fhir/organization.html">Organization</a> (see {@link #organization})
24  */
25 public class EncountersBuilder {
26 
27     private static final String DEFAULT_ENCOUNTER_JSON =
28             "{"
29                     + "  \"resourceType\": \"Encounter\","
30                     + "  \"id\": \"example\","
31                     + "  \"status\": \"in-progress\","
32                     + "  \"class\": {"
33                     + "    \"system\": \"http://terminology.hl7.org/CodeSystem/v3-ActCode\","
34                     + "    \"code\": \"IMP\","
35                     + "    \"display\": \"inpatient encounter\""
36                     + "  },"
37                     + "  \"subject\": {"
38                     + "    \"reference\": \"Patient/example\""
39                     + "  },"
40                     + "  \"diagnosis\": ["
41                     + "    {"
42                     + "      \"condition\": {"
43                     + "        \"display\":"
44                     + "\"Complications from Roel's TPF chemotherapy on January 28th, 2013\""
45                     + "      },"
46                     + "      \"use\": {"
47                     + "        \"coding\": ["
48                     + "          {"
49                     + "            \"system\":"
50                     + " \"http://terminology.hl7.org/CodeSystem/diagnosis-role\","
51                     + "            \"code\": \"AD\","
52                     + "            \"display\": \"Admission diagnosis\""
53                     + "          }"
54                     + "        ]"
55                     + "      },"
56                     + "      \"rank\": 2"
57                     + "    },"
58                     + "    {"
59                     + "      \"condition\": {"
60                     + "        \"display\": \"The patient is treated for a tumor\""
61                     + "      },"
62                     + "      \"use\": {"
63                     + "        \"coding\": ["
64                     + "          {"
65                     + "            \"system\":"
66                     + "\"http://terminology.hl7.org/CodeSystem/diagnosis-role\","
67                     + "            \"code\": \"CC\","
68                     + "            \"display\": \"Chief complaint\""
69                     + "          }"
70                     + "        ]"
71                     + "      },"
72                     + "      \"rank\": 1"
73                     + "    }"
74                     + "  ]"
75                     + "}";
76 
77     private static final String DEFAULT_LOCATION_JSON =
78             "{"
79                     + "  \"resourceType\": \"Location\","
80                     + "  \"id\": \"1\","
81                     + "  \"identifier\": ["
82                     + "    {"
83                     + "      \"value\": \"B1-S.F2\""
84                     + "    }"
85                     + "  ],"
86                     + "  \"status\": \"active\","
87                     + "  \"name\": \"South Wing, second floor\","
88                     + "  \"alias\": ["
89                     + "    \"BU MC, SW, F2\","
90                     + "    \"Burgers University Medical Center, South Wing, second floor\""
91                     + "  ],"
92                     + "  \"description\": \"Second floor of the Old South Wing\","
93                     + "  \"mode\": \"instance\","
94                     + "  \"telecom\": ["
95                     + "    {"
96                     + "      \"system\": \"phone\","
97                     + "      \"value\": \"2328\","
98                     + "      \"use\": \"work\""
99                     + "    },"
100                     + "    {"
101                     + "      \"system\": \"fax\","
102                     + "      \"value\": \"2329\","
103                     + "      \"use\": \"work\""
104                     + "    },"
105                     + "    {"
106                     + "      \"system\": \"email\","
107                     + "      \"value\": \"second wing admissions\""
108                     + "    },"
109                     + "    {"
110                     + "      \"system\": \"url\","
111                     + "      \"value\": \"http://sampleorg.com/southwing\","
112                     + "      \"use\": \"work\""
113                     + "    }"
114                     + "  ],"
115                     + "  \"address\": {"
116                     + "    \"use\": \"work\","
117                     + "    \"line\": ["
118                     + "      \"Galapagosweg 91, Building A\""
119                     + "    ],"
120                     + "    \"city\": \"Den Burg\","
121                     + "    \"postalCode\": \"9105 PZ\","
122                     + "    \"country\": \"NLD\""
123                     + "  },"
124                     + "  \"physicalType\": {"
125                     + "    \"coding\": ["
126                     + "      {"
127                     + "        \"system\":"
128                     + "\"http://terminology.hl7.org/CodeSystem/location-physical-type\","
129                     + "        \"code\": \"wi\","
130                     + "        \"display\": \"Wing\""
131                     + "      }"
132                     + "    ]"
133                     + "  },"
134                     + "  \"position\": {"
135                     + "    \"longitude\": -83.6945691,"
136                     + "    \"latitude\": 42.25475478,"
137                     + "    \"altitude\": 0"
138                     + "  },"
139                     + "  \"managingOrganization\": {"
140                     + "    \"reference\": \"Organization/f001\""
141                     + "  },"
142                     + "  \"endpoint\": ["
143                     + "    {"
144                     + "      \"reference\": \"Endpoint/example\""
145                     + "    }"
146                     + "  ]"
147                     + "}";
148 
149     private static final String DEFAULT_ORGANIZATION_JSON =
150             "{"
151                     + "  \"resourceType\": \"Organization\","
152                     + "  \"id\": \"2.16.840.1.113883.19.5\","
153                     + "  \"identifier\": ["
154                     + "    {"
155                     + "      \"system\": \"urn:ietf:rfc:3986\","
156                     + "      \"value\": \"urn:oid:2.16.840.1.113883.19.5\""
157                     + "    }"
158                     + "  ],"
159                     + "  \"name\": \"Good Health Clinic\""
160                     + "}";
161 
162     public static class EncounterBuilder extends FhirResourceBuilder<EncounterBuilder> {
EncounterBuilder()163         private EncounterBuilder() {
164             super(DEFAULT_ENCOUNTER_JSON);
165         }
166 
167         @Override
returnThis()168         protected EncounterBuilder returnThis() {
169             return this;
170         }
171     }
172 
173     public static class LocationBuilder extends FhirResourceBuilder<LocationBuilder> {
LocationBuilder()174         private LocationBuilder() {
175             super(DEFAULT_LOCATION_JSON);
176         }
177 
178         @Override
returnThis()179         protected LocationBuilder returnThis() {
180             return this;
181         }
182     }
183 
184     public static class OrganizationBuilder extends FhirResourceBuilder<OrganizationBuilder> {
OrganizationBuilder()185         private OrganizationBuilder() {
186             super(DEFAULT_ORGANIZATION_JSON);
187         }
188 
189         @Override
returnThis()190         protected OrganizationBuilder returnThis() {
191             return this;
192         }
193     }
194 
195     /**
196      * Returns a helper class useful for making FHIR <a
197      * href="https://www.hl7.org/fhir/encounter.html">Encounter</a> data for use in tests.
198      */
encounter()199     public static EncounterBuilder encounter() {
200         return new EncounterBuilder();
201     }
202 
203     /**
204      * Returns a helper class useful for making FHIR <a
205      * href="https://www.hl7.org/fhir/location.html">Location</a> data for use in tests.
206      */
location()207     public static LocationBuilder location() {
208         return new LocationBuilder();
209     }
210 
211     /**
212      * Returns a helper class useful for making FHIR <a
213      * href="https://www.hl7.org/fhir/organization.html">Organization</a> data for use in tests.
214      */
organization()215     public static OrganizationBuilder organization() {
216         return new OrganizationBuilder();
217     }
218 }
219