Skip to content

Commit

Permalink
Minor codestyle fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Thopap committed May 20, 2024
1 parent 17c471e commit 278629c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private List<Association> collectAssociationsOfSubmissionSet(
IQuery<Bundle> submissionSetfhirQuery) {
var xdsAssocations = new ArrayList<Association>();
var resultForSubmissionSet = buildResultForSubmissionSet(submissionSetfhirQuery);
resultForSubmissionSet.forEach(submission -> {
resultForSubmissionSet.forEach(submission ->
submission.getEntry().forEach(entry -> {
var assocEntryUuid = entry.getId() != null ? entry.getId() : new URN(UUID.randomUUID()).toString();
if (entry.getItem().getResource() != null) {
Expand All @@ -341,24 +341,24 @@ private List<Association> collectAssociationsOfSubmissionSet(
xdsAssocations.add(new Association(AssociationType.HAS_MEMBER, assocEntryUuid,
entryUuidFrom(submission),entry.getItem().getIdentifier().getValue()));
}
});
});
})
);
return xdsAssocations;
}


private List<Association> collectAssociationsOfFolders(IQuery<Bundle> folderFhirQuery) {
var xdsAssocations = new ArrayList<Association>();
var resultForFolder = buildResultForFolder(folderFhirQuery);
resultForFolder.forEach(folder -> {
resultForFolder.forEach(folder ->
folder.getEntry().forEach(entry -> {
if (entry.getItem().getResource() instanceof DocumentReference folderDoc) {
var assocEntryUuid = entry.getId() != null ? entry.getId() : new URN(UUID.randomUUID()).toString();
xdsAssocations.add(new Association(AssociationType.HAS_MEMBER, assocEntryUuid,
entryUuidFrom(folder), entryUuidFrom(folderDoc)));
}
});
});
})
);
return xdsAssocations;
}

