diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java index c66a8663312..8ab09545a6d 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java @@ -179,9 +179,16 @@ public class FhirTerser { switch (theDefinition.getChildType()) { case PRIMITIVE_XHTML: case PRIMITIVE_DATATYPE: - case RESOURCE_REF: // These are primitive types break; + case RESOURCE_REF: + ResourceReferenceDt resRefDt = (ResourceReferenceDt)theElement; + if (resRefDt.getReference().getValue() == null && resRefDt.getResource() != null) { + IResource theResource = resRefDt.getResource(); + BaseRuntimeElementCompositeDefinition def = myContext.getResourceDefinition(theResource); + visit(theResource, null, def, theCallback); + } + break; case RESOURCE_BLOCK: case COMPOSITE_DATATYPE: case RESOURCE: { diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/AdverseReactionAuditor.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/AdverseReactionAuditor.java new file mode 100644 index 00000000000..9c935f3cb46 --- /dev/null +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/AdverseReactionAuditor.java @@ -0,0 +1,65 @@ +package ca.uhn.fhir.rest.server.audit; + +import java.util.HashMap; +import java.util.Map; + +import ca.uhn.fhir.model.base.composite.BaseIdentifierDt; +import ca.uhn.fhir.model.dstu.resource.AdverseReaction; +import ca.uhn.fhir.model.dstu.valueset.SecurityEventObjectSensitivityEnum; +import ca.uhn.fhir.model.dstu.valueset.SecurityEventObjectTypeEnum; + +public class AdverseReactionAuditor implements IResourceAuditor { + + private AdverseReaction myResource = null; + + @Override + public AdverseReaction getResource() { + return myResource; + } + + @Override + public void setResource(AdverseReaction resource) { + myResource = resource; + } + + @Override + public boolean isAuditable() { + return myResource != null; + } + + @Override + public String getName() { + if(myResource == null) return null; + return "AdverseReaction:" + myResource.getIdentifierFirstRep().getValue(); + } + + @Override + public BaseIdentifierDt getIdentifier() { + if(myResource == null) return null; + return myResource.getIdentifierFirstRep(); + } + + @Override + public SecurityEventObjectTypeEnum getType() { + return SecurityEventObjectTypeEnum.OTHER; + } + + @Override + public String getDescription() { + return null; + } + + @Override + public Map getDetail() { + Map details = new HashMap(); + details.put("subject", myResource.getSubject().getReference().getValue()); + details.put("version", myResource.getId().getVersionIdPart()); + return details; + } + + @Override + public SecurityEventObjectSensitivityEnum getSensitivity() { + return null; + } + +} diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/DiagnosticReportAuditor.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/DiagnosticReportAuditor.java index 32a39c57125..c13cb74055e 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/DiagnosticReportAuditor.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/DiagnosticReportAuditor.java @@ -78,6 +78,7 @@ public class DiagnosticReportAuditor implements IResourceAuditor details = new HashMap(); details.put("dateIssued", myDiagnosticReport.getIssued().getValueAsString()); details.put("version", myDiagnosticReport.getId().getVersionIdPart()); + details.put("subject", myDiagnosticReport.getSubject().getReference().getValue()); return details; } diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/EncounterAuditor.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/EncounterAuditor.java index 34ea305dd5e..0fd8d97d1fc 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/EncounterAuditor.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/EncounterAuditor.java @@ -91,6 +91,7 @@ public class EncounterAuditor implements IResourceAuditor { details.put("service", myEncounter.getServiceProvider().getDisplay().getValue()); details.put("type", myEncounter.getTypeFirstRep().getText().getValue()); details.put("status", myEncounter.getStatus().getValueAsString()); + details.put("subject", myEncounter.getSubject().getReference().getValue()); return details; } diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/MedicationPrescriptionAuditor.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/MedicationPrescriptionAuditor.java index 58122c3b0f8..ed1704b26e3 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/MedicationPrescriptionAuditor.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/MedicationPrescriptionAuditor.java @@ -81,7 +81,7 @@ public class MedicationPrescriptionAuditor implements IResourceAuditor getDetail() { - return null; //no additional details required for audit? + return null; //no additional details required for audit } @Override diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/ObservationAuditor.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/ObservationAuditor.java new file mode 100644 index 00000000000..fa4a0467b8a --- /dev/null +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/ObservationAuditor.java @@ -0,0 +1,66 @@ +package ca.uhn.fhir.rest.server.audit; + +import java.util.HashMap; +import java.util.Map; + +import ca.uhn.fhir.model.base.composite.BaseIdentifierDt; +import ca.uhn.fhir.model.dstu.resource.Observation; +import ca.uhn.fhir.model.dstu.valueset.SecurityEventObjectSensitivityEnum; +import ca.uhn.fhir.model.dstu.valueset.SecurityEventObjectTypeEnum; + +public class ObservationAuditor implements IResourceAuditor { + + private Observation myResource = null; + + @Override + public Observation getResource() { + return myResource; + } + + @Override + public void setResource(Observation resource) { + myResource = resource; + } + + @Override + public boolean isAuditable() { + return myResource != null; + } + + @Override + public String getName() { + if(myResource == null) return null; + return "Observation:" + myResource.getName().getCodingFirstRep().getCode().getValue(); + } + + @Override + public BaseIdentifierDt getIdentifier() { + return myResource.getIdentifier(); + } + + @Override + public SecurityEventObjectTypeEnum getType() { + return SecurityEventObjectTypeEnum.OTHER; + } + + @Override + public String getDescription() { + return null; + } + + @Override + public Map getDetail() { + if(myResource == null) return null; + Map details = new HashMap(); + details.put("dateIssued", myResource.getIssued().getValueAsString()); + details.put("version", myResource.getId().getVersionIdPart()); + details.put("subject", myResource.getSubject().getReference().getValue()); + return details; + } + + @Override + public SecurityEventObjectSensitivityEnum getSensitivity() { + return null; + } + +} diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/ProcedureAuditor.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/ProcedureAuditor.java new file mode 100644 index 00000000000..6ec9aa739f6 --- /dev/null +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/rest/server/audit/ProcedureAuditor.java @@ -0,0 +1,66 @@ +package ca.uhn.fhir.rest.server.audit; + +import java.util.HashMap; +import java.util.Map; + +import ca.uhn.fhir.model.base.composite.BaseIdentifierDt; +import ca.uhn.fhir.model.dstu.composite.IdentifierDt; +import ca.uhn.fhir.model.dstu.resource.Procedure; +import ca.uhn.fhir.model.dstu.valueset.SecurityEventObjectSensitivityEnum; +import ca.uhn.fhir.model.dstu.valueset.SecurityEventObjectTypeEnum; + +public class ProcedureAuditor implements IResourceAuditor { + + private Procedure myResource = null; + + @Override + public Procedure getResource() { + return myResource; + } + + @Override + public void setResource(Procedure resource) { + myResource = resource; + } + + @Override + public boolean isAuditable() { + return myResource != null; + } + + @Override + public String getName() { + if(myResource == null) return null; + return "Procedure:" + myResource.getId().getIdPart(); + } + + @Override + public BaseIdentifierDt getIdentifier() { + if(myResource == null) return null; + return new IdentifierDt(myResource.getId().getResourceType(), myResource.getId().getIdPart()); + } + + @Override + public SecurityEventObjectTypeEnum getType() { + return SecurityEventObjectTypeEnum.OTHER; + } + + @Override + public String getDescription() { + return null; + } + + @Override + public Map getDetail() { + if(myResource == null) return null; + Map details = new HashMap(); + details.put("subject", myResource.getSubject().getReference().getValue()); + return details; + } + + @Override + public SecurityEventObjectSensitivityEnum getSensitivity() { + return null; + } + +} diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java index ef0fde36220..ca8c2cb2ce8 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java @@ -12,13 +12,20 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + + import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.Bundle; +import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.composite.CodeableConceptDt; +import ca.uhn.fhir.model.dstu.composite.CodingDt; import ca.uhn.fhir.model.dstu.composite.HumanNameDt; import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; import ca.uhn.fhir.model.dstu.resource.Composition; import ca.uhn.fhir.model.dstu.resource.Composition.Section; import ca.uhn.fhir.model.dstu.resource.Condition; +import ca.uhn.fhir.model.dstu.resource.DiagnosticReport; +import ca.uhn.fhir.model.dstu.resource.Observation; import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.model.dstu.resource.Practitioner; import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum; @@ -26,6 +33,7 @@ import ca.uhn.fhir.model.dstu.valueset.ConditionStatusEnum; import ca.uhn.fhir.model.dstu.valueset.NameUseEnum; import ca.uhn.fhir.model.dstu.valueset.PractitionerRoleEnum; import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.rest.server.RestfulServer; /** * Initially contributed by Alexander Kley for bug #29 @@ -155,5 +163,84 @@ public class ContainedResourceEncodingTest { Assert.assertArrayEquals(expectedCompXml.getBytes(), actualCompXml.getBytes()); } + + + @Test + public void testBundleWithContained() { + + DiagnosticReport dr = new DiagnosticReport(); + dr.setId(new IdDt("DiagnosticReport","123")); + + Observation observation = new Observation(); + + CodeableConceptDt obsName = new CodeableConceptDt(); + obsName.setText("name"); + observation.setName(obsName); + + ResourceReferenceDt result = dr.addResult(); + result.setResource(observation); + + ArrayList performers = new ArrayList(); + ResourceReferenceDt performer = new ResourceReferenceDt(); + + Practitioner p = new Practitioner(); + p.setId(new IdDt(UUID.randomUUID().toString())); + p.addIdentifier().setSystem("DoctorID").setValue("4711"); + p.addRole(PractitionerRoleEnum.DOCTOR); + p.setName(new HumanNameDt().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); + + performer.setResource(p); + performers.add(performer); + observation.setPerformer(performers); + + + List list = new ArrayList(); + list.add(dr); + Bundle bundle = RestfulServer.createBundleFromResourceList(new FhirContext(), null, list, null, null, 0); + + IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); + String xml = parser.encodeBundleToString(bundle); + Assert.assertTrue(xml.contains("Mueller")); + + } + + @Test + public void testBundleWithContainedWithNoIdDt() { + + DiagnosticReport dr = new DiagnosticReport(); + dr.setId(new IdDt("DiagnosticReport","123")); + + Observation observation = new Observation(); + + CodeableConceptDt obsName = new CodeableConceptDt(); + obsName.setText("name"); + observation.setName(obsName); + + ResourceReferenceDt result = dr.addResult(); + result.setResource(observation); + + ArrayList performers = new ArrayList(); + ResourceReferenceDt performer = new ResourceReferenceDt(); + + Practitioner p = new Practitioner(); + // no idDt on practitioner p + p.addIdentifier().setSystem("DoctorID").setValue("4711"); + p.addRole(PractitionerRoleEnum.DOCTOR); + p.setName(new HumanNameDt().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); + + performer.setResource(p); + performers.add(performer); + observation.setPerformer(performers); + + + List list = new ArrayList(); + list.add(dr); + Bundle bundle = RestfulServer.createBundleFromResourceList(new FhirContext(), null, list, null, null, 0); + + IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); + String xml = parser.encodeBundleToString(bundle); + Assert.assertTrue(xml.contains("Mueller")); + + } }