From 278629c6d8f7478e29798918318ddd90c75b90b9 Mon Sep 17 00:00:00 2001 From: Thomas Papke Date: Mon, 20 May 2024 17:56:31 +0200 Subject: [PATCH] Minor codestyle fixes --- .../registry/query/StoredQueryVistorImpl.java | 20 +++--- .../register/RegisterDocumentsProcessor.java | 64 ++++++++----------- 2 files changed, 37 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/openehealth/app/xdstofhir/registry/query/StoredQueryVistorImpl.java b/src/main/java/org/openehealth/app/xdstofhir/registry/query/StoredQueryVistorImpl.java index 901f293..a9ad6fc 100644 --- a/src/main/java/org/openehealth/app/xdstofhir/registry/query/StoredQueryVistorImpl.java +++ b/src/main/java/org/openehealth/app/xdstofhir/registry/query/StoredQueryVistorImpl.java @@ -331,7 +331,7 @@ private List collectAssociationsOfSubmissionSet( IQuery submissionSetfhirQuery) { var xdsAssocations = new ArrayList(); 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) { @@ -341,8 +341,8 @@ private List collectAssociationsOfSubmissionSet( xdsAssocations.add(new Association(AssociationType.HAS_MEMBER, assocEntryUuid, entryUuidFrom(submission),entry.getItem().getIdentifier().getValue())); } - }); - }); + }) + ); return xdsAssocations; } @@ -350,15 +350,15 @@ private List collectAssociationsOfSubmissionSet( private List collectAssociationsOfFolders(IQuery folderFhirQuery) { var xdsAssocations = new ArrayList(); 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; } @@ -370,10 +370,10 @@ private List collectAssociationsOfDocument(IQuery 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() @@ -527,7 +527,7 @@ private void mapAssociations(List associations) { } private List mapSubmissionSets(Iterable fhirSubmissions) { - return mapSubmissionSets(fhirSubmissions, (sub) -> true); + return mapSubmissionSets(fhirSubmissions, sub -> true); } private List mapSubmissionSets(Iterable fhirSubmissions, Predicate xdsSubmissionSetCriteria) { diff --git a/src/main/java/org/openehealth/app/xdstofhir/registry/register/RegisterDocumentsProcessor.java b/src/main/java/org/openehealth/app/xdstofhir/registry/register/RegisterDocumentsProcessor.java index 3db2645..ee3f891 100644 --- a/src/main/java/org/openehealth/app/xdstofhir/registry/register/RegisterDocumentsProcessor.java +++ b/src/main/java/org/openehealth/app/xdstofhir/registry/register/RegisterDocumentsProcessor.java @@ -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; @@ -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); } /** @@ -182,17 +181,17 @@ private List createUpdateOfExistingFolders(List 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); @@ -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(); } @@ -225,9 +222,8 @@ private List 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)); @@ -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()); @@ -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())); } /** @@ -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()); }