Skip to content

Commit

Permalink
Parameter payload
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas0T committed Aug 29, 2024
1 parent 0e7e5ec commit 5684097
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 53 deletions.
Binary file modified README.md
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonAppend;
import de.medizininformatikinitiative.flare.model.mapping.MappingException;
import de.medizininformatikinitiative.torch.BundleCreator;
import de.medizininformatikinitiative.torch.ResourceTransformer;
import de.medizininformatikinitiative.torch.model.Crtdl;
import de.medizininformatikinitiative.torch.util.ResultFileManager;
import org.hl7.fhir.r4.model.Attachment;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Library;
import org.hl7.fhir.r4.model.Measure;
import org.hl7.fhir.r4b.model.TypeConvertor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -99,13 +99,13 @@ public Mono<ServerResponse> handleCrtdlBundle(ServerRequest request) {
return request.bodyToMono(String.class)
.switchIfEmpty(Mono.error(new IllegalArgumentException("Empty request body")))
.flatMap(body -> Mono.fromCallable(() -> {
Bundle bundle = parser.parseResource(Bundle.class, body);
if (bundle.isEmpty() && !isValidBundle(bundle)) {
logger.debug("Empty Bundle");
throw new IllegalArgumentException("Empty bundle");
Parameters parameters = parser.parseResource(Parameters.class, body);
if (parameters.isEmpty()) {
logger.debug("Empty Parameters");
throw new IllegalArgumentException("Empty Parameters");
}
Library library = extractLibraryFromBundle(bundle);
Crtdl crtdl = parseCrtdlContent(decodeCrtdlContent(library));
Crtdl crtdl = parseCrtdlContent(decodeCrtdlContent(parameters));

logger.debug("Parsed CRTDL", crtdl.getSqString());
return crtdl;
}).subscribeOn(Schedulers.boundedElastic())) // Ensure parsing and decoding are non-blocking
Expand Down Expand Up @@ -185,46 +185,6 @@ public Mono<ServerResponse> handleCrtdl(ServerRequest request) {
}


private boolean isValidBundle(Bundle bundle) {
boolean hasLibrary = false;
boolean hasMeasure = false;

for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource() instanceof Library) {
hasLibrary = true;

} else if (entry.getResource() instanceof Measure) {
hasMeasure = true;

}


}
if (hasLibrary && hasMeasure) {
return true;
}
logger.error("No library or measure");
return false;
}

private Library extractLibraryFromBundle(Bundle bundle) {
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource() instanceof Library) {
return (Library) entry.getResource();
}
}
throw new IllegalArgumentException("No Library resource found in the Bundle");
}

private Measure extractMeasureFromBundle(Bundle bundle) {
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource() instanceof Measure) {
return (Measure) entry.getResource();
}
}
throw new IllegalArgumentException("No Measure resource found in the Bundle");
}

private byte[] decodeCrtdlContent(Library library) {
for (Attachment attachment : library.getContent()) {
if ("application/crtdl+json".equals(attachment.getContentType())) {
Expand All @@ -235,6 +195,26 @@ private byte[] decodeCrtdlContent(Library library) {
throw new IllegalArgumentException("No base64 encoded CRDTL content found in Library resource");
}

private byte[] decodeCrtdlContent(Parameters parameters) {
for (Parameters.ParametersParameterComponent parameter : parameters.getParameter()) {
if ("crtdl".equals(parameter.getName())) {
logger.info("Found crtdl");
parameter.children().forEach(x-> {
logger.info(" Childname {} {}", x, x.getTypeCode());
}
);
Property valueElement = parameter.getChildByName("value[x]");

if (valueElement.hasValues()) {
Base64BinaryType value = (Base64BinaryType) valueElement.getValues().getFirst();
logger.info(" valueElement has values {}",value);
return value.getValue();
}
}
}
throw new IllegalArgumentException("No base64 encoded CRDTL content found in Library resource");
}

private Crtdl parseCrtdlContent(byte[] content) throws IOException {
// Convert byte array to string for logging and debugging
String contentString = new String(content, StandardCharsets.UTF_8);
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ torch:

logging:
level:
de.medizininformatikinitiative.torch.util: ${LOG_LEVEL:warn}
de.medizininformatikinitiative.torch: ${LOG_LEVEL:warn}
de.medizininformatikinitiative.torch.rest: ${LOG_LEVEL:warn}
de.medizininformatikinitiative.torch.util: ${LOG_LEVEL:info}
de.medizininformatikinitiative.torch: ${LOG_LEVEL:info}
de.medizininformatikinitiative.torch.rest: ${LOG_LEVEL:info}
org.springframework: ${LOG_LEVEL:info}


0 comments on commit 5684097

Please sign in to comment.