Skip to content

Commit

Permalink
#1 Add initial support for GetRelatedDocumentsQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
Thopap committed Dec 19, 2023
1 parent e3beec8 commit e310a45
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@
import org.openehealth.ipf.commons.ihe.xds.core.requests.query.Query.Visitor;
import org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryList;

/**
* Implement ITI-18 queries using IPF visitor pattern.
*
* The XDS queries will be mapped to a FHIR query.
*
*
*/
public class StoredQueryVistorImpl implements Visitor {
/*
* Hapi currently ignore "_list" parameter, workaround here with "_has" reverse chain search
Expand Down Expand Up @@ -136,7 +143,22 @@ public void visit(GetSubmissionSetAndContentsQuery query) {

@Override
public void visit(GetRelatedDocumentsQuery query) {
throw new UnsupportedOperationException("Not yet implemented");
IQuery<Bundle> documentFhirQuery = initDocumentQuery();
documentFhirQuery.include(DocumentReference.INCLUDE_RELATESTO);
String identifier = MappingSupport.toUrnCoded(Objects.requireNonNullElse(query.getUniqueId(), query.getUuid()));
documentFhirQuery.where(DocumentReference.IDENTIFIER.exactly().systemAndValues(URI_URN, identifier));
documentFhirQuery.where(DocumentReference.RELATESTO.isMissing(false));
buildResultForDocuments(documentFhirQuery);
List<DocumentReference> results = new ArrayList<>();
populateDocumentTo(results);
documentFhirQuery = initDocumentQuery();
documentFhirQuery.include(DocumentReference.INCLUDE_RELATESTO);
documentFhirQuery.where(DocumentReference.RELATESTO
.hasChainedProperty(DocumentReference.IDENTIFIER.exactly().systemAndValues(URI_URN, identifier)));
documentFhirQuery.where(DocumentReference.RELATESTO.isMissing(false));
buildResultForDocuments(documentFhirQuery);
populateDocumentTo(results);
documentResult = () -> results.iterator();
}

@Override
Expand Down Expand Up @@ -221,6 +243,12 @@ public void visit(FindDocumentsByReferenceIdQuery query) {
buildResultForDocuments(documentFhirQuery);
}

private void populateDocumentTo(List<DocumentReference> results) {
for (var result : documentResult) {
results.add(result);
}
}

private void buildResultForFolder(IQuery<Bundle> folderFhirQuery) {
folderResult = () -> new PagingFhirResultIterator<MhdFolder>(folderFhirQuery.execute(), MhdFolder.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetAllQuery;
import org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetFoldersForDocumentQuery;
import org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetFoldersQuery;
import org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetRelatedDocumentsQuery;
import org.openehealth.ipf.commons.ihe.xds.core.requests.query.GetSubmissionSetAndContentsQuery;

@ExtendWith(MockServerExtension.class)
Expand Down Expand Up @@ -194,4 +195,28 @@ void testGetFolderForDocuments (){
);
}

@Test
void testGetRelatedDocuments (){
mockServer.when(
request().withPath("/DocumentReference"))
.respond(response().withStatusCode(200).withContentType(MediaType.APPLICATION_JSON)
.withBody(EMPTY_BUNDLE_RESULT));
var query = (GetRelatedDocumentsQuery) SampleData.createGetRelatedDocumentsQuery().getQuery();
classUnderTest.visit(query);
classUnderTest.getDocumentResult().iterator();

mockServer.verify(request()
.withQueryStringParameter("identifier", "urn:ietf:rfc:3986|urn:ihe:xds:12.21.34")
.withQueryStringParameter("_include", "DocumentReference:subject", "DocumentReference:relatesto")
.withQueryStringParameter("_profile", MappingSupport.MHD_COMPREHENSIVE_PROFILE)
.withQueryStringParameter("relatesto:missing", "false")
);
mockServer.verify(request()
.withQueryStringParameter("relatesto.identifier", "urn:ietf:rfc:3986|urn:ihe:xds:12.21.34")
.withQueryStringParameter("_include", "DocumentReference:subject", "DocumentReference:relatesto")
.withQueryStringParameter("_profile", MappingSupport.MHD_COMPREHENSIVE_PROFILE)
.withQueryStringParameter("relatesto:missing", "false")
);
}

}

0 comments on commit e310a45

Please sign in to comment.