Open kthaya opened 5 years ago
I'm not sure I follow- Could you please provide a code snippet which demonstrates this issue?
import odl.ca.uhn.fhir_2_5.context.FhirContext;
import odl.org.hl7.fhir_2_5.dstu3.model.Bundle;
import odl.ca.uhn.fhir_2_5.parser.IParser;
public class HapiSetIdTest {
public static void main(String[] args) throws Exception {
FhirContext ctxDstu2 = FhirContext.forDstu3();
String input = "<Bundle xmlns=\"http://hl7.org/fhir\"><id value=\"bundle-example\" /><entry><fullUrl value=\"https://example.com/base/MedicationRequest/3123\"/>"
+ "<resource><MedicationRequest></MedicationRequest></resource></entry></Bundle>";
IParser parser = ctxDstu2.newXmlParser();
Bundle output = (Bundle) parser.parseResource(input);
System.out.println(parser.encodeResourceToString(output));
}
}
Question is why output has id tag \
Output
<Bundle xmlns="http://hl7.org/fhir"><id value="bundle-example"></id><entry><fullUrl value="https://example.com/base/MedicationRequest/3123"></fullUrl><resource><MedicationRequest xmlns="http://hl7.org/fhir"><id value="3123"></id></MedicationRequest></resource></entry></Bundle>
Input
<Bundle xmlns="http://hl7.org/fhir"><id value="bundle-example"/><entry><fullUrl value="https://example.com/base/MedicationRequest/3123"/><resource><MedicationRequest></MedicationRequest></resource></entry></Bundle>
That 3123 comes from the fullUrl
tag. It is by design, since that is the purpose of that field.
Thanks, when I look at FHIR spec identity is still optional (0..1) - https://www.hl7.org/fhir/medicationrequest-definitions.html#MedicationRequest.identifier
FYI: MedicationRequest.identifier
is different from MedicationRequest.id
The id field is optional too, but certainly in this specific use case, if you're parsing a Bundle that provides an ID via the fullUrl
field, I believe it's the right behaviour to respect it. Can you not just clear it if manually after parsing you need different behaviour?
Describe the bug When a message string converted from JSON to XML or XML to JSON, ID is always added to output even input message doesn't have id. I don't see anywhere in FHIR specification to mention that ID is mandatory.
To Reproduce
Expected behavior Output should not contain ID tag
Environment (please complete the following information):