I'm checking FHIR-dstu3 but it is not working .
but the fhir dstu3 is not working...
package example;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.Bundle.BundleType;
import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb;
import org.hl7.fhir.dstu3.model.Enumerations;
import org.hl7.fhir.dstu3.model.Observation;
import org.hl7.fhir.dstu3.model.Observation.ObservationStatus;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Quantity;
import org.hl7.fhir.dstu3.model.Reference;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.client.IGenericClient;
public class example {
public static void main(String[] args) {
Patient patient = new Patient();
patient.addIdentifier()
.setValue("12345");
patient.addName()
.setFamily("Cho")
.addGiven("sung")
.addGiven("hwan");
patient.setGender(Enumerations.AdministrativeGender.MALE);
patient.setId(IdDt.newRandomUuid());
Observation observation = new Observation();
observation.setStatus(ObservationStatus.FINAL);
observation
.getCode()
.addCoding()
.setCode("789-8")
.setDisplay("Erythrocytes [#/volume] in Blood by Automated count");
observation.setValue(
new Quantity()
.setValue(4.12)
.setUnit("10 trillion/L")
.setCode("10*12/L"));
observation.setSubject(new Reference(patient.getId()));
Bundle bundle = new Bundle();
bundle.setType(BundleType.TRANSACTION);
bundle.addEntry()
.setFullUrl(patient.getId())
.setResource(patient)
.getRequest()
.setUrl("Patient")
.setMethod(HTTPVerb.POST);
// Add the observation. This entry is a POST with no header
// (normal create) meaning that it will be created even if
// a similar resource already exists.
bundle.addEntry()
.setResource(observation)
.getRequest()
.setUrl("Observation")
.setMethod(HTTPVerb.POST);
// Log the request
FhirContext ctx = FhirContext.forDstu3();
System.out.println(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle));
// Create a client and post the transaction to the server
Bundle resp = client.transaction().withBundle(bundle).execute();
// Log the response
System.out.println(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp));
}
}
but, i can not see that log the response.
14:01:07.997 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource class: org.hl7.fhir.dstu3.model.CapabilityStatement
14:01:07.998 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource block class: org.hl7.fhir.dstu3.model.CapabilityStatement$CapabilityStatementDocumentComponent
14:01:07.999 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource block class: org.hl7.fhir.dstu3.model.CapabilityStatement$CapabilityStatementImplementationComponent
14:01:08.003 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource block class: org.hl7.fhir.dstu3.model.CapabilityStatement$CapabilityStatementRestComponent
14:01:08.004 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource block class: org.hl7.fhir.dstu3.model.CapabilityStatement$CapabilityStatementSoftwareComponent
14:01:08.005 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource block class: org.hl7.fhir.dstu3.model.CapabilityStatement$CapabilityStatementMessagingComponent
14:01:08.008 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Done scanning FHIR library, found 6 model entries in 12ms
14:01:08.880 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource block class: org.hl7.fhir.dstu3.model.CapabilityStatement$CapabilityStatementRestResourceComponent
14:01:08.883 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Done scanning FHIR library, found 1 model entries in 5ms
14:01:08.886 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource block class: org.hl7.fhir.dstu3.model.CapabilityStatement$ResourceInteractionComponent
14:01:08.887 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Done scanning FHIR library, found 1 model entries in 3ms
14:01:08.891 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource block class: org.hl7.fhir.dstu3.model.CapabilityStatement$CapabilityStatementRestResourceSearchParamComponent
14:01:08.893 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Done scanning FHIR library, found 1 model entries in 3ms
14:01:08.927 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource block class: org.hl7.fhir.dstu3.model.CapabilityStatement$SystemInteractionComponent
14:01:08.928 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Done scanning FHIR library, found 1 model entries in 2ms
14:01:08.931 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource block class: org.hl7.fhir.dstu3.model.CapabilityStatement$CapabilityStatementRestOperationComponent
14:01:08.932 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Done scanning FHIR library, found 1 model entries in 3ms
14:01:08.962 [main] DEBUG ca.uhn.fhir.rest.client.RestfulClientFactory - Server conformance statement indicates unknown FHIR version: 3.0.1
14:01:09.202 [main] DEBUG ca.uhn.fhir.util.XmlUtil - WstxOutputFactory (Woodstox) not found on classpath
14:01:09.231 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource class: org.hl7.fhir.dstu3.model.OperationOutcome
14:01:09.231 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Scanning resource block class: org.hl7.fhir.dstu3.model.OperationOutcome$OperationOutcomeIssueComponent
14:01:09.235 [main] DEBUG ca.uhn.fhir.context.ModelScanner - Done scanning FHIR library, found 2 model entries in 6ms
14:01:09.240 [main] DEBUG ca.uhn.fhir.util.XmlUtil - WstxOutputFactory (Woodstox) not found on classpath
Exception in thread "main" ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException: HTTP 412 Precondition Failed: Failed to CREATE resource with match URL "identifier=
http://acme.org/mrns|12345" because this search matched 40 resources
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException.newInstance(BaseServerResponseException.java:307)
at ca.uhn.fhir.rest.client.BaseClient.invokeClient(BaseClient.java:290)
at ca.uhn.fhir.rest.client.GenericClient$BaseClientExecutable.invoke(GenericClient.java:637)
at ca.uhn.fhir.rest.client.GenericClient$TransactionExecutable.execute(GenericClient.java:2196)
at example.example.main(example.java:81)
Please help me.