Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#560 fixed parsing error
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh Patel committed Jan 30, 2021
1 parent d2e94c0 commit 6cb0080
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
Expand Up @@ -60,10 +60,15 @@ protected ResponseEntity<String> handleDeleteResource(final Class<? extends Meta
final String version, final String owner, final String auth) {
try {
performDelete(resourceClass.getSimpleName(), id, version, owner, auth);
log.info("Finished deleting " + resourceClass + ".");
return ResponseEntity.noContent().build();
} catch (BaseServerResponseException e) {
log.error("BaseServerResponseException - " + e.getMessage());
log.error("BaseServerResponseException - " + e);
return ResponseEntity.status(e.getStatusCode()).body(e.getResponseBody());
} catch (Exception e) {
log.error("Exception - " + e.getMessage());
log.error("Exception - " + e);
return badRequest(e.getMessage());
}
}
Expand All @@ -72,14 +77,17 @@ protected ResponseEntity<String> handleFhirOperation(Parameters parameters, Clas
try {
return ResponseEntity.ok(oclFhirUtil.getResourceAsString(performFhirOperation(parameters, type, operation)));
} catch (BaseServerResponseException e) {
log.error("BaseServerResponseException - " + e.getMessage());
log.error("BaseServerResponseException - " + e);
return ResponseEntity.status(e.getStatusCode()).body(e.getResponseBody());
} catch (Exception e) {
log.error("Exception - " + e.getMessage());
log.error("Exception - " + e);
return badRequest(e.getMessage());
}
}

protected String searchResource(final Class<? extends MetadataResource> resourceClass, final String... filters) {
log.info("Building query");
IQuery q = oclFhirUtil.getClient().search().forResource(resourceClass);
if (filters.length % 2 == 0) {
for (int i = 0; i < filters.length; i += 2) {
Expand Down
Expand Up @@ -111,17 +111,13 @@ private CodeSystem toBaseCodeSystem(final Source source){
// copyright
if (isValid(source.getCopyright()))
codeSystem.setCopyright(source.getCopyright());
// content_type
// The ? value is not parsable and invalid.
if (isValid(source.getContentType())) {
Optional<String> content = Stream.of(CodeSystem.CodeSystemContentMode.values()).map(Enum::toString).filter(m -> source.getContentType().equalsIgnoreCase(m))
Optional<String> content = Stream.of(CodeSystem.CodeSystemContentMode.values()).map(Enum::toString)
.filter(m -> source.getContentType().equalsIgnoreCase(m))
.filter(m -> !m.equals(CodeSystem.CodeSystemContentMode.NULL.toCode()))
.findAny();
if (content.isPresent()) {
codeSystem.setContent(CodeSystem.CodeSystemContentMode.fromCode(content.get().toLowerCase()));
} else {
codeSystem.setContent(CodeSystem.CodeSystemContentMode.NULL);
}
} else {
codeSystem.setContent(CodeSystem.CodeSystemContentMode.NULL);
content.ifPresent(s -> codeSystem.setContent(CodeSystem.CodeSystemContentMode.fromCode(s.toLowerCase())));
}
// revision date
if (source.getRevisionDate() != null)
Expand Down Expand Up @@ -441,7 +437,7 @@ private Source toBaseSource(final CodeSystem codeSystem, final UserProfile user,
String name = isValid(codeSystem.getName()) ? codeSystem.getName() : codeSystem.getId();
source.setName(name);
// content type
if (codeSystem.getContent() != null)
if (codeSystem.getContent() != null && !codeSystem.getContent().toCode().equals(CodeSystem.CodeSystemContentMode.NULL.toCode()))
source.setContentType(codeSystem.getContent().toCode());
// copyright
if (isValid(codeSystem.getCopyright()))
Expand Down
Expand Up @@ -93,7 +93,6 @@ public static <T extends Resource> Bundle getBundle(List<T> resource, String fhi
component.setResource(r);
bundle.addEntry(component);
});
log.info("Built bundle with " + bundle.getEntry().size() + " entries.");
return bundle;
}

Expand Down
Expand Up @@ -134,7 +134,7 @@ public void testSearchCodeSystem_contentType_external() {
assertEquals(1, bundle.getTotal());
assertEquals(0, ((CodeSystem) bundle.getEntryFirstRep().getResource()).getConcept().size());
assertBaseCodeSystem((CodeSystem) bundle.getEntry().get(0).getResource(), URL_SOURCE_1, SOURCE_1_NAME, SOURCE_1_FULL_NAME,
"Jon Doe 1", "jondoe1@gmail.com", "USA", TEST_SOURCE, SOURCE_1_COPYRIGHT_TEXT, "?");
"Jon Doe 1", "jondoe1@gmail.com", "USA", TEST_SOURCE, SOURCE_1_COPYRIGHT_TEXT, null);
}

@Test
Expand All @@ -148,7 +148,7 @@ public void testSearchCodeSystem_contentType_null() {
assertEquals(1, bundle.getTotal());
assertEquals(0, ((CodeSystem) bundle.getEntryFirstRep().getResource()).getConcept().size());
assertBaseCodeSystem((CodeSystem) bundle.getEntry().get(0).getResource(), URL_SOURCE_1, SOURCE_1_NAME, SOURCE_1_FULL_NAME,
"Jon Doe 1", "jondoe1@gmail.com", "USA", TEST_SOURCE, SOURCE_1_COPYRIGHT_TEXT, "?");
"Jon Doe 1", "jondoe1@gmail.com", "USA", TEST_SOURCE, SOURCE_1_COPYRIGHT_TEXT, null);
}

@Test
Expand Down Expand Up @@ -779,6 +779,7 @@ private void assertBaseCodeSystem(CodeSystem system, String url, String name, St
assertEquals(jurisdictionCode, system.getJurisdictionFirstRep().getCodingFirstRep().getCode());
assertEquals(purpose, system.getPurpose());
assertEquals(copyright, system.getCopyright());
assertEquals(contentType, system.getContent().toCode());
if (system.getContent() != null)
assertEquals(contentType, system.getContent().toCode());
}
}

0 comments on commit 6cb0080

Please sign in to comment.