Skip to content

Commit

Permalink
#1 Add initial Folder support
Browse files Browse the repository at this point in the history
  • Loading branch information
Thopap committed Dec 3, 2023
1 parent f2ce76a commit c60e9a5
Show file tree
Hide file tree
Showing 8 changed files with 1,839 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class MappingSupport {
public static String URI_URN = "urn:ietf:rfc:3986";
public static final String MHD_COMPREHENSIVE_PROFILE = "https://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.Comprehensive.DocumentReference";
public static final String MHD_COMPREHENSIVE_SUBMISSIONSET_PROFILE = "https://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.Comprehensive.SubmissionSet";
public static final String MHD_COMPREHENSIVE_FOLDER_PROFILE = "https://profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.Comprehensive.Folder";

public static final Map<Precision, TemporalPrecisionEnum> PRECISION_MAP_FROM_XDS = new EnumMap<>(
Map.of(Precision.DAY, TemporalPrecisionEnum.DAY,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.openehealth.app.xdstofhir.registry.common.fhir;

import java.util.List;

import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.Extension;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
import lombok.Getter;
import lombok.Setter;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.ListResource;
import org.openehealth.app.xdstofhir.registry.common.MappingSupport;

@ResourceDef(name = "List", profile = MappingSupport.MHD_COMPREHENSIVE_FOLDER_PROFILE)
public class MhdFolder extends ListResource {
private static final long serialVersionUID = 6730967324453182475L;

public static final CodeableConcept FOLDER_CODEING = new CodeableConcept(
new Coding("https://profiles.ihe.net/ITI/MHD/CodeSystem/MHDlistTypes", "folder",
"Folder as a FHIR List"));

public MhdFolder() {
super();
setCode(FOLDER_CODEING);
setStatus(ListStatus.CURRENT);
setMode(ListMode.WORKING);
}

@Child(name = "designationType", type = {CodeableConcept.class}, order=1, min=1, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
@Extension(url = "https://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-designationType", definedLocally = false, isModifier = false)
@Description(shortDefinition = "Clinical code of the List")
@Getter @Setter
private List<CodeableConcept> designationType;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.openehealth.app.xdstofhir.registry.common.mapper;

import java.util.Collections;
import java.util.function.Function;
import java.util.stream.Collectors;

import lombok.RequiredArgsConstructor;
import org.hl7.fhir.r4.model.Annotation;
import org.hl7.fhir.r4.model.Identifier;
import org.openehealth.app.xdstofhir.registry.common.MappingSupport;
import org.openehealth.app.xdstofhir.registry.common.fhir.MhdFolder;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.Folder;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class XdsToFhirFolderMapper extends AbstractXdsToFhirMapper
implements Function<Folder, MhdFolder> {
@Override
public MhdFolder apply(Folder xdFolder) {
var mhdList = new MhdFolder();
mhdList.addIdentifier(fromIdentifier(xdFolder.getEntryUuid(), Identifier.IdentifierUse.OFFICIAL));
mhdList.addIdentifier(
fromIdentifier(MappingSupport.OID_URN + xdFolder.getUniqueId(), Identifier.IdentifierUse.USUAL));
mhdList.setSubject(patientReferenceFrom(xdFolder));
mhdList.setDateElement(fromTimestamp(xdFolder.getLastUpdateTime()));
mhdList.setDesignationType(xdFolder.getCodeList().stream().map(this::fromCode).collect(Collectors.toList()));
if (xdFolder.getTitle() != null)
mhdList.setTitle(xdFolder.getTitle().getValue());
if (xdFolder.getComments() != null) {
Annotation annotation = new Annotation();
annotation.setText(xdFolder.getComments().getValue());
mhdList.setNote(Collections.singletonList(annotation));
}
return mhdList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import ca.uhn.fhir.rest.client.api.IGenericClient;
import lombok.RequiredArgsConstructor;
import org.hl7.fhir.r4.model.DocumentReference;
import org.openehealth.app.xdstofhir.registry.common.fhir.MhdFolder;
import org.openehealth.app.xdstofhir.registry.common.fhir.MhdSubmissionSet;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntry;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.Folder;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.ObjectReference;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.SubmissionSet;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.Version;
Expand All @@ -34,6 +36,7 @@ public class StoredQueryProcessor implements Iti18Service {
private final IGenericClient client;
private final Function<DocumentReference, DocumentEntry> documentMapper;
private final Function<MhdSubmissionSet, SubmissionSet> submissionMapper;
private final Function<MhdFolder, Folder> folderMapper;
private static final Version DEFAULT_VERSION = new Version("1");

@Override
Expand All @@ -45,11 +48,15 @@ public QueryResponse processQuery(QueryRegistry query) {

var fhirDocuments = visitor.getDocumentsFromResult();
var fhirSubmissions = visitor.getSubmissionSetsFrom();
var fhirFolder = visitor.getFoldersFrom();
var xdsDocuments = new ArrayList<DocumentEntry>();
var xdsSubmissionSets = new ArrayList<SubmissionSet>();
var xdsFolders = new ArrayList<Folder>();

int currentResourceCount = 0;

for (DocumentReference document : fhirDocuments) {
if (xdsDocuments.size() > maxResultCount) {
if (currentResourceCount > maxResultCount) {
response.setStatus(Status.PARTIAL_SUCCESS);
response.setErrors(Collections.singletonList(new ErrorInfo(ErrorCode.TOO_MANY_RESULTS,
"Result exceed maximum of " + maxResultCount, Severity.WARNING, null, null)));
Expand All @@ -59,12 +66,12 @@ public QueryResponse processQuery(QueryRegistry query) {
if (xdsDoc != null) {
assignDefaultVersioning().accept(xdsDoc);
xdsDocuments.add(xdsDoc);
currentResourceCount++;
}

}

for (MhdSubmissionSet submissionset : fhirSubmissions) {
if (xdsDocuments.size() + xdsSubmissionSets.size() > maxResultCount) {
if (currentResourceCount > maxResultCount) {
response.setStatus(Status.PARTIAL_SUCCESS);
response.setErrors(Collections.singletonList(new ErrorInfo(ErrorCode.TOO_MANY_RESULTS,
"Result exceed maximum of " + maxResultCount, Severity.WARNING, null, null)));
Expand All @@ -74,6 +81,22 @@ public QueryResponse processQuery(QueryRegistry query) {
if (xdsSubmission != null) {
assignDefaultVersioning().accept(xdsSubmission);
xdsSubmissionSets.add(xdsSubmission);
currentResourceCount++;
}
}

for (MhdFolder folder : fhirFolder) {
if (currentResourceCount > maxResultCount) {
response.setStatus(Status.PARTIAL_SUCCESS);
response.setErrors(Collections.singletonList(new ErrorInfo(ErrorCode.TOO_MANY_RESULTS,
"Result exceed maximum of " + maxResultCount, Severity.WARNING, null, null)));
break;
}
var xdsFolder = folderMapper.apply(folder);
if (xdsFolder != null) {
assignDefaultVersioning().accept(xdsFolder);
xdsFolders.add(xdsFolder);
currentResourceCount++;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.codesystems.DocumentReferenceStatus;
import org.openehealth.app.xdstofhir.registry.common.MappingSupport;
import org.openehealth.app.xdstofhir.registry.common.fhir.MhdFolder;
import org.openehealth.app.xdstofhir.registry.common.fhir.MhdSubmissionSet;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.AvailabilityStatus;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.Code;
Expand Down Expand Up @@ -65,6 +66,7 @@
public class StoredQueryVistorImpl implements Visitor {
private IQuery<Bundle> documentFhirQuery;
private IQuery<Bundle> submissionSetfhirQuery;
private IQuery<Bundle> folderFhirQuery;

private final IGenericClient client;

Expand Down Expand Up @@ -156,7 +158,13 @@ public void visit(FindDocumentsForMultiplePatientsQuery query) {

@Override
public void visit(FindFoldersQuery query) {
throw new UnsupportedOperationException("Not yet implemented");
this.folderFhirQuery = client.search().forResource(MhdFolder.class)
.withProfile(MappingSupport.MHD_COMPREHENSIVE_FOLDER_PROFILE)
.where(MhdFolder.CODE.exactly()
.codings(MhdFolder.FOLDER_CODEING.getCodingFirstRep()))
.include(MhdFolder.INCLUDE_SUBJECT)
.returnBundle(Bundle.class);
mapPatientIdToQuery(query, folderFhirQuery);
}

@Override
Expand Down Expand Up @@ -218,9 +226,16 @@ public void visit(GetAllQuery query) {
.codings(MhdSubmissionSet.SUBMISSIONSET_CODEING.getCodingFirstRep()))
.include(MhdSubmissionSet.INCLUDE_SUBJECT)
.returnBundle(Bundle.class);
this.folderFhirQuery = client.search().forResource(MhdFolder.class)
.withProfile(MappingSupport.MHD_COMPREHENSIVE_FOLDER_PROFILE)
.where(MhdFolder.CODE.exactly()
.codings(MhdFolder.FOLDER_CODEING.getCodingFirstRep()))
.include(MhdFolder.INCLUDE_SUBJECT)
.returnBundle(Bundle.class);

mapPatientIdToQuery(query, documentFhirQuery);
mapPatientIdToQuery(query, submissionSetfhirQuery);
mapPatientIdToQuery(query, folderFhirQuery);
}

@Override
Expand Down Expand Up @@ -315,6 +330,13 @@ public Iterable<MhdSubmissionSet> getSubmissionSetsFrom() {
return () -> new PagingFhirResultIterator<MhdSubmissionSet>(submissionSetfhirQuery.execute(), MhdSubmissionSet.class);
}

public Iterable<MhdFolder> getFoldersFrom() {
if (folderFhirQuery == null) {
return () -> Collections.emptyIterator();
}
return () -> new PagingFhirResultIterator<MhdFolder>(folderFhirQuery.execute(), MhdFolder.class);
}

public class PagingFhirResultIterator<T extends DomainResource> implements Iterator<T> {

private Bundle resultBundle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
import org.hl7.fhir.r4.model.Patient;
import org.openehealth.app.xdstofhir.registry.common.MappingSupport;
import org.openehealth.app.xdstofhir.registry.common.RegistryConfiguration;
import org.openehealth.app.xdstofhir.registry.common.fhir.MhdFolder;
import org.openehealth.app.xdstofhir.registry.common.fhir.MhdSubmissionSet;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.AssociationType;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.AvailabilityStatus;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.DocumentEntry;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.Folder;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.SubmissionSet;
import org.openehealth.ipf.commons.ihe.xds.core.metadata.XDSMetaClass;
import org.openehealth.ipf.commons.ihe.xds.core.requests.RegisterDocumentSet;
Expand All @@ -36,6 +38,7 @@ public class RegisterDocumentsProcessor implements Iti42Service {
private final IGenericClient client;
private final Function<DocumentEntry, DocumentReference> documentMapper;
private final Function<SubmissionSet, MhdSubmissionSet> submissionSetMapper;
private final Function<Folder, MhdFolder> folderMapper;
private final RegistryConfiguration registryConfig;

@Override
Expand All @@ -45,6 +48,8 @@ public Response processRegister(RegisterDocumentSet register) {
validateKnownRepository(register);
register.getDocumentEntries().forEach(this::assignRegistryValues);
register.getDocumentEntries().forEach(this::assignPatientId);
register.getFolders().forEach(this::assignRegistryValues);
register.getFolders().forEach(this::assignPatientId);
assignPatientId(register.getSubmissionSet());
assignRegistryValues(register.getSubmissionSet());
register.getAssociations().stream().filter(assoc -> assoc.getAssociationType() == AssociationType.REPLACE)
Expand All @@ -54,6 +59,7 @@ public Response processRegister(RegisterDocumentSet register) {
.orElseThrow(() -> new XDSMetaDataException(ValidationMessage.UNRESOLVED_REFERENCE,
assoc.getSourceUuid())))));
register.getDocumentEntries().forEach(doc -> builder.addTransactionCreateEntry(documentMapper.apply(doc)));
register.getFolders().forEach(folder -> builder.addTransactionCreateEntry(folderMapper.apply(folder)));
builder.addTransactionCreateEntry(submissionSetMapper.apply(register.getSubmissionSet()));

// Execute the transaction
Expand Down
Loading

0 comments on commit c60e9a5

Please sign in to comment.