Skip to content

Commit

Permalink
Adding unit tests for bulk export web service client.
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrszul committed Mar 27, 2024
1 parent 9e7ba86 commit b49b08a
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package au.csiro.pathling.export.fhir;

import java.time.Instant;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand All @@ -31,8 +30,7 @@
*
* @see <a href="https://hl7.org/fhir/r4/parameters.html">Parameters</a>
*/
@Value
@Builder
@Value(staticConstructor = "of")
public class Parameters {

public static final String RESOURCE_TYPE = "Parameters";
Expand Down Expand Up @@ -111,19 +109,20 @@ public static Parameter of(@Nonnull final String name, final @Nonnull Instant va
* The type of the resource. Should be "Parameters".
*/
@Nonnull
@Builder.Default
String resourceType = RESOURCE_TYPE;

/**
* A collection of parameters.
*/
@Nonnull
@Builder.Default
List<Parameter> parameter = Collections.emptyList();

List<Parameter> parameter;

@Nonnull
public String toJson() {
return FhirJsonSupport.toJson(this);
}

public static Parameters of(@Nonnull final Parameter... parameters) {
return Parameters.of(List.of(parameters));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/**
* Represents a request to initiate a bulk export operation.
*
* @see <a href="https://hl7.org/fhir/uv/bulkdata/export.html#query-parameters>FHIR Bulk Export
* @see <a href="https://hl7.org/fhir/uv/bulkdata/export.html#query-parameters">FHIR Bulk Export
* Request Query Parameters</a>
*/
@Value
Expand All @@ -50,13 +50,15 @@ public interface Level {

/**
* The path to the export operation corresponding to this level.
*
* @return the path to the export operation.
*/
@Nonnull
String getPath();

/**
* Whether this level supports patient-specific exports.
*
* @return true if patient-specific exports are supported.
*/
boolean isPatientSupported();
Expand Down Expand Up @@ -131,12 +133,18 @@ public boolean isPatientSupported() {
Level level = new SystemLevel();

/**
* The format of the output. The default is 'ndjson'. The value of the '_outputFormat' query
* parameter.
* The format of the output. The value of the '_outputFormat' query parameter.
*/
@Nonnull
@Nullable
@Builder.Default
String _outputFormat = null;

/**
* The date and time to use as the lower bound for the export. The value of the '_since' query
*/
@Nullable
@Builder.Default
String _outputFormat = "ndjson";
Instant _since = null;

/**
* The types of resources to export. The value of the '_type' query parameter.
Expand All @@ -161,12 +169,6 @@ public boolean isPatientSupported() {
@Builder.Default
List<String> _typeFilter = Collections.emptyList();

/**
* The date and time to use as the lower bound for the export. The value of the '_since' query
*/
@Nullable
@Builder.Default
Instant _since = null;

/**
* The patient(s) to include in the export. The value of the 'patient' parameter.
Expand All @@ -184,13 +186,12 @@ public boolean isPatientSupported() {
public Parameters toParameters() {

final List<Parameter> params = Stream.of(
Stream.of(
Parameter.of("_outputFormat", _outputFormat)
),
Optional.ofNullable(_outputFormat)
.map(s -> Parameter.of("_outputFormat", s)).stream(),
Optional.ofNullable(_since)
.map(s -> Parameter.of("_since", s)).stream(),
_type.stream()
.map(t -> Parameter.of("_type", t)),
Lists.optionalOf(_type)
.map(e -> Parameter.of("_type", String.join(",", e))).stream(),
Lists.optionalOf(_elements)
.map(e -> Parameter.of("_elements", String.join(",", e))).stream(),
Lists.optionalOf(_typeFilter)
Expand All @@ -200,9 +201,6 @@ public Parameters toParameters() {
)
.flatMap(Function.identity())
.collect(Collectors.toUnmodifiableList());

return Parameters.builder()
.parameter(params)
.build();
return Parameters.of(params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,24 @@

package au.csiro.pathling.export.fhir;

import static org.junit.jupiter.api.Assertions.assertEquals;

import au.csiro.pathling.export.fhir.Parameters.Parameter;
import java.time.Instant;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import java.time.Instant;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

class ParametersTest {


@Test
public void testSerializerParametersWithReference() {

final Parameters parameters = Parameters.builder()
.parameter(List.of(
Parameter.of("reference", Reference.of("Patient/00")),
Parameter.of("reference", Reference.of("Patient/01"))
)
).build();
final Parameters parameters = Parameters.of(
Parameter.of("reference", Reference.of("Patient/00")),
Parameter.of("reference", Reference.of("Patient/01"))
);
assertEquals(
new JSONObject()
.put("resourceType", "Parameters")
Expand All @@ -63,13 +60,11 @@ public void testSerializesParametersOfAllTyes() {

final String testInstantString = "2023-01-01T00:00:00.123Z";

final Parameters parameters = Parameters.builder()
.parameter(List.of(
Parameter.of("reference", Reference.of("Patient/00")),
Parameter.of("string", "stringValue"),
Parameter.of("instant", Instant.parse(testInstantString))
)
).build();
final Parameters parameters = Parameters.of(
Parameter.of("reference", Reference.of("Patient/00")),
Parameter.of("string", "stringValue"),
Parameter.of("instant", Instant.parse(testInstantString))
);
assertEquals(
new JSONObject()
.put("resourceType", "Parameters")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2023 Commonwealth Scientific and Industrial Research
* Organisation (CSIRO) ABN 41 687 119 230.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package au.csiro.pathling.export.ws;

import au.csiro.pathling.export.fhir.Parameters;
import au.csiro.pathling.export.fhir.Parameters.Parameter;
import au.csiro.pathling.export.fhir.Reference;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

class BulkExportRequestTest {


@Test
void testToParametersWithAllDefaults() {
final BulkExportRequest request = BulkExportRequest.builder()
.build();
assertEquals(Parameters.of(), request.toParameters());
}

@Test
void testToParametersWithWithAllValuesSet() {
final BulkExportRequest request = BulkExportRequest.builder()
._outputFormat("fhir+ndjson")
._since(Instant.parse("2023-08-01T00:00:00Z"))
._type(List.of("Patient", "Condition"))
._elements(List.of("Patient.name", "Patient.birthDate"))
._typeFilter(List.of("Patient?active=true", "Condition?clinicalStatus=active"))
.patient(List.of(Reference.of("Patient/00"), Reference.of("Patient/01")))
.build();
assertEquals(
Parameters.of(
Parameter.of("_outputFormat", "fhir+ndjson"),
Parameter.of("_since", Instant.parse("2023-08-01T00:00:00Z")),
Parameter.of("_type", "Patient,Condition"),
Parameter.of("_elements", "Patient.name,Patient.birthDate"),
Parameter.of("_typeFilter", "Patient?active=true,Condition?clinicalStatus=active"),
Parameter.of("patient", Reference.of("Patient/00")),
Parameter.of("patient", Reference.of("Patient/01"))
),
request.toParameters());
}
}

0 comments on commit b49b08a

Please sign in to comment.