Skip to content

Commit

Permalink
ITI-51 query "FindDocumentsByReferenceIdListForMultiplePatients"; closes
Browse files Browse the repository at this point in the history
  • Loading branch information
unixoid committed Jul 11, 2024
1 parent dd8d1ab commit a9e5ecb
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2024 the original author or authors.
*
* 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 org.openehealth.ipf.commons.ihe.xds.core.requests.query;

import jakarta.xml.bind.annotation.*;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.AvailabilityStatus;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntryType;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.ReferenceId;
import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.query.QuerySlotHelper;

import java.io.Serial;
import java.util.List;

/**
* Represents a Multi-Patient stored query for FindDocuments by Reference ID.
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "FindDocumentsByReferenceIdForMultiplePatientsQuery",
propOrder = {"patientIds","status", "documentEntryTypes", "referenceIds"})
@XmlRootElement(name = "findDocumentsByReferenceIdForMultiplePatientsQuery")
@EqualsAndHashCode(callSuper = true, doNotUseGetters = true)
@ToString(callSuper = true, doNotUseGetters = true)
public class FindDocumentsByReferenceIdForMultiplePatientsQuery extends DocumentsQuery implements DocumentEntryTypeAwareStoredQuery {
@Serial
private static final long serialVersionUID = -8981126710746958226L;

@Getter @Setter private List<Identifiable> patientIds;
@Getter @Setter private List<AvailabilityStatus> status;
@XmlElement(name = "documentEntryType")
@Getter @Setter private List<DocumentEntryType> documentEntryTypes;
@XmlElement(name = "referenceId")
@Getter @Setter private QueryList<String> referenceIds;

/**
* Constructs the query.
*/
public FindDocumentsByReferenceIdForMultiplePatientsQuery() {
super(QueryType.FIND_DOCUMENTS_BY_REFERENCE_ID_MPQ);
}

@Override
public void accept(Visitor visitor) {
visitor.visit(this);
}

/**
* Allows to use a collection of {@link ReferenceId} instead of a collection of {@link String}
* for specifying the query parameter "$XDSDocumentEntryReferenceIdList".
*
* @param referenceIds a collection of {@link ReferenceId} objects with AND/OR semantics.
*/
public void setTypedReferenceIds(QueryList<ReferenceId> referenceIds) {
this.referenceIds = QuerySlotHelper.render(referenceIds);
}

/**
* Tries to return the query parameter "$XDSDocumentEntryReferenceIdList"
* as a collection of {@link ReferenceId} instead of a collection of {@link String}.
* This may fail if SQL LIKE wildcards ("%", "_", etc.) are used in one or more elements.
*
* @return a collection of {@link ReferenceId} objects with AND/OR semantics.
*/
public QueryList<ReferenceId> getTypedReferenceIds() {
return QuerySlotHelper.parse(this.referenceIds, ReferenceId.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public interface Visitor {
void visit(GetAllQuery query);
void visit(FindSubmissionSetsQuery query);
void visit(FindDocumentsByReferenceIdQuery query);
void visit(FindDocumentsByReferenceIdForMultiplePatientsQuery query);
// for ITI-63
void visit(FetchQuery query);
// for PHARM-1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public enum QueryType {
@XmlEnumValue("FindFolders") FIND_FOLDERS("urn:uuid:958f3006-baad-4929-a4de-ff1114824431", FindFoldersQuery.class),
/** Searches for documents by reference IDs */
@XmlEnumValue("FindDocumentsByReferenceId") FIND_DOCUMENTS_BY_REFERENCE_ID("urn:uuid:12941a89-e02e-4be5-967c-ce4bfc8fe492", FindDocumentsByReferenceIdQuery.class),
/** Searches for documents by reference IDs (Multi Patient Variety). */
@XmlEnumValue("FindDocumentsByReferenceIdForMultiplePatients") FIND_DOCUMENTS_BY_REFERENCE_ID_MPQ("urn:uuid:1191642d-86c4-42d8-b784-f95445f9f0d5", FindDocumentsByReferenceIdForMultiplePatientsQuery.class),
/** Searches for folders (Multi Patient Variety). */
@XmlEnumValue("FindFoldersForMultiplePatients") FIND_FOLDERS_MPQ("urn:uuid:50d3f5ac-39a2-11de-a1ca-b366239e58df", FindFoldersForMultiplePatientsQuery.class),
/** Returns everything. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public void visit(FindDocumentsByReferenceIdQuery query) {
FindDocumentsByReferenceIdQueryTransformer.getInstance().fromEbXML(query, ebXML);
}

@Override
public void visit(FindDocumentsByReferenceIdForMultiplePatientsQuery query) {
FindDocumentsByReferenceIdForMultiplePatientsQueryTransformer.getInstance().fromEbXML(query, ebXML);
}

@Override
public void visit(FindMedicationTreatmentPlansQuery query) {
FindMedicationTreatmentPlansQueryTransformer.getInstance().fromEbXML(query, ebXML);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public void visit(FindDocumentsByReferenceIdQuery query) {
FindDocumentsByReferenceIdQueryTransformer.getInstance().toEbXML(query, ebXML);
}

@Override
public void visit(FindDocumentsByReferenceIdForMultiplePatientsQuery query) {
FindDocumentsByReferenceIdForMultiplePatientsQueryTransformer.getInstance().toEbXML(query, ebXML);
}

@Override
public void visit(FindMedicationTreatmentPlansQuery query) {
FindMedicationTreatmentPlansQueryTransformer.getInstance().toEbXML(query, ebXML);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 the original author or authors.
*
* 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 org.openehealth.ipf.commons.ihe.xds.core.transform.requests.query;

import lombok.Getter;
import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLAdhocQueryRequest;
import org.openehealth.ipf.commons.ihe.xds.core.requests.query.FindDocumentsByReferenceIdForMultiplePatientsQuery;

import static org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter.*;

/**
* Transforms between a {@link FindDocumentsByReferenceIdForMultiplePatientsQuery} and {@link EbXMLAdhocQueryRequest}.
*/
public class FindDocumentsByReferenceIdForMultiplePatientsQueryTransformer extends DocumentsQueryTransformer<FindDocumentsByReferenceIdForMultiplePatientsQuery> {

@Getter
private static final FindDocumentsByReferenceIdForMultiplePatientsQueryTransformer instance = new FindDocumentsByReferenceIdForMultiplePatientsQueryTransformer();

@Override
protected void toEbXML(FindDocumentsByReferenceIdForMultiplePatientsQuery query, QuerySlotHelper slots) {
super.toEbXML(query, slots);
slots.fromPatientIdList(DOC_ENTRY_PATIENT_ID, query.getPatientIds());
slots.fromDocumentEntryType(DOC_ENTRY_TYPE, query.getDocumentEntryTypes());
slots.fromStatus(DOC_ENTRY_STATUS, query.getStatus());
slots.fromStringList(DOC_ENTRY_REFERENCE_IDS, query.getReferenceIds());
}

@Override
protected void fromEbXML(FindDocumentsByReferenceIdForMultiplePatientsQuery query, QuerySlotHelper slots) {
super.fromEbXML(query, slots);
query.setPatientIds(slots.toPatientIdList(DOC_ENTRY_PATIENT_ID));
query.setDocumentEntryTypes(slots.toDocumentEntryType(DOC_ENTRY_TYPE));
query.setStatus(slots.toStatus(DOC_ENTRY_STATUS));
query.setReferenceIds(slots.toStringQueryList(DOC_ENTRY_REFERENCE_IDS));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ private static void addAllowedMultipleSlots(QueryType queryType, QueryParameter.
DOC_ENTRY_EVENT_CODE,
DOC_ENTRY_CONFIDENTIALITY_CODE);

addAllowedMultipleSlots(FIND_DOCUMENTS_BY_REFERENCE_ID_MPQ,
DOC_ENTRY_REFERENCE_IDS,
DOC_ENTRY_EVENT_CODE,
DOC_ENTRY_CONFIDENTIALITY_CODE);

addAllowedMultipleSlots(FIND_FOLDERS,
FOLDER_CODES);

Expand Down Expand Up @@ -160,7 +165,7 @@ private static void addAllowedMultipleSlots(QueryType queryType, QueryParameter.
ALLOWED_QUERY_TYPES = new HashMap<>(5);
ALLOWED_QUERY_TYPES.put(ITI_18, itiStoredQueryTypes);
ALLOWED_QUERY_TYPES.put(ITI_38, itiStoredQueryTypes);
ALLOWED_QUERY_TYPES.put(ITI_51, EnumSet.of(FIND_DOCUMENTS_MPQ, FIND_FOLDERS_MPQ));
ALLOWED_QUERY_TYPES.put(ITI_51, EnumSet.of(FIND_DOCUMENTS_MPQ, FIND_FOLDERS_MPQ, FIND_DOCUMENTS_BY_REFERENCE_ID_MPQ));
ALLOWED_QUERY_TYPES.put(ITI_63, EnumSet.of(FETCH));
ALLOWED_QUERY_TYPES.put(PHARM_1, pharmStoredQueryTypes);
}
Expand Down Expand Up @@ -248,8 +253,11 @@ private QueryParameterValidation[] instantiateValidators(QueryType queryType, Xd
};

case FIND_DOCUMENTS_BY_REFERENCE_ID:
case FIND_DOCUMENTS_BY_REFERENCE_ID_MPQ:
return new QueryParameterValidation[]{
new StringValidation(DOC_ENTRY_PATIENT_ID, cxValidator, false),
queryType.equals(FIND_DOCUMENTS_BY_REFERENCE_ID)
? new StringValidation(DOC_ENTRY_PATIENT_ID, cxValidator, false)
: new StringListValidation(DOC_ENTRY_PATIENT_ID, cxValidator),
new CodeValidation(DOC_ENTRY_CLASS_CODE),
new CodeValidation(DOC_ENTRY_TYPE_CODE),
new CodeValidation(DOC_ENTRY_PRACTICE_SETTING_CODE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,30 @@ public static QueryRegistry createFindDocumentsByReferenceIdQuery() {
return new QueryRegistry(query);
}

public static QueryRegistry createFindDocumentsByReferenceIdForMultiplePatientsQuery() {
var query = new FindDocumentsByReferenceIdForMultiplePatientsQuery();
populateDocumentsQuery(query);
query.setPatientIds(Arrays.asList(
new Identifiable("id3", new AssigningAuthority("1.3")),
new Identifiable("id4", new AssigningAuthority("1.4"))));
query.setStatus(Arrays.asList(AvailabilityStatus.APPROVED, AvailabilityStatus.SUBMITTED));
query.setDocumentEntryTypes(Collections.singletonList(DocumentEntryType.STABLE));

var referenceIds = new QueryList<ReferenceId>();
referenceIds.getOuterList().add(Arrays.asList(
new ReferenceId("ref-id-11", new CXiAssigningAuthority("", "1.1.1.1", "ISO"),
ReferenceId.ID_TYPE_CODE_UNIQUE_ID),
new ReferenceId("ref-id-12", null, ReferenceId.ID_TYPE_WORKFLOW_INSTANCE_ID),
new ReferenceId("ref-id-13", null, ReferenceId.ID_TYPE_CODE_REFERRAL)));
referenceIds.getOuterList().add(Arrays.asList(
new ReferenceId("ref-id-21", new CXiAssigningAuthority("", "1.1.1.2", "ISO"),
ReferenceId.ID_TYPE_CODE_ACCESSION),
new ReferenceId("ref-id-22", null, ReferenceId.ID_TYPE_CODE_ORDER)));
query.setTypedReferenceIds(referenceIds);

return new QueryRegistry(query);
}

public static QueryRegistry createFindDocumentsByTitleQuery() {
var query = new FindDocumentsByTitleQuery();
populateDocumentsQuery(query);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2024 the original author or authors.
*
* 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 org.openehealth.ipf.commons.ihe.xds.core.transform.requests.ebxml30;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openehealth.ipf.commons.ihe.xds.core.SampleData;
import org.openehealth.ipf.commons.ihe.xds.core.ebxml.ebxml30.EbXMLFactory30;
import org.openehealth.ipf.commons.ihe.xds.core.requests.query.FindDocumentsByReferenceIdForMultiplePatientsQuery;
import org.openehealth.ipf.commons.ihe.xds.core.requests.query.QueryType;
import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.QueryParameter;
import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.query.AbstractQueryTransformerTest;
import org.openehealth.ipf.commons.ihe.xds.core.transform.requests.query.FindDocumentsByReferenceIdForMultiplePatientsQueryTransformer;

import java.util.Arrays;

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

/**
* Tests for {@link FindDocumentsByReferenceIdForMultiplePatientsQueryTransformer}.
* @author Dmytro Rud
*/
public class FindDocumentsByReferenceIdListForMultiplePatientsQueryTransformerTest extends AbstractQueryTransformerTest<FindDocumentsByReferenceIdForMultiplePatientsQuery, FindDocumentsByReferenceIdForMultiplePatientsQueryTransformer> {

@BeforeEach
public void setUp() {
transformer = FindDocumentsByReferenceIdForMultiplePatientsQueryTransformer.getInstance();
query = (FindDocumentsByReferenceIdForMultiplePatientsQuery) SampleData.createFindDocumentsByReferenceIdForMultiplePatientsQuery().getQuery();
ebXML = new EbXMLFactory30().createAdhocQueryRequest();
}

@Test
public void testToEbXML() {
transformer.toEbXML(query, ebXML);

assertEquals(QueryType.FIND_DOCUMENTS_BY_REFERENCE_ID_MPQ.getId(), ebXML.getId());
assertEquals("12.21.41", ebXML.getHome());
assertEquals(Arrays.asList("('id3^^^&1.3&ISO')", "('id4^^^&1.4&ISO')"),
ebXML.getSlotValues(QueryParameter.DOC_ENTRY_PATIENT_ID.getSlotName()));

var referenceIdSlots = ebXML.getSlots(QueryParameter.DOC_ENTRY_REFERENCE_IDS.getSlotName());
assertEquals(2, referenceIdSlots.size());
assertEquals(Arrays.asList(
"('ref-id-11^^^&1.1.1.1&ISO^urn:ihe:iti:xds:2013:uniqueId')",
"('ref-id-12^^^^urn:ihe:iti:xdw:2013:workflowInstanceId')",
"('ref-id-13^^^^urn:ihe:iti:xds:2013:referral')"),
referenceIdSlots.get(0).getValueList());
assertEquals(Arrays.asList(
"('ref-id-21^^^&1.1.1.2&ISO^urn:ihe:iti:xds:2013:accession')",
"('ref-id-22^^^^urn:ihe:iti:xds:2013:order')"),
referenceIdSlots.get(1).getValueList());
}

@Override
protected FindDocumentsByReferenceIdForMultiplePatientsQuery emptyQuery() {
return new FindDocumentsByReferenceIdForMultiplePatientsQuery();
}
}
3 changes: 3 additions & 0 deletions src/site/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<action issue="449" dev="unixoid" type="add">
Add W3C Trace Context ID to Audit Trail records in the Swiss EPR context
</action>
<action issue="447" dev="unixoid" type="add">
Implement CP-ITI-793: Support for query type "FindDocumentsByReferenceIdListForMultiplePatients" in ITI-51
</action>
<action issue="446" dev="Ivan1pl" type="fix">
Properly handle query payload when translating ATNA audit records to FHIR
</action>
Expand Down

0 comments on commit a9e5ecb

Please sign in to comment.