Expand All @@ -370,10 +370,10 @@ private List<Association> collectAssociationsOfDocument(IQuery<Bundle> documentF

resultForDocuments.forEach(doc -> {
var listResources = BundleUtil.toListOfResourcesOfType(client.getFhirContext(), docResultBundle, ListResource.class);
listResources.stream().filter(list -> list.getEntry().stream().anyMatch(entry -> doc.equals(entry.getItem().getResource()))).forEach(submission -> {
listResources.stream().filter(list -> list.getEntry().stream().anyMatch(entry -> doc.equals(entry.getItem().getResource()))).forEach(submission ->
xdsAssocations.add(new Association(AssociationType.HAS_MEMBER, new URN(UUID.randomUUID()).toString(),
entryUuidFrom(submission), entryUuidFrom(doc)));
});
entryUuidFrom(submission), entryUuidFrom(doc)))
);
doc.getRelatesTo().forEach(related -> {
if (related.getTarget().getResource() instanceof DocumentReference relatedDoc) {
var assocEntryUuid = related.getId() != null ? related.getId()
Expand Down Expand Up @@ -527,7 +527,7 @@ private void mapAssociations(List<Association> associations) {
}

private List<MhdSubmissionSet> mapSubmissionSets(Iterable<MhdSubmissionSet> fhirSubmissions) {
return mapSubmissionSets(fhirSubmissions, (sub) -> true);
return mapSubmissionSets(fhirSubmissions, sub -> true);
}

private List<MhdSubmissionSet> mapSubmissionSets(Iterable<MhdSubmissionSet> fhirSubmissions, Predicate<SubmissionSet> xdsSubmissionSetCriteria) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.openehealth.app.xdstofhir.registry.common.MappingSupport.OID_URN;
import static org.openehealth.app.xdstofhir.registry.common.MappingSupport.URI_URN;
import static org.openehealth.app.xdstofhir.registry.common.MappingSupport.UUID_URN;
import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.metaDataAssert;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -155,15 +156,13 @@ private void validateResubmission(DocumentEntry doc) {
} catch (XDSMetaDataException notPresent) {
return;
}
if (existingDoc.getIdentifier().stream().filter(id -> id.getValue().equals(doc.getEntryUuid())).findAny().isPresent()) {
throw new XDSMetaDataException(ValidationMessage.UUID_NOT_UNIQUE);
}
if (!(doc.getHash().equals(existingDoc.getContentFirstRep().getAttachment().getHashElement().asStringValue()))) {
throw new XDSMetaDataException(ValidationMessage.DIFFERENT_HASH_CODE_IN_RESUBMISSION);
}
if (doc.getSize() != existingDoc.getContentFirstRep().getAttachment().getSize()) {
throw new XDSMetaDataException(ValidationMessage.DIFFERENT_SIZE_IN_RESUBMISSION);
}
metaDataAssert(existingDoc.getIdentifier().stream().filter(id -> id.getValue().equals(doc.getEntryUuid()))
.findAny().isEmpty(), ValidationMessage.UUID_NOT_UNIQUE);
metaDataAssert(
doc.getHash().equals(existingDoc.getContentFirstRep().getAttachment().getHashElement().asStringValue()),
ValidationMessage.DIFFERENT_HASH_CODE_IN_RESUBMISSION);
metaDataAssert(doc.getSize() == existingDoc.getContentFirstRep().getAttachment().getSize(),
ValidationMessage.DIFFERENT_SIZE_IN_RESUBMISSION);
}

/**
Expand All @@ -182,17 +181,17 @@ private List<MhdFolder> createUpdateOfExistingFolders(List<String> externalFolde
folder.setDate(new Date());
var documentEntry = documentMap.get(assoc.getTargetUuid());
if (documentEntry != null) {
if (!folder.getSubject().getIdentifier().getValue()
.equals(documentEntry.getPatientId().getId())) {
throw new XDSMetaDataException(ValidationMessage.FOLDER_PATIENT_ID_WRONG);
}
metaDataAssert(
folder.getSubject().getIdentifier().getValue()
.equals(documentEntry.getPatientId().getId()),
ValidationMessage.FOLDER_PATIENT_ID_WRONG);
folder.addEntry(createReference(assoc, DocumentReference.class.getSimpleName()));
} else {
var existingDoc = lookupExistingDocument(assoc.getTargetUuid());
if (!folder.getSubject().getIdentifier().getValue()
.equals(existingDoc.getSubject().getIdentifier().getValue())) {
throw new XDSMetaDataException(ValidationMessage.FOLDER_PATIENT_ID_WRONG);
}
metaDataAssert(
folder.getSubject().getIdentifier().getValue()
.equals(existingDoc.getSubject().getIdentifier().getValue()),
ValidationMessage.FOLDER_PATIENT_ID_WRONG);
var ref = new ListEntryComponent(new Reference(existingDoc));
ref.setId(assoc.getEntryUuid());
folder.addEntry(ref);
Expand All @@ -213,9 +212,7 @@ private MhdFolder lookupExistingFolder(String entryUuid) {
var result = client.search().forResource(MhdFolder.class).count(1)
.where(ListResource.IDENTIFIER.exactly().systemAndValues(URI_URN, entryUuid))
.returnBundle(Bundle.class).execute();
if (result.getEntry().isEmpty()) {
throw new XDSMetaDataException(ValidationMessage.UNRESOLVED_REFERENCE, entryUuid);
}
metaDataAssert(!result.getEntry().isEmpty(), ValidationMessage.UNRESOLVED_REFERENCE, entryUuid);
return (MhdFolder)result.getEntryFirstRep().getResource();
}

Expand All @@ -225,9 +222,8 @@ private List<DocumentReferenceRelatesToComponent> createDocToDocReferences(List<
.filter(assoc -> DOC_DOC_FHIR_ASSOCIATIONS.containsKey(assoc.getAssociationType()))
.map(assoc -> {
var result = lookupExistingDocument(assoc.getTargetUuid());
if (!result.getStatus().equals(DocumentReferenceStatus.CURRENT)) {
throw new XDSMetaDataException(ValidationMessage.UNRESOLVED_REFERENCE, assoc.getTargetUuid());
}
metaDataAssert(result.getStatus().equals(DocumentReferenceStatus.CURRENT),
ValidationMessage.UNRESOLVED_REFERENCE, assoc.getTargetUuid());
var ref = new DocumentReferenceRelatesToComponent();
ref.setCode(DOC_DOC_FHIR_ASSOCIATIONS.get(assoc.getAssociationType()));
ref.setTarget(new Reference(result));
Expand Down Expand Up @@ -345,9 +341,8 @@ private ListEntryComponent createReference(Association assoc) {
*/
private DocumentReference replacePreviousDocument(String entryUuid, DocumentReference replacingDocument) {
var replacedDocument = lookupExistingDocument(entryUuid);
if (replacedDocument.getStatus() != DocumentReferenceStatus.CURRENT) {
throw new XDSMetaDataException(ValidationMessage.DEPRECATED_OBJ_CANNOT_BE_TRANSFORMED);
}
metaDataAssert(replacedDocument.getStatus() == DocumentReferenceStatus.CURRENT,
ValidationMessage.DEPRECATED_OBJ_CANNOT_BE_TRANSFORMED);
if (!replacedDocument.getSubject().getReference().endsWith(replacingDocument.getSubject().getReference())) {
log.debug("Replacing and replaced document do not have the same patientid {} and {}",
replacedDocument.getSubject().getReference(), replacingDocument.getSubject().getReference());
Expand All @@ -363,18 +358,15 @@ private DocumentReference lookupExistingDocument(String... ids) {
.where(DocumentReference.IDENTIFIER.exactly().systemAndValues(URI_URN, ids))
.cacheControl(new CacheControlDirective().setNoCache(true).setNoStore(true))
.returnBundle(Bundle.class).execute();
if (result.getEntry().isEmpty()) {
throw new XDSMetaDataException(ValidationMessage.UNRESOLVED_REFERENCE, Arrays.toString(ids));
}
metaDataAssert(!result.getEntry().isEmpty(), ValidationMessage.UNRESOLVED_REFERENCE, Arrays.toString(ids));
return (DocumentReference)result.getEntryFirstRep().getResource();
}

private void validateKnownRepository(RegisterDocumentSet register) {
register.getDocumentEntries().forEach(doc -> {
if (!registryConfig.getRepositoryEndpoint().containsKey(doc.getRepositoryUniqueId())) {
throw new XDSMetaDataException(ValidationMessage.UNKNOWN_REPOSITORY_ID, doc.getRepositoryUniqueId());
}
});
register.getDocumentEntries()
.forEach(doc -> metaDataAssert(
registryConfig.getRepositoryEndpoint().containsKey(doc.getRepositoryUniqueId()),
ValidationMessage.UNKNOWN_REPOSITORY_ID, doc.getRepositoryUniqueId()));
}

/**
Expand Down Expand Up @@ -425,9 +417,7 @@ private void assignPatientId(XDSMetaClass xdsObject) {
xdsObject.getPatientId().getId()))
.returnBundle(Bundle.class).cacheControl(new CacheControlDirective().setNoCache(true).setNoStore(true))
.execute();
if (result.getEntry().isEmpty()) {
throw new XDSMetaDataException(ValidationMessage.UNKNOWN_PATIENT_ID);
}
metaDataAssert(!result.getEntry().isEmpty(), ValidationMessage.UNKNOWN_PATIENT_ID);
xdsObject.getPatientId().setId(result.getEntryFirstRep().getResource().getIdPart());
}

Expand Down

0 comments on commit 278629c

Please sign in to comment.