我正在使用 HAPI FHIR DSTU2HL7Org 在远程服务器中创建 MedicationOrders。对象的构造如下。
MedicationOrder[] medicationOrder = null;
MedicationOrderDataWrapper[] medicationOrderWrapper = new MedicationOrderDataToolkit().getMedicationOrderDataWrapper(wrapper);
if(medicationOrderWrapper != null)
{
medicationOrder = new MedicationOrder[medicationOrderWrapper.length];
for(int i=0; i<medicationOrderWrapper.length; i++)
{
medicationOrder[i] = new MedicationOrder();
MedicationOrderDosageInstructionComponent dosageInstruction = new MedicationOrderDosageInstructionComponent().setDose(medicationOrderWrapper[i].getDoseQuantity()).
setTiming(medicationOrderWrapper[i].getTiming()).setAdditionalInstructions(medicationOrderWrapper[i].getAdditionalInstruction());
medicationOrder[i].addDosageInstruction(dosageInstruction).setEncounterTarget(medicationOrderWrapper[i].getEncounter()).
setMedication(medicationOrderWrapper[i].getMedicationCodeableConcept()).setPatientTarget(medicationOrderWrapper[i].getPatient()).setPrescriberTarget(medicationOrderWrapper[i].getPractitioner())
.addExtension(medicationOrderWrapper[i].getExtension());
medicationOrder[i].getContained().add(medicationOrder[i].getEncounterTarget());
medicationOrder[i].getContained().add(medicationOrderWrapper[i].getOrganization());
medicationOrder[i].getContained().add(medicationOrderWrapper[i].getLocation());
medicationOrder[i].getContained().add(medicationOrder[i].getPatientTarget());
medicationOrder[i].getContained().add(medicationOrder[i].getPrescriberTarget());
medicationOrder[i].setEncounter(new Reference("#" + medicationOrder[i].getEncounterTarget().getId()))
.setPatient(new Reference("#" + medicationOrder[i].getPatientTarget().getId()).setDisplay(medicationOrder[i].getPatientTarget().getName().get(0).getText()))
.setPrescriber(new Reference("#" + medicationOrder[i].getPrescriberTarget().getId()).setDisplay(medicationOrder[i].getPrescriberTarget().getName().getText()))
.setReason(medicationOrderWrapper[i].getReasonCodeableConcept()).addIdentifier(medicationOrderWrapper[i].getCosmicIdentifier());
但是此代码会导致生成的 xml 消息中包含重复的元素。Organization 和 Location 元素分别出现 3 次和 2 次,而 Patient、Practitioner 和 Encounter 仅出现一次。
谁能解释一下?