Hapi FHIR Bundle - 资源不包含 id 元素
Hapi FHIR Bundle - Resource doesn't contain id element
我正在尝试生成一个包含 diagnosticReport 和多个关联媒体的包。但是,我无法设法让生成的包包含媒体资源的 id 元素 (entry[i]/resource/id).
我生成了这样的诊断报告和媒体:
protected Media createMedia(String patientID, DatasetFile datasetFile, Thumbnail thumbnail) {
Media media = new Media();
media.setId(IdType.newRandomUuid());
media.setStatus(Media.MediaStatus.COMPLETED);
media.setHeight(thumbnail.height);
media.setWidth(thumbnail.width);
media.getCreatedDateTimeType().setValue(DateTime.now().toDate());
media.getSubject().setReference("Patient/" + patientID);
media.getSubject().setType("Patient");
Identifier identifier = media.addIdentifier();
identifier.setSystem(testSystem);
identifier.setValue(datasetFile.getGlobalId().toString());
media.getType().addCoding()
.setSystem("http://hl7.org/fhir/ValueSet/media-type")
.setCode("image");
media.getContent()
.setTitle(thumbnail.fileName)
.setContentType(thumbnail.contentType)
.setData(thumbnail.imageContent);
return media;
}
protected DiagnosticReport createDiagnosticReport(String patientID, Long globalMessageId, Dataset dataset, Map<DatasetFile, Media> medias) {
DiagnosticReport diagnosticReport = new DiagnosticReport();
diagnosticReport.setId(IdType.newRandomUuid());
diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.FINAL);
diagnosticReport.getText().getDiv().setValueAsString("TBD");
diagnosticReport.getText().setStatus(Narrative.NarrativeStatus.ADDITIONAL);
diagnosticReport.getCode()
.addCoding()
.setSystem("http://loinc.org")
.setCode("10197-2")
.setDisplay("Physical findings of Eye Narrative");
diagnosticReport.getSubject().setReference("Patient/" + patientID);
diagnosticReport.getEffectiveDateTimeType().setValue(DateTime.now().toDate());
Identifier identifier = diagnosticReport.addIdentifier();
identifier.setSystem(testSystem);
identifier.setValue(dataset.getGlobalId().toString());
medias.values().stream().forEach(m -> {
DiagnosticReport.DiagnosticReportMediaComponent mediaRep = diagnosticReport.addMedia();
mediaRep.getLink().setReference(m.getIdElement().getValue());
mediaRep.getLink().setType("Media");
});
return diagnosticReport;
}
这是我用来将诊断报告和媒体放入包中的代码:
protected void addDiagnosticReportAndMediasToBundle(Bundle bundle, DiagnosticReport diagnosticReport, Map<DatasetFile, Media> medias) {
bundle.setType(Bundle.BundleType.TRANSACTION);
bundle.addEntry()
.setResource(diagnosticReport)
.getRequest()
.setUrl("DiagnosticReport")
.setMethod(Bundle.HTTPVerb.POST);
medias.values().forEach(m -> {
Bundle.BundleEntryComponent bundleEntryComponent = bundle.addEntry();
bundleEntryComponent.setResource(m);
// bundleEntryComponent.setId(m.getId());
bundleEntryComponent.getRequest()
.setUrl("Media")
.setMethod(Bundle.HTTPVerb.POST);
});
}
这导致以下片段(摘录):
{
"resourceType": "Bundle",
"type": "transaction",
"entry": [ {
"resource": {
"resourceType": "DiagnosticReport",
"text": {
"status": "additional",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">TBD</div>"
},
"identifier": [ {
"system": "http://test.com/my",
"value": "10"
} ],
"status": "final",
"code": {
"coding": [ {
"system": "http://loinc.org",
"code": "10197-2",
"display": "Physical findings of Eye Narrative"
} ]
},
"subject": {
"reference": "Patient/559d0494ddd50c0e847e14b5"
},
"effectiveDateTime": "2021-03-17T19:41:11+01:00",
"media": [ {
"link": {
"reference": "urn:uuid:67f3d12d-85f2-412c-bcd7-ab1f55acb63a",
"type": "Media"
}
} ]
},
"request": {
"method": "POST",
"url": "DiagnosticReport"
}
},
{
"resource": {
"resourceType": "Media",
"identifier": [ {
"system": "http://test.com/my",
"value": "1616"
} ],
"status": "completed",
"type": {
"coding": [ {
"system": "http://hl7.org/fhir/ValueSet/media-type",
"code": "image"
} ]
},
"subject": {
"reference": "Patient/559d0494ddd50c0e847e14b5",
"type": "Patient"
},
"createdDateTime": "2021-03-17T19:41:11+01:00",
"height": 200,
"width": 200,
"content": {
"contentType": "image/jpeg",
"data": "/9j/4AAQSkZJRgABAgEAYABgAAD(...)",
"title": "dummy image.jpg"
}
},
"request": {
"method": "POST",
"url": "Media"
}
} ]
}
媒体的随机uuid出现在diagnosticReport条目[i]/resource/media[j]/link/reference
调用 m.setId 或 m.setIdElement 没有按预期更改任何内容。
这是 FHIR 的预期行为吗?在我的示例中,我只有一个媒体,但如果有 2 个,我将无法识别哪个媒体是哪个?
谢谢!
- 您的媒体资源上没有 ID。
“资源”:{
“资源类型”:“媒体”,
"id": "1234", ...
- 媒体中的参考资料不适合您的申请。它不应该使用骨灰盒,而是对媒体资源的引用
“媒体”:[{
“link”:{
"参考": "Media34",
“类型”:“媒体”
}
} ]
使用 media.setId(IdType.newRandomUuid());
无效。如果我将任何静态字符串作为参数传递,它会按预期工作。
我正在尝试生成一个包含 diagnosticReport 和多个关联媒体的包。但是,我无法设法让生成的包包含媒体资源的 id 元素 (entry[i]/resource/id).
我生成了这样的诊断报告和媒体:
protected Media createMedia(String patientID, DatasetFile datasetFile, Thumbnail thumbnail) {
Media media = new Media();
media.setId(IdType.newRandomUuid());
media.setStatus(Media.MediaStatus.COMPLETED);
media.setHeight(thumbnail.height);
media.setWidth(thumbnail.width);
media.getCreatedDateTimeType().setValue(DateTime.now().toDate());
media.getSubject().setReference("Patient/" + patientID);
media.getSubject().setType("Patient");
Identifier identifier = media.addIdentifier();
identifier.setSystem(testSystem);
identifier.setValue(datasetFile.getGlobalId().toString());
media.getType().addCoding()
.setSystem("http://hl7.org/fhir/ValueSet/media-type")
.setCode("image");
media.getContent()
.setTitle(thumbnail.fileName)
.setContentType(thumbnail.contentType)
.setData(thumbnail.imageContent);
return media;
}
protected DiagnosticReport createDiagnosticReport(String patientID, Long globalMessageId, Dataset dataset, Map<DatasetFile, Media> medias) {
DiagnosticReport diagnosticReport = new DiagnosticReport();
diagnosticReport.setId(IdType.newRandomUuid());
diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.FINAL);
diagnosticReport.getText().getDiv().setValueAsString("TBD");
diagnosticReport.getText().setStatus(Narrative.NarrativeStatus.ADDITIONAL);
diagnosticReport.getCode()
.addCoding()
.setSystem("http://loinc.org")
.setCode("10197-2")
.setDisplay("Physical findings of Eye Narrative");
diagnosticReport.getSubject().setReference("Patient/" + patientID);
diagnosticReport.getEffectiveDateTimeType().setValue(DateTime.now().toDate());
Identifier identifier = diagnosticReport.addIdentifier();
identifier.setSystem(testSystem);
identifier.setValue(dataset.getGlobalId().toString());
medias.values().stream().forEach(m -> {
DiagnosticReport.DiagnosticReportMediaComponent mediaRep = diagnosticReport.addMedia();
mediaRep.getLink().setReference(m.getIdElement().getValue());
mediaRep.getLink().setType("Media");
});
return diagnosticReport;
}
这是我用来将诊断报告和媒体放入包中的代码:
protected void addDiagnosticReportAndMediasToBundle(Bundle bundle, DiagnosticReport diagnosticReport, Map<DatasetFile, Media> medias) {
bundle.setType(Bundle.BundleType.TRANSACTION);
bundle.addEntry()
.setResource(diagnosticReport)
.getRequest()
.setUrl("DiagnosticReport")
.setMethod(Bundle.HTTPVerb.POST);
medias.values().forEach(m -> {
Bundle.BundleEntryComponent bundleEntryComponent = bundle.addEntry();
bundleEntryComponent.setResource(m);
// bundleEntryComponent.setId(m.getId());
bundleEntryComponent.getRequest()
.setUrl("Media")
.setMethod(Bundle.HTTPVerb.POST);
});
}
这导致以下片段(摘录):
{
"resourceType": "Bundle",
"type": "transaction",
"entry": [ {
"resource": {
"resourceType": "DiagnosticReport",
"text": {
"status": "additional",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">TBD</div>"
},
"identifier": [ {
"system": "http://test.com/my",
"value": "10"
} ],
"status": "final",
"code": {
"coding": [ {
"system": "http://loinc.org",
"code": "10197-2",
"display": "Physical findings of Eye Narrative"
} ]
},
"subject": {
"reference": "Patient/559d0494ddd50c0e847e14b5"
},
"effectiveDateTime": "2021-03-17T19:41:11+01:00",
"media": [ {
"link": {
"reference": "urn:uuid:67f3d12d-85f2-412c-bcd7-ab1f55acb63a",
"type": "Media"
}
} ]
},
"request": {
"method": "POST",
"url": "DiagnosticReport"
}
},
{
"resource": {
"resourceType": "Media",
"identifier": [ {
"system": "http://test.com/my",
"value": "1616"
} ],
"status": "completed",
"type": {
"coding": [ {
"system": "http://hl7.org/fhir/ValueSet/media-type",
"code": "image"
} ]
},
"subject": {
"reference": "Patient/559d0494ddd50c0e847e14b5",
"type": "Patient"
},
"createdDateTime": "2021-03-17T19:41:11+01:00",
"height": 200,
"width": 200,
"content": {
"contentType": "image/jpeg",
"data": "/9j/4AAQSkZJRgABAgEAYABgAAD(...)",
"title": "dummy image.jpg"
}
},
"request": {
"method": "POST",
"url": "Media"
}
} ]
}
媒体的随机uuid出现在diagnosticReport条目[i]/resource/media[j]/link/reference
调用 m.setId 或 m.setIdElement 没有按预期更改任何内容。
这是 FHIR 的预期行为吗?在我的示例中,我只有一个媒体,但如果有 2 个,我将无法识别哪个媒体是哪个?
谢谢!
- 您的媒体资源上没有 ID。
“资源”:{ “资源类型”:“媒体”, "id": "1234", ...
- 媒体中的参考资料不适合您的申请。它不应该使用骨灰盒,而是对媒体资源的引用
“媒体”:[{ “link”:{ "参考": "Media34", “类型”:“媒体” } } ]
使用 media.setId(IdType.newRandomUuid());
无效。如果我将任何静态字符串作为参数传递,它会按预期工作。