This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #303 from MeasureAuthoringTool/feature/MAT-2572-uc…
…um-units Feature/mat 2572 ucum units
- Loading branch information
Showing
5 changed files
with
2,199 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
mat-fhir-services/src/main/java/gov/cms/mat/fhir/services/rest/UCUMController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package gov.cms.mat.fhir.services.rest; | ||
|
||
import gov.cms.mat.fhir.services.service.UCUMValidationService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.net.URLDecoder; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
@RestController | ||
@RequestMapping(path = "/ucum") | ||
@Tag(name = "UCUM-Controller", | ||
description = "API for validating ucum codes") | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class UCUMController { | ||
private final UCUMValidationService ucumValidationService; | ||
|
||
@Operation(summary = "Validate", | ||
description = "Validate the ucum unit") | ||
@GetMapping("/{unit}") | ||
public Boolean validateCode(@PathVariable("unit") String unit) { | ||
return ucumValidationService.validate(URLDecoder.decode(unit, StandardCharsets.UTF_8)); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
mat-fhir-services/src/main/java/gov/cms/mat/fhir/services/service/UCUMValidationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package gov.cms.mat.fhir.services.service; | ||
|
||
import org.fhir.ucum.UcumEssenceService; | ||
import org.fhir.ucum.UcumException; | ||
import org.fhir.ucum.UcumService; | ||
import org.springframework.beans.InvalidPropertyException; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.io.IOException; | ||
|
||
@Service | ||
public class UCUMValidationService { | ||
@Value("classpath:ucum/ucum-essence.xml") | ||
private Resource resource; | ||
|
||
private UcumService ucumService; | ||
|
||
@PostConstruct | ||
void postConstruct() { | ||
try { | ||
ucumService = new UcumEssenceService(resource.getInputStream()); | ||
} catch (UcumException | IOException e) { | ||
throw new InvalidPropertyException(this.getClass(), "resource", e.getMessage()); | ||
} | ||
} | ||
|
||
public Boolean validate(String unit) { | ||
String result = ucumService.validate(unit); | ||
|
||
//Returns:null if valid | ||
return result == null; | ||
} | ||
} |
Oops, something went wrong.