I'm checking FHIR-dstu3 but it is not working .

670 views
Skip to first unread message

Sunghwan Cho

unread,
May 19, 2017, 1:06:35 AM5/19/17
to HAPI FHIR
I'm checking FHIR-dstu3 but it is not working .

I checked Fhir-dstu2 client example using hapi-dstu2 server (http://hapifhir.io/doc_rest_client_examples.html)

but the fhir dstu3 is not working...

i did not received the server response.

this is my source

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()
     .setSystem("http://acme.org/mrns")
     .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()
        .setSystem("http://loinc.org")
        .setCode("789-8")
        .setDisplay("Erythrocytes [#/volume] in Blood by Automated count");
  observation.setValue(
  new Quantity()
     .setValue(4.12)
     .setUnit("10 trillion/L")
     .setSystem("http://unitsofmeasure.org")
     .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")
     .setIfNoneExist("identifier=http://acme.org/mrns|12345")
     .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
IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3");

Bundle resp = client.transaction().withBundle(bundle).execute();
 
// Log the response
System.out.println(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp));
  
   }

}


I can see creates the following transaction bundle. 

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. 

James Agnew

unread,
May 19, 2017, 11:53:16 AM5/19/17
to Sunghwan Cho, HAPI FHIR
The key here is this part of the error:

> Failed to CREATE resource with match URL "identifier=http://acme.org/mrns|12345" because this search matched 40 resources

You can only do a conditional create if there are 0..1 existing resources on the server that match the criteria, and in this case there are 40.

Try using a different identifier than 12345.

Cheers,
James


--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+unsubscribe@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/5fcb5a7a-a8d0-4a85-9cae-7541eb4a9f82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sunghwan Cho

unread,
May 21, 2017, 7:37:38 PM5/21/17
to HAPI FHIR, health...@gmail.com
Thank you for your help. 
I understand. 

2017년 5월 20일 토요일 오전 12시 53분 16초 UTC+9, James Agnew 님의 말:
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages