我正在检查如何使用 MDHT 库来验证 C-CDA 文档,查看当前的实现,为我的项目创建验证 Web 服务。我首先制作了一个 Eclipse 本地 Java 项目,将 JAR 添加到类路径中,并实现代码。执行成功。但是,当我将相同的代码复制到我的 Web 项目(使用 Spring Boot 制作)并发送执行此类代码的请求时,程序会失败。
为了更好地解释,我做了以下最小方法:
public void executeMDHTCode(byte[] fileContents) {
System.out.println(Arrays.toString(fileContents));
ValidationResult result = new ValidationResult();
ClinicalDocument doc = null;
try {
ConsolPackage.eINSTANCE.eClass();
doc = CDAUtil.load(new ByteArrayInputStream(fileContents), result);
} catch (ClassCastException|SAXParseException|Resource.IOWrappedException e) {
doc = null;
} catch (Exception e) {
throw new RuntimeException("Unknown error: " + e.getMessage(), e);
}
}
然后我在我的测试项目中的以下主要方法中使用它
public static void main(String[] args) throws IOException {
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
int b = -1;
InputStream stream = AppTest.class.getResourceAsStream("xml_ccda_invalid.xml");
while((b = stream.read()) != -1) {
outstr.write(b);
}
executeMDHTCode(outstr.toByteArray()); // only added 'static'
}
然后在我的服务器项目中使用相同的代码(将其封装ccdaService
在
@RequestMapping(/*POST endpoint properties*/)
public ResponseEntity<Object> validateCCDAFile(@RequestBody MultipartFile file) throws IOException {
ccdaService.executeMDHTCode(file.getBytes());
return null;
}
在这两种情况下要测试的文档xml_ccda_invalid.xml
包含以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<ClinicalDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:hl7-org:v3" xsi:schemaLocation="urn:hl7-org:v3 CDA.xsd">
<realmCode code="US"/>
</ClinicalDocument>
正如我所说,测试项目版本正确终止。但是服务器版本抛出以下异常:
java.lang.UnsupportedOperationException: Unknown type ([vocab, ActClinicalDocument, DOCCLIN])
at org.eclipse.mdht.uml.cda.operations.ClinicalDocumentOperations.validateClassCode(ClinicalDocumentOperations.java:133) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
at org.eclipse.mdht.uml.cda.impl.ClinicalDocumentImpl.validateClassCode(ClinicalDocumentImpl.java:1659) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
at org.eclipse.mdht.uml.cda.util.CDAValidator.validateClinicalDocument_validateClassCode(CDAValidator.java:1769) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
at org.eclipse.mdht.uml.cda.util.CDAValidator.validateClinicalDocument(CDAValidator.java:1753) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
at org.eclipse.mdht.uml.cda.util.CDAValidator.validate(CDAValidator.java:1075) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
at org.eclipse.emf.ecore.util.EObjectValidator.validate(EObjectValidator.java:324) ~[org.eclipse.emf.ecore-2.12.0.v20160420-0247.jar:?]
at org.eclipse.emf.ecore.util.Diagnostician.doValidate(Diagnostician.java:171) ~[org.eclipse.emf.ecore-2.12.0.v20160420-0247.jar:?]
at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:158) ~[org.eclipse.emf.ecore-2.12.0.v20160420-0247.jar:?]
at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:137) ~[org.eclipse.emf.ecore-2.12.0.v20160420-0247.jar:?]
at org.eclipse.emf.ecore.util.Diagnostician.validate(Diagnostician.java:108) ~[org.eclipse.emf.ecore-2.12.0.v20160420-0247.jar:?]
at org.eclipse.mdht.uml.cda.util.CDAUtil.validate(CDAUtil.java:707) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
at org.eclipse.mdht.uml.cda.util.CDAUtil.validate(CDAUtil.java:696) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
at org.eclipse.mdht.uml.cda.util.CDAUtil.performEMFValidation(CDAUtil.java:830) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
at org.eclipse.mdht.uml.cda.util.CDAUtil.load(CDAUtil.java:277) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
at org.eclipse.mdht.uml.cda.util.CDAUtil.load(CDAUtil.java:252) ~[org.eclipse.mdht.uml.cda-3.0.0.201706220503.jar:?]
at companypackage.service.impl.CCDAServiceImpl.executeMDHTCode(CCDAServiceImpl.java:109) ~[bin/:?]
at companypackage.controller.CCDAController.validateCCDAFile(CCDAController.java:32) ~[bin/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_102]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_102]
at (other spring and apache calls...)
我使用该println
语句检查输入数组的内容,它们在两种情况下都是相同的,所以这不是服务器处理文件的问题。
我不知道为什么会这样。我将服务器项目的所有 jar 放入测试项目的类路径中,它仍然可以工作,所以这不是类名冲突。它似乎只有在实际使用时才会受到干扰。
我会错过什么?