diff --git a/examples/pom.xml b/examples/pom.xml
index 5c13aa4f458..8e323c00995 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -21,7 +21,7 @@
ca.uhn.hapi.fhir
- hapi-fhir-structures-dstu
+ hapi-fhir-structures-dstu2
0.9-SNAPSHOT
diff --git a/examples/src/main/java/example/CompleteExampleClient.java b/examples/src/main/java/example/CompleteExampleClient.java
index 50f6a4263a1..1208d90b984 100644
--- a/examples/src/main/java/example/CompleteExampleClient.java
+++ b/examples/src/main/java/example/CompleteExampleClient.java
@@ -5,10 +5,10 @@ import java.io.IOException;
import java.util.List;
import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
-import ca.uhn.fhir.model.dstu.resource.Organization;
-import ca.uhn.fhir.model.dstu.resource.Patient;
+import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
+import ca.uhn.fhir.model.dstu2.resource.Organization;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.rest.annotation.RequiredParam;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.client.api.IRestfulClient;
@@ -57,7 +57,7 @@ public class CompleteExampleClient {
Organization org = (Organization) managingRef.loadResource(client);
// Print organization name
- System.out.println(org.getName().getValue());
+ System.out.println(org.getName());
}
diff --git a/examples/src/main/java/example/ExampleProviders.java b/examples/src/main/java/example/ExampleProviders.java
index 21bf37cad43..e1490ebdd75 100644
--- a/examples/src/main/java/example/ExampleProviders.java
+++ b/examples/src/main/java/example/ExampleProviders.java
@@ -1,18 +1,17 @@
package example;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import ca.uhn.fhir.model.api.Bundle;
-import ca.uhn.fhir.model.dstu.resource.Patient;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.annotation.RequiredParam;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
-@SuppressWarnings(value= {"serial","unused"})
+@SuppressWarnings(value= {"serial"})
public class ExampleProviders {
diff --git a/examples/src/main/java/example/ExampleRestfulClient.java b/examples/src/main/java/example/ExampleRestfulClient.java
index 1fa98ce45dc..3995b0e1082 100644
--- a/examples/src/main/java/example/ExampleRestfulClient.java
+++ b/examples/src/main/java/example/ExampleRestfulClient.java
@@ -3,7 +3,7 @@ package example;
import java.util.List;
import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu.resource.Patient;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.StringDt;
@SuppressWarnings("unused")
diff --git a/examples/src/main/java/example/Extensions.java b/examples/src/main/java/example/Extensions.java
index 57e2a934928..ea7fdde2d1c 100644
--- a/examples/src/main/java/example/Extensions.java
+++ b/examples/src/main/java/example/Extensions.java
@@ -5,9 +5,9 @@ import java.util.List;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.ExtensionDt;
-import ca.uhn.fhir.model.dstu.composite.HumanNameDt;
-import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
+import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
+import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.parser.DataFormatException;
@@ -21,7 +21,7 @@ public static void main(String[] args) throws DataFormatException, IOException {
// START SNIPPET: resourceExtension
// Create an example patient
Patient patient = new Patient();
-patient.addIdentifier(IdentifierUseEnum.OFFICIAL, "urn:example", "7000135", null);
+patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:example").setValue("7000135");
// Create an extension
ExtensionDt ext = new ExtensionDt();
diff --git a/examples/src/main/java/example/FhirContextIntro.java b/examples/src/main/java/example/FhirContextIntro.java
index 2d94e311c7c..32f21bcb50e 100644
--- a/examples/src/main/java/example/FhirContextIntro.java
+++ b/examples/src/main/java/example/FhirContextIntro.java
@@ -1,13 +1,11 @@
package example;
import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu.composite.HumanNameDt;
-import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
-import ca.uhn.fhir.model.dstu.resource.Observation;
-import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.dstu.valueset.NameUseEnum;
-import ca.uhn.fhir.model.primitive.CodeDt;
-import ca.uhn.fhir.model.primitive.StringDt;
+import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
+import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
+import ca.uhn.fhir.model.dstu2.resource.Observation;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
+import ca.uhn.fhir.model.dstu2.valueset.NameUseEnum;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.parser.IParser;
@@ -103,16 +101,14 @@ IParser parser = ctx.newXmlParser();
Patient patient = parser.parseResource(Patient.class, msgString);
// The patient object has accessor methods to retrieve all of the
-// data which has been parsed into the instance. All of the
-// FHIR datatypes are represented by classes which end in "Dt".
-StringDt patientId = patient.getIdentifier().get(0).getValue();
-StringDt familyName = patient.getName().get(0).getFamily().get(0);
-CodeDt gender = patient.getGender().getCoding().get(0).getCode();
+// data which has been parsed into the instance.
+String patientId = patient.getIdentifier().get(0).getValue();
+String familyName = patient.getName().get(0).getFamily().get(0).getValue();
+String gender = patient.getGender();
-// The various datatype classes have accessors called getValue()
-System.out.println(patientId.getValue()); // PRP1660
-System.out.println(familyName.getValue()); // Cardinal
-System.out.println(gender.getValue()); // M
+System.out.println(patientId); // PRP1660
+System.out.println(familyName); // Cardinal
+System.out.println(gender); // M
//END SNIPPET: parseMsg
}
diff --git a/examples/src/main/java/example/FhirDataModel.java b/examples/src/main/java/example/FhirDataModel.java
index d6020d40628..ac08660faae 100644
--- a/examples/src/main/java/example/FhirDataModel.java
+++ b/examples/src/main/java/example/FhirDataModel.java
@@ -1,16 +1,18 @@
package example;
import java.util.Date;
+import java.util.Set;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
-import ca.uhn.fhir.model.dstu.composite.CodingDt;
-import ca.uhn.fhir.model.dstu.composite.HumanNameDt;
-import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
-import ca.uhn.fhir.model.dstu.composite.PeriodDt;
-import ca.uhn.fhir.model.dstu.composite.QuantityDt;
-import ca.uhn.fhir.model.dstu.resource.Observation;
-import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum;
+import ca.uhn.fhir.model.dstu2.composite.CodingDt;
+import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
+import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
+import ca.uhn.fhir.model.dstu2.composite.PeriodDt;
+import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
+import ca.uhn.fhir.model.dstu2.resource.Observation;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
+import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
+import ca.uhn.fhir.model.dstu2.valueset.MaritalStatusCodesEnum;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.model.primitive.StringDt;
@@ -28,8 +30,8 @@ public class FhirDataModel {
// The InstantDt also lets you work with the instant as a Java Date
// object or as a FHIR String.
- Date date = obs.getIssued().getValue(); // A date object
- String dateString = obs.getIssued().getValueAsString(); // "2014-03-08T12:59:58.068-05:00"
+ Date date = obs.getIssuedElement().getValue(); // A date object
+ String dateString = obs.getIssuedElement().getValueAsString(); // "2014-03-08T12:59:58.068-05:00"
// END SNIPPET: datatypes
System.out.println(date);
@@ -47,31 +49,108 @@ public class FhirDataModel {
// child elements.
IdentifierDt identifierDt = observation.getIdentifier();
PeriodDt periodDt = observation.getIdentifier().getPeriod();
- DateTimeDt activeDt = observation.getIdentifier().getPeriod().getStart();
+ DateTimeDt activeDt = observation.getIdentifier().getPeriod().getStartElement();
// DateTimeDt is a FHIR primitive however, so the following will return
// null
// unless a value has been placed there.
- Date active = observation.getIdentifier().getPeriod().getStart().getValue();
+ Date active = observation.getIdentifier().getPeriod().getStartElement().getValue();
// END SNIPPET: nonNull
}
+ @SuppressWarnings("unused")
public static void codes() {
// START SNIPPET: codes
Patient patient = new Patient();
- // Coded types can naturally be set using plain Strings
- CodingDt genderCoding = patient.getGender().addCoding();
- genderCoding.setSystem("http://hl7.org/fhir/v3/AdministrativeGender");
- genderCoding.setCode("M");
-
- // This is equivalent to the three statements above
- patient.setGender(AdministrativeGenderCodesEnum.M);
+ // You can set this code using a String if you want. Note that
+ // for "closed" valuesets (such as the one used for Patient.gender)
+ // you must use one of the strings defined by the FHIR specification.
+ // You must not define your own.
+ patient.getGenderElement().setValue("male");
+
+ // HAPI also provides Java enumerated types which make it easier to
+ // deal with coded values. This code achieves the exact same result
+ // as the code above.
+ patient.setGender(AdministrativeGenderEnum.MALE);
+
+ // You can also retrieve coded values the same way
+ String genderString = patient.getGenderElement().getValueAsString();
+ AdministrativeGenderEnum genderEnum = patient.getGenderElement().getValueAsEnum();
+
+ // The following is a shortcut to create
+ patient.setMaritalStatus(MaritalStatusCodesEnum.M);
// END SNIPPET: codes
}
+
+ @SuppressWarnings("unused")
+ public static void codeableConcepts() {
+ // START SNIPPET: codeableConcepts
+ Patient patient = new Patient();
+
+ // Coded types can naturally be set using plain strings
+ CodingDt statusCoding = patient.getMaritalStatus().addCoding();
+ statusCoding.setSystem("http://hl7.org/fhir/v3/MaritalStatus");
+ statusCoding.setCode("M");
+ statusCoding.setDisplay("Married");
+
+ // You could add a second coding to the field if needed too. This
+ // can be useful if you want to convey the concept using different
+ // codesystems.
+ CodingDt secondStatus = patient.getMaritalStatus().addCoding();
+ secondStatus.setCode("H");
+ secondStatus.setSystem("http://example.com#maritalStatus");
+ secondStatus.setDisplay("Happily Married");
+
+ // CodeableConcept also has a text field meant to convey
+ // a user readable version of the concepts it conveys.
+ patient.getMaritalStatus().setText("Happily Married");
+
+ // There are also accessors for retrieving values
+ String firstCode = patient.getMaritalStatus().getCoding().get(0).getCode();
+ String secondCode = patient.getMaritalStatus().getCoding().get(1).getCode();
+ // END SNIPPET: codeableConcepts
+
+ }
+
+ @SuppressWarnings("unused")
+ public static void codeableConceptEnums() {
+ // START SNIPPET: codeableConceptEnums
+ Patient patient = new Patient();
+
+ // Set the CodeableConcept's first coding to use the code
+ // and codesystem associated with the M value.
+ patient.setMaritalStatus(MaritalStatusCodesEnum.M);
+
+ // If you need to set other fields (such as the display name) after
+ // using the Enum type, you may still do so.
+ patient.getMaritalStatus().getCodingFirstRep().setDisplay("Married");
+ patient.getMaritalStatus().getCodingFirstRep().setPrimary(true);
+ patient.getMaritalStatus().getCodingFirstRep().setVersion("1.0");
+
+ // You can use accessors to retrieve values from CodeableConcept fields
+
+ // Returns "M"
+ String code = patient.getMaritalStatus().getCodingFirstRep().getCode();
+
+ // Returns "http://hl7.org/fhir/v3/MaritalStatus". This value was also
+ // populated via the enum above.
+ String codeSystem = patient.getMaritalStatus().getCodingFirstRep().getCode();
+
+ // In many cases, Enum types can be used to retrieve values as well. Note that
+ // the setter takes a single type, but the getter returns a Set, because the
+ // field can technicaly contain more than one code and codesystem. BE CAREFUL
+ // when using this method however, as no Enum will be returned in the case
+ // that the field contains only a code other than the ones defined by the Enum.
+ Set status = patient.getMaritalStatus().getValueAsEnum();
+ // END SNIPPET: codeableConceptEnums
+
+ }
+
+
public static void main(String[] args) {
datatypes();
@@ -88,8 +167,8 @@ public class FhirDataModel {
observation.setValue(q);
// Set the reference range
- observation.getReferenceRangeFirstRep().setLow(100);
- observation.getReferenceRangeFirstRep().setHigh(200);
+ observation.getReferenceRangeFirstRep().setLow(new QuantityDt(100));
+ observation.getReferenceRangeFirstRep().setHigh(new QuantityDt(200));
// END SNIPPET: observation
diff --git a/examples/src/main/java/example/GenericClientExample.java b/examples/src/main/java/example/GenericClientExample.java
index bd679f52607..e8e9d6e1b72 100644
--- a/examples/src/main/java/example/GenericClientExample.java
+++ b/examples/src/main/java/example/GenericClientExample.java
@@ -8,10 +8,10 @@ import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.base.resource.BaseConformance;
import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
-import ca.uhn.fhir.model.dstu.resource.Observation;
-import ca.uhn.fhir.model.dstu.resource.Organization;
-import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum;
+import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
+import ca.uhn.fhir.model.dstu2.resource.Observation;
+import ca.uhn.fhir.model.dstu2.resource.Organization;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.client.IGenericClient;
@@ -47,7 +47,7 @@ public class GenericClientExample {
// START SNIPPET: create
Patient patient = new Patient();
// ..populate the patient object..
- patient.addIdentifier("urn:system", "12345");
+ patient.addIdentifier().setSystem("urn:system").setValue("12345");
patient.addName().addFamily("Smith").addGiven("John");
// Invoke the server create method (and send pretty-printed JSON
@@ -72,7 +72,7 @@ public class GenericClientExample {
// START SNIPPET: update
Patient patient = new Patient();
// ..populate the patient object..
- patient.addIdentifier("urn:system", "12345");
+ patient.addIdentifier().setSystem("urn:system").setValue("12345");
patient.addName().addFamily("Smith").addGiven("John");
// To update a resource, it should have an ID set (if the resource
@@ -106,7 +106,7 @@ public class GenericClientExample {
System.out.println("Version ID: " + patient.getId().getVersionIdPart());
// Now let's make a change to the resource
- patient.setGender(AdministrativeGenderCodesEnum.F);
+ patient.setGender(AdministrativeGenderEnum.FEMALE);
// Invoke the server update method - Because the resource has
// a version, it will be included in the request sent to
@@ -147,7 +147,7 @@ public class GenericClientExample {
Bundle response = client.search()
.forResource(Patient.class)
.where(Patient.BIRTHDATE.beforeOrEquals().day("2011-01-01"))
- .and(Patient.PROVIDER.hasChainedProperty(Organization.NAME.matches().value("Health")))
+ .and(Patient.CAREPROVIDER.hasChainedProperty(Organization.NAME.matches().value("Health")))
.execute();
// END SNIPPET: search
diff --git a/examples/src/main/java/example/IRestfulClient.java b/examples/src/main/java/example/IRestfulClient.java
index 5555b9394ea..b9a8ebbfd18 100644
--- a/examples/src/main/java/example/IRestfulClient.java
+++ b/examples/src/main/java/example/IRestfulClient.java
@@ -2,7 +2,7 @@ package example;
import java.util.List;
-import ca.uhn.fhir.model.dstu.resource.Patient;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.annotation.IdParam;
diff --git a/examples/src/main/java/example/MyPatient.java b/examples/src/main/java/example/MyPatient.java
index d2e91a7683c..71337774b48 100644
--- a/examples/src/main/java/example/MyPatient.java
+++ b/examples/src/main/java/example/MyPatient.java
@@ -8,7 +8,7 @@ import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.Extension;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
-import ca.uhn.fhir.model.dstu.resource.Patient;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.util.ElementUtil;
diff --git a/examples/src/main/java/example/MyPatientUse.java b/examples/src/main/java/example/MyPatientUse.java
index 1604fb237c4..3e973a3707e 100644
--- a/examples/src/main/java/example/MyPatientUse.java
+++ b/examples/src/main/java/example/MyPatientUse.java
@@ -10,7 +10,7 @@ import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.api.annotation.Extension;
import ca.uhn.fhir.model.api.annotation.ResourceDef;
-import ca.uhn.fhir.model.dstu.resource.Patient;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.parser.DataFormatException;
diff --git a/examples/src/main/java/example/Narrative.java b/examples/src/main/java/example/Narrative.java
index 5e2f37f4594..edf3a042bc1 100644
--- a/examples/src/main/java/example/Narrative.java
+++ b/examples/src/main/java/example/Narrative.java
@@ -3,8 +3,8 @@ package example;
import java.io.IOException;
import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu.valueset.NarrativeStatusEnum;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
import ca.uhn.fhir.parser.DataFormatException;
@@ -14,7 +14,7 @@ public static void main(String[] args) throws DataFormatException, IOException {
//START SNIPPET: example1
Patient patient = new Patient();
-patient.addIdentifier("urn:foo", "7000135");
+patient.addIdentifier().setSystem("urn:foo").setValue("7000135");
patient.addName().addFamily("Smith").addGiven("John").addGiven("Edward");
patient.addAddress().addLine("742 Evergreen Terrace").setCity("Springfield").setState("ZZ");
diff --git a/examples/src/main/java/example/PagingPatientProvider.java b/examples/src/main/java/example/PagingPatientProvider.java
index ac03fd3e720..d1cb53a1708 100644
--- a/examples/src/main/java/example/PagingPatientProvider.java
+++ b/examples/src/main/java/example/PagingPatientProvider.java
@@ -3,7 +3,7 @@ package example;
import java.util.List;
import ca.uhn.fhir.model.api.IResource;
-import ca.uhn.fhir.model.dstu.resource.Patient;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.rest.annotation.RequiredParam;
import ca.uhn.fhir.rest.annotation.Search;
@@ -11,7 +11,7 @@ import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.IResourceProvider;
-@SuppressWarnings("unused")
+
//START SNIPPET: provider
public class PagingPatientProvider implements IResourceProvider {
diff --git a/examples/src/main/java/example/PagingServer.java b/examples/src/main/java/example/PagingServer.java
index 83b1667f738..d4d7bed2b02 100644
--- a/examples/src/main/java/example/PagingServer.java
+++ b/examples/src/main/java/example/PagingServer.java
@@ -1,17 +1,6 @@
package example;
-import java.util.List;
-
-import ca.uhn.fhir.model.api.IResource;
-import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.primitive.InstantDt;
-import ca.uhn.fhir.rest.annotation.RequiredParam;
-import ca.uhn.fhir.rest.annotation.Search;
-import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider;
-import ca.uhn.fhir.rest.server.IBundleProvider;
-import ca.uhn.fhir.rest.server.IPagingProvider;
-import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
@SuppressWarnings({ "unused", "serial" })
diff --git a/examples/src/main/java/example/QuickUsage.java b/examples/src/main/java/example/QuickUsage.java
index de9a4cbe3af..b117d46887a 100644
--- a/examples/src/main/java/example/QuickUsage.java
+++ b/examples/src/main/java/example/QuickUsage.java
@@ -1,15 +1,14 @@
package example;
-import static ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum.OFFICIAL;
-import static ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum.SECONDARY;
-
import java.io.IOException;
import java.util.List;
import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
-import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum;
+import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
+import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
+import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.RequiredParam;
@@ -24,12 +23,12 @@ public class QuickUsage {
public static void main(String[] args) throws DataFormatException, IOException {
Patient patient = new Patient();
-patient.addIdentifier().setUse(OFFICIAL).setSystem("urn:fake:mrns").setValue("7000135");
-patient.addIdentifier().setUse(SECONDARY).setSystem("urn:fake:otherids").setValue("3287486");
+patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:fake:mrns").setValue("7000135");
+patient.addIdentifier().setUse(IdentifierUseEnum.SECONDARY).setSystem("urn:fake:otherids").setValue("3287486");
patient.addName().addFamily("Smith").addGiven("John").addGiven("Q").addSuffix("Junior");
-patient.setGender(AdministrativeGenderCodesEnum.M);
+patient.setGender(AdministrativeGenderEnum.MALE);
FhirContext ctx = new FhirContext();
diff --git a/examples/src/main/java/example/ResourceRefs.java b/examples/src/main/java/example/ResourceRefs.java
index 28729139d16..102db3a5392 100644
--- a/examples/src/main/java/example/ResourceRefs.java
+++ b/examples/src/main/java/example/ResourceRefs.java
@@ -1,8 +1,8 @@
package example;
import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.dstu.resource.Organization;
-import ca.uhn.fhir.model.dstu.resource.Patient;
+import ca.uhn.fhir.model.dstu2.resource.Organization;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
public class ResourceRefs {
@@ -17,12 +17,12 @@ public class ResourceRefs {
// Create an organization, and give it a local ID
Organization org = new Organization();
org.setId("#localOrganization");
- org.getName().setValue("Contained Test Organization");
+ org.getNameElement().setValue("Contained Test Organization");
// Create a patient
Patient patient = new Patient();
patient.setId("Patient/1333");
- patient.addIdentifier("urn:mrns", "253345");
+ patient.addIdentifier().setSystem("urn:mrns").setValue("253345");
// Set the reference, and manually add the contained resource
patient.getManagingOrganization().setReference("#localOrganization");
diff --git a/examples/src/main/java/example/RestfulObservationResourceProvider.java b/examples/src/main/java/example/RestfulObservationResourceProvider.java
index ab7e74a7232..8c2795364b4 100644
--- a/examples/src/main/java/example/RestfulObservationResourceProvider.java
+++ b/examples/src/main/java/example/RestfulObservationResourceProvider.java
@@ -3,9 +3,9 @@ package example;
import java.util.Collections;
import java.util.List;
-import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum;
-import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
+import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
+import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt;
@@ -49,7 +49,7 @@ public class RestfulObservationResourceProvider implements IResourceProvider {
patient.getIdentifier().get(0).setValue("00002");
patient.addName().addFamily("Test");
patient.getName().get(0).addGiven("PatientOne");
- patient.setGender(AdministrativeGenderCodesEnum.F);
+ patient.setGender(AdministrativeGenderEnum.FEMALE);
return patient;
}
@@ -79,7 +79,7 @@ public class RestfulObservationResourceProvider implements IResourceProvider {
patient.addName();
patient.getName().get(0).addFamily("Test");
patient.getName().get(0).addGiven("PatientOne");
- patient.getGender().setText("M");
+ patient.setGender(AdministrativeGenderEnum.MALE);
return Collections.singletonList(patient);
}
diff --git a/examples/src/main/java/example/RestfulPatientResourceProvider.java b/examples/src/main/java/example/RestfulPatientResourceProvider.java
index 6cee1480d3d..919a612ef46 100644
--- a/examples/src/main/java/example/RestfulPatientResourceProvider.java
+++ b/examples/src/main/java/example/RestfulPatientResourceProvider.java
@@ -3,9 +3,9 @@ package example;
import java.util.Collections;
import java.util.List;
-import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum;
-import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
+import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
+import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt;
@@ -50,7 +50,7 @@ public class RestfulPatientResourceProvider implements IResourceProvider {
patient.getIdentifier().get(0).setValue("00002");
patient.addName().addFamily("Test");
patient.getName().get(0).addGiven("PatientOne");
- patient.setGender(AdministrativeGenderCodesEnum.F);
+ patient.setGender(AdministrativeGenderEnum.FEMALE);
return patient;
}
@@ -80,7 +80,7 @@ public class RestfulPatientResourceProvider implements IResourceProvider {
patient.addName();
patient.getName().get(0).addFamily(theFamilyName.getValue());
patient.getName().get(0).addGiven("PatientOne");
- patient.getGender().setText("M");
+ patient.setGender(AdministrativeGenderEnum.MALE);
return Collections.singletonList(patient);
}
diff --git a/examples/src/main/java/example/RestfulPatientResourceProviderMore.java b/examples/src/main/java/example/RestfulPatientResourceProviderMore.java
index 3c4a62be824..f53638d4ec6 100644
--- a/examples/src/main/java/example/RestfulPatientResourceProviderMore.java
+++ b/examples/src/main/java/example/RestfulPatientResourceProviderMore.java
@@ -1,7 +1,6 @@
package example;
import java.io.IOException;
-import java.lang.annotation.Documented;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -20,17 +19,15 @@ import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
-import ca.uhn.fhir.rest.annotation.TagListParam;
-import ca.uhn.fhir.model.dstu.composite.CodingDt;
-import ca.uhn.fhir.model.dstu.resource.Conformance;
-import ca.uhn.fhir.model.dstu.resource.DiagnosticReport;
-import ca.uhn.fhir.model.dstu.resource.Observation;
-import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
-import ca.uhn.fhir.model.dstu.resource.Organization;
-import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
-import ca.uhn.fhir.model.dstu.valueset.IssueSeverityEnum;
+import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
+import ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum;
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
+import ca.uhn.fhir.model.dstu2.resource.Conformance;
+import ca.uhn.fhir.model.dstu2.resource.DiagnosticReport;
+import ca.uhn.fhir.model.dstu2.resource.Observation;
+import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
+import ca.uhn.fhir.model.dstu2.resource.Organization;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.DecimalDt;
import ca.uhn.fhir.model.primitive.IdDt;
@@ -52,6 +49,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.annotation.Since;
import ca.uhn.fhir.rest.annotation.Sort;
+import ca.uhn.fhir.rest.annotation.TagListParam;
import ca.uhn.fhir.rest.annotation.Transaction;
import ca.uhn.fhir.rest.annotation.TransactionParam;
import ca.uhn.fhir.rest.annotation.Update;
@@ -163,7 +161,7 @@ public List findPatients(
//START SNIPPET: referenceSimple
@Search
public List findPatientsWithSimpleReference(
- @OptionalParam(name=Patient.SP_PROVIDER) ReferenceParam theProvider
+ @OptionalParam(name=Patient.SP_CAREPROVIDER) ReferenceParam theProvider
) {
List retVal=new ArrayList();
diff --git a/examples/src/main/java/example/ServerExceptionsExample.java b/examples/src/main/java/example/ServerExceptionsExample.java
index 07fb1e0b164..471dbfd04fd 100644
--- a/examples/src/main/java/example/ServerExceptionsExample.java
+++ b/examples/src/main/java/example/ServerExceptionsExample.java
@@ -1,79 +1,13 @@
package example;
-import java.io.IOException;
-import java.lang.annotation.Documented;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-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.api.Include;
-import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
-import ca.uhn.fhir.model.api.Tag;
-import ca.uhn.fhir.model.api.TagList;
-import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
-import ca.uhn.fhir.model.api.annotation.Description;
-import ca.uhn.fhir.rest.annotation.TagListParam;
-import ca.uhn.fhir.model.dstu.composite.CodingDt;
-import ca.uhn.fhir.model.dstu.resource.Conformance;
-import ca.uhn.fhir.model.dstu.resource.DiagnosticReport;
-import ca.uhn.fhir.model.dstu.resource.Observation;
-import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
-import ca.uhn.fhir.model.dstu.resource.Organization;
-import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
-import ca.uhn.fhir.model.dstu.valueset.IssueSeverityEnum;
-import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
-import ca.uhn.fhir.model.primitive.DecimalDt;
+import ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum;
+import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
-import ca.uhn.fhir.model.primitive.InstantDt;
-import ca.uhn.fhir.parser.DataFormatException;
-import ca.uhn.fhir.rest.annotation.AddTags;
-import ca.uhn.fhir.rest.annotation.Count;
-import ca.uhn.fhir.rest.annotation.Create;
-import ca.uhn.fhir.rest.annotation.DeleteTags;
-import ca.uhn.fhir.rest.annotation.GetTags;
-import ca.uhn.fhir.rest.annotation.History;
import ca.uhn.fhir.rest.annotation.IdParam;
-import ca.uhn.fhir.rest.annotation.IncludeParam;
-import ca.uhn.fhir.rest.annotation.Metadata;
-import ca.uhn.fhir.rest.annotation.OptionalParam;
import ca.uhn.fhir.rest.annotation.Read;
-import ca.uhn.fhir.rest.annotation.RequiredParam;
-import ca.uhn.fhir.rest.annotation.ResourceParam;
-import ca.uhn.fhir.rest.annotation.Search;
-import ca.uhn.fhir.rest.annotation.Since;
-import ca.uhn.fhir.rest.annotation.Sort;
-import ca.uhn.fhir.rest.annotation.Transaction;
-import ca.uhn.fhir.rest.annotation.TransactionParam;
-import ca.uhn.fhir.rest.annotation.Update;
-import ca.uhn.fhir.rest.annotation.Validate;
-import ca.uhn.fhir.rest.api.MethodOutcome;
-import ca.uhn.fhir.rest.api.SortOrderEnum;
-import ca.uhn.fhir.rest.api.SortSpec;
-import ca.uhn.fhir.rest.client.api.IBasicClient;
-import ca.uhn.fhir.rest.client.api.IRestfulClient;
-import ca.uhn.fhir.rest.param.CompositeParam;
-import ca.uhn.fhir.rest.param.DateParam;
-import ca.uhn.fhir.rest.param.DateRangeParam;
-import ca.uhn.fhir.rest.param.QuantityParam;
-import ca.uhn.fhir.rest.param.ReferenceParam;
-import ca.uhn.fhir.rest.param.StringAndListParam;
-import ca.uhn.fhir.rest.param.StringOrListParam;
-import ca.uhn.fhir.rest.param.StringParam;
-import ca.uhn.fhir.rest.param.TokenOrListParam;
-import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
-import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
-import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
-import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
@SuppressWarnings("unused")
public abstract class ServerExceptionsExample implements IResourceProvider {
diff --git a/examples/src/main/java/example/ServerInterceptors.java b/examples/src/main/java/example/ServerInterceptors.java
index d50cefad1e9..9f72c18dab6 100644
--- a/examples/src/main/java/example/ServerInterceptors.java
+++ b/examples/src/main/java/example/ServerInterceptors.java
@@ -3,18 +3,14 @@ package example;
import java.io.IOException;
import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.ExtensionDt;
-import ca.uhn.fhir.model.dstu.composite.HumanNameDt;
-import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
+import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
+import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.parser.DataFormatException;
-import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
public class ServerInterceptors {
@@ -25,7 +21,7 @@ public static void main(String[] args) throws DataFormatException, IOException {
// START SNIPPET: resourceExtension
// Create an example patient
Patient patient = new Patient();
-patient.addIdentifier(IdentifierUseEnum.OFFICIAL, "urn:example", "7000135", null);
+patient.addIdentifier().setUse(IdentifierUseEnum.OFFICIAL).setSystem("urn:example").setValue("7000135");
// Create an extension
ExtensionDt ext = new ExtensionDt();
diff --git a/examples/src/main/java/example/ServerMetadataExamples.java b/examples/src/main/java/example/ServerMetadataExamples.java
index d9f5621e3a8..be28683b9b1 100644
--- a/examples/src/main/java/example/ServerMetadataExamples.java
+++ b/examples/src/main/java/example/ServerMetadataExamples.java
@@ -6,7 +6,7 @@ import java.util.List;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.Tag;
import ca.uhn.fhir.model.api.TagList;
-import ca.uhn.fhir.model.dstu.resource.Patient;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.rest.annotation.Search;
diff --git a/examples/src/main/java/example/TagsExamples.java b/examples/src/main/java/example/TagsExamples.java
index fd4ac010d41..57bbdce0c74 100644
--- a/examples/src/main/java/example/TagsExamples.java
+++ b/examples/src/main/java/example/TagsExamples.java
@@ -7,7 +7,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.Tag;
import ca.uhn.fhir.model.api.TagList;
-import ca.uhn.fhir.model.dstu.resource.Patient;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.client.IGenericClient;
diff --git a/examples/src/main/java/example/ValidatorExamples.java b/examples/src/main/java/example/ValidatorExamples.java
index c2460d85004..27b9bb24386 100644
--- a/examples/src/main/java/example/ValidatorExamples.java
+++ b/examples/src/main/java/example/ValidatorExamples.java
@@ -8,8 +8,8 @@ import org.apache.commons.io.filefilter.WildcardFileFilter;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
-import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.dstu.valueset.ContactSystemEnum;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
+import ca.uhn.fhir.model.dstu2.valueset.ContactPointSystemEnum;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.ValidationResult;
@@ -23,8 +23,8 @@ public class ValidatorExamples {
// Create and populate a new patient object
Patient p = new Patient();
p.addName().addFamily("Smith").addGiven("John").addGiven("Q");
- p.addIdentifier("urn:foo:identifiers", "12345");
- p.addTelecom().setSystem(ContactSystemEnum.PHONE).setValue("416 123-4567");
+ p.addIdentifier().setSystem("urn:foo:identifiers").setValue("12345");
+ p.addTelecom().setSystem(ContactPointSystemEnum.PHONE).setValue("416 123-4567");
// Request a validator and apply it
FhirValidator val = ctx.newValidator();
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java
index cd606181ee2..ea3a7b463b0 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java
@@ -20,11 +20,14 @@ package ca.uhn.fhir.model.primitive;
* #L%
*/
-import static ca.uhn.fhir.model.api.TemporalPrecisionEnum.*;
+import static ca.uhn.fhir.model.api.TemporalPrecisionEnum.DAY;
+import static ca.uhn.fhir.model.api.TemporalPrecisionEnum.MILLI;
+import static ca.uhn.fhir.model.api.TemporalPrecisionEnum.MONTH;
+import static ca.uhn.fhir.model.api.TemporalPrecisionEnum.SECOND;
+import static ca.uhn.fhir.model.api.TemporalPrecisionEnum.YEAR;
import java.text.ParseException;
import java.util.ArrayList;
-import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -330,13 +333,7 @@ public abstract class BaseDateTimeDt extends BasePrimitive {
}
/**
- * Sets the precision for this datatype using field values from {@link Calendar}. Valid values are:
- *
- * - {@link Calendar#SECOND}
- *
- {@link Calendar#DAY_OF_MONTH}
- *
- {@link Calendar#MONTH}
- *
- {@link Calendar#YEAR}
- *
+ * Sets the precision for this datatype
*
* @throws DataFormatException
*/
@@ -372,15 +369,23 @@ public abstract class BaseDateTimeDt extends BasePrimitive {
updateStringValue();
}
+ /**
+ * Sets the value for this type using the given Java Date object as the time, and using the
+ * default precision for this datatype, as well as the local timezone as determined by the
+ * local operating system. Both of these properties may be modified in subsequent calls
+ * if neccesary.
+ */
@Override
public BaseDateTimeDt setValue(Date theValue) {
- clearTimeZone();
- super.setValue(theValue);
+ setValue(theValue, getDefaultPrecisionForDatatype());
return this;
}
/**
- * Sets the value of this date/time using the specified level of precision
+ * Sets the value for this type using the given Java Date object as the time, and using the
+ * specified precision, as well as the local timezone as determined by the
+ * local operating system. Both of these properties may be modified in subsequent calls
+ * if neccesary.
*
* @param theValue
* The date value
@@ -390,8 +395,8 @@ public abstract class BaseDateTimeDt extends BasePrimitive {
*/
public void setValue(Date theValue, TemporalPrecisionEnum thePrecision) throws DataFormatException {
clearTimeZone();
- super.setValue(theValue);
myPrecision = thePrecision;
+ super.setValue(theValue);
}
@Override
diff --git a/hapi-fhir-jpaserver-example/src/main/webapp/WEB-INF/web.xml b/hapi-fhir-jpaserver-example/src/main/webapp/WEB-INF/web.xml
index 7ee3d9af50c..af794b95fb1 100644
--- a/hapi-fhir-jpaserver-example/src/main/webapp/WEB-INF/web.xml
+++ b/hapi-fhir-jpaserver-example/src/main/webapp/WEB-INF/web.xml
@@ -9,7 +9,7 @@
contextConfigLocation
- classpath:hapi-fhir-server-resourceproviders-dev.xml
+ classpath:hapi-fhir-server-resourceproviders-dstu2.xml
/WEB-INF/hapi-fhir-server-database-config.xml
/WEB-INF/hapi-fhir-server-config.xml
/WEB-INF/hapi-fhir-tester-application-context.xml
diff --git a/hapi-fhir-jpaserver-uhnfhirtest/pom.xml b/hapi-fhir-jpaserver-uhnfhirtest/pom.xml
index 8f848ed5c46..e2b7cbfd7bb 100644
--- a/hapi-fhir-jpaserver-uhnfhirtest/pom.xml
+++ b/hapi-fhir-jpaserver-uhnfhirtest/pom.xml
@@ -49,12 +49,12 @@
${phloc_commons_version}
-
+
org.springframework
diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java
index 517f0f9880d..b4b8811002f 100644
--- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java
+++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java
@@ -3,6 +3,7 @@ package ca.uhn.fhir.model.primitive;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@@ -17,6 +18,7 @@ import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import ca.uhn.fhir.model.dstu.resource.Condition;
+import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.validation.ValidationResult;
@@ -33,6 +35,22 @@ public class BaseDateTimeDtTest {
myDateInstantZoneParser = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSSZ", TimeZone.getTimeZone("GMT-02:00"));
}
+ /**
+ * See #101
+ */
+ @Test
+ public void testPrecision() throws Exception {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(myDateInstantParser.parse("2012-01-02 22:31:02.333"));
+ cal.setTimeZone(TimeZone.getTimeZone("EST"));
+
+ Patient patient = new Patient();
+ patient.setBirthDate(cal.getTime(), TemporalPrecisionEnum.DAY);
+ String out = ourCtx.newXmlParser().encodeResourceToString(patient);
+ assertThat(out, containsString(""));
+ }
+
+
@Test
public void setTimezoneToZulu() {
DateTimeDt dt = new DateTimeDt(new Date(816411488000L));
diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java
new file mode 100644
index 00000000000..4ca03c140f9
--- /dev/null
+++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java
@@ -0,0 +1,57 @@
+package ca.uhn.fhir.model.primitive;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
+
+public class BaseDateTimeDtTest {
+ private SimpleDateFormat myDateInstantParser;
+
+ @Before
+ public void before() {
+ myDateInstantParser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+ }
+
+ /**
+ * See HAPI #101 - https://github.com/jamesagnew/hapi-fhir/issues/101
+ */
+ @Test
+ public void testPrecisionRespectedForSetValueWithPrecision() throws Exception {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(myDateInstantParser.parse("2012-01-02 22:31:02.333"));
+ cal.setTimeZone(TimeZone.getTimeZone("EST"));
+
+ Date time = cal.getTime();
+
+ DateDt date = new DateDt();
+ date.setValue(time, TemporalPrecisionEnum.DAY);
+ assertEquals("2012-01-02", date.getValueAsString());
+ }
+
+ /**
+ * See HAPI #101 - https://github.com/jamesagnew/hapi-fhir/issues/101
+ */
+ @Test
+ public void testPrecisionRespectedForSetValue() throws Exception {
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(myDateInstantParser.parse("2012-01-02 22:31:02.333"));
+ cal.setTimeZone(TimeZone.getTimeZone("EST"));
+
+ Date time = cal.getTime();
+
+ DateDt date = new DateDt();
+ date.setValue(time);
+ assertEquals("2012-01-02", date.getValueAsString());
+ }
+
+
+}
diff --git a/hapi-fhir-testpage-overlay/pom.xml b/hapi-fhir-testpage-overlay/pom.xml
index 230b8c96d8a..ec2ff14ffbd 100644
--- a/hapi-fhir-testpage-overlay/pom.xml
+++ b/hapi-fhir-testpage-overlay/pom.xml
@@ -29,11 +29,21 @@
hapi-fhir-base
0.9-SNAPSHOT
+
+ ca.uhn.hapi.fhir
+ hapi-fhir-jpaserver-base
+ 0.9-SNAPSHOT
+
ca.uhn.hapi.fhir
hapi-fhir-structures-dstu
0.9-SNAPSHOT
+
+ ca.uhn.hapi.fhir
+ hapi-fhir-structures-dstu2
+ 0.9-SNAPSHOT
+
ca.uhn.hapi.fhir
hapi-fhir-structures-dev
@@ -57,12 +67,12 @@
provided
-
+
ch.qos.logback
diff --git a/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/Controller.java b/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/Controller.java
index 279715db4c0..e5e4d29c046 100644
--- a/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/Controller.java
+++ b/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/Controller.java
@@ -421,17 +421,17 @@ public class Controller {
private boolean extractSearchParamsDev(IResource theConformance, String resourceName, TreeSet includes, TreeSet sortParams, List queries, boolean haveSearchParams,
List> queryIncludes) {
- ca.uhn.fhir.model.dev.resource.Conformance conformance = (ca.uhn.fhir.model.dev.resource.Conformance) theConformance;
- for (ca.uhn.fhir.model.dev.resource.Conformance.Rest nextRest : conformance.getRest()) {
- for (ca.uhn.fhir.model.dev.resource.Conformance.RestResource nextRes : nextRest.getResource()) {
+ ca.uhn.fhir.model.dstu2.resource.Conformance conformance = (ca.uhn.fhir.model.dstu2.resource.Conformance) theConformance;
+ for (ca.uhn.fhir.model.dstu2.resource.Conformance.Rest nextRest : conformance.getRest()) {
+ for (ca.uhn.fhir.model.dstu2.resource.Conformance.RestResource nextRes : nextRest.getResource()) {
if (nextRes.getTypeElement().getValue().equals(resourceName)) {
for (StringDt next : nextRes.getSearchInclude()) {
if (next.isEmpty() == false) {
includes.add(next.getValue());
}
}
- for (ca.uhn.fhir.model.dev.resource.Conformance.RestResourceSearchParam next : nextRes.getSearchParam()) {
- if (next.getTypeElement().getValueAsEnum() != ca.uhn.fhir.model.dev.valueset.SearchParamTypeEnum.COMPOSITE) {
+ for (ca.uhn.fhir.model.dstu2.resource.Conformance.RestResourceSearchParam next : nextRes.getSearchParam()) {
+ if (next.getTypeElement().getValueAsEnum() != ca.uhn.fhir.model.dstu2.valueset.SearchParamTypeEnum.COMPOSITE) {
sortParams.add(next.getNameElement().getValue());
}
}
@@ -1083,21 +1083,21 @@ public class Controller {
private IResource loadAndAddConfDev(final HomeRequest theRequest, final ModelMap theModel) {
IGenericClient client = getContext(theRequest).newRestfulGenericClient(theRequest.getServerBase(myConfig));
- ca.uhn.fhir.model.dev.resource.Conformance conformance;
+ ca.uhn.fhir.model.dstu2.resource.Conformance conformance;
try {
- conformance = (ca.uhn.fhir.model.dev.resource.Conformance) client.conformance();
+ conformance = (ca.uhn.fhir.model.dstu2.resource.Conformance) client.conformance();
} catch (Exception e) {
ourLog.warn("Failed to load conformance statement", e);
theModel.put("errorMsg", "Failed to load conformance statement, error was: " + e.toString());
- conformance = new ca.uhn.fhir.model.dev.resource.Conformance();
+ conformance = new ca.uhn.fhir.model.dstu2.resource.Conformance();
}
theModel.put("jsonEncodedConf", getContext(theRequest).newJsonParser().encodeResourceToString(conformance));
Map resourceCounts = new HashMap();
long total = 0;
- for (ca.uhn.fhir.model.dev.resource.Conformance.Rest nextRest : conformance.getRest()) {
- for (ca.uhn.fhir.model.dev.resource.Conformance.RestResource nextResource : nextRest.getResource()) {
+ for (ca.uhn.fhir.model.dstu2.resource.Conformance.Rest nextRest : conformance.getRest()) {
+ for (ca.uhn.fhir.model.dstu2.resource.Conformance.RestResource nextResource : nextRest.getResource()) {
List exts = nextResource.getUndeclaredExtensionsByUrl(RESOURCE_COUNT_EXT_URL);
if (exts != null && exts.size() > 0) {
Number nextCount = ((DecimalDt) (exts.get(0).getValue())).getValueAsNumber();
@@ -1109,10 +1109,10 @@ public class Controller {
theModel.put("resourceCounts", resourceCounts);
if (total > 0) {
- for (ca.uhn.fhir.model.dev.resource.Conformance.Rest nextRest : conformance.getRest()) {
- Collections.sort(nextRest.getResource(), new Comparator() {
+ for (ca.uhn.fhir.model.dstu2.resource.Conformance.Rest nextRest : conformance.getRest()) {
+ Collections.sort(nextRest.getResource(), new Comparator() {
@Override
- public int compare(ca.uhn.fhir.model.dev.resource.Conformance.RestResource theO1, ca.uhn.fhir.model.dev.resource.Conformance.RestResource theO2) {
+ public int compare(ca.uhn.fhir.model.dstu2.resource.Conformance.RestResource theO1, ca.uhn.fhir.model.dstu2.resource.Conformance.RestResource theO2) {
DecimalDt count1 = new DecimalDt();
List count1exts = theO1.getUndeclaredExtensionsByUrl(RESOURCE_COUNT_EXT_URL);
if (count1exts != null && count1exts.size() > 0) {
diff --git a/hapi-fhir-testpage-overlay/src/test/java/ca/uhn/fhir/jpa/test/OverlayTestApp.java b/hapi-fhir-testpage-overlay/src/test/java/ca/uhn/fhir/jpa/test/OverlayTestApp.java
index e738b52d1e3..01d08262159 100644
--- a/hapi-fhir-testpage-overlay/src/test/java/ca/uhn/fhir/jpa/test/OverlayTestApp.java
+++ b/hapi-fhir-testpage-overlay/src/test/java/ca/uhn/fhir/jpa/test/OverlayTestApp.java
@@ -11,14 +11,7 @@ import org.eclipse.jetty.webapp.WebAppContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
-import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
-import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu1;
import ca.uhn.fhir.jpa.provider.JpaSystemProvider;
-import ca.uhn.fhir.jpa.rp.dstu2.DiagnosticReportResourceProvider;
-import ca.uhn.fhir.jpa.rp.dstu2.ObservationResourceProvider;
-import ca.uhn.fhir.jpa.rp.dstu2.OrganizationResourceProvider;
-import ca.uhn.fhir.jpa.rp.dstu2.PatientResourceProvider;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
@@ -26,10 +19,8 @@ import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
import ca.uhn.fhir.model.dstu.resource.DiagnosticReport;
-import ca.uhn.fhir.model.dstu.resource.Observation;
import ca.uhn.fhir.model.dstu.resource.Organization;
import ca.uhn.fhir.model.dstu.resource.Patient;
-import ca.uhn.fhir.model.dstu.resource.Questionnaire;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IncludeParam;
import ca.uhn.fhir.rest.annotation.OptionalParam;
diff --git a/pom.xml b/pom.xml
index 68e2a579f0a..9c320e515f9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -128,6 +128,10 @@
twilson650
Tom Wilson
+
+ esteban-aliverti
+ Esteban Aliverti
+
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 727b22d3bde..bd26f68afe0 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -101,6 +101,11 @@
if StAX API was configured to use a different provider. Thanks to
James Butler for reporting and figuring out where the issue was!
+
+ Calling BaseDateTimeDt#setValue(Date, TemporalPrecisionEnum) did not always actually respect
+ the given precision when the value was encoded. Thanks to jacksonjesse for
+ reporting!
+
Encoders (both XML and JSON) will no longer encode contained resources if they are
not referenced anywhere in the resource via a local reference. This is just a convenience
diff --git a/src/site/xdoc/doc_fhirobjects.xml b/src/site/xdoc/doc_fhirobjects.xml
index 280b9689c4c..f0d1524f4ad 100644
--- a/src/site/xdoc/doc_fhirobjects.xml
+++ b/src/site/xdoc/doc_fhirobjects.xml
@@ -56,11 +56,18 @@
There are many places in the FHIR specification where a "coded" string is
used. This means that a code must be chosen from a list of allowable values.
-
+
+ Closed Valuesets / Codes
+
- In these cases, HAPI tries to simplify the process by providing Java Enum
- types, which can be used to reduce complexity and provide compile-time
- checking.
+ The FHIR specification defines a number of "closed" ValueSets, such as
+ the one used for
+
+ Patient.gender
+ (note that this field was not a closed ValueSet in DSTU1 but is as of DSTU2).
+ These valuesets must either be empty, or be populated with a value drawn from
+ the list of allowable values defined by FHIR. HAPI provides special typesafe
+ Enums to help in dealing with these fields.
@@ -68,6 +75,42 @@
+ Open Valusets / CodeableConcepts
+
+
+ The FHIR specification also defines a number of "open" ValueSets, such as
+ the one used for
+ Patient.maritalStatus.
+ These fields may define a set of allowable codes, but also allow you to
+ use your own codes instead if none of the given codes matches your needs. This
+ is called an incomplete binding.
+ Some fields may even define a set of codes that serve as nothing more than
+ an example as to the type of codes that would be used there. This is known as
+ an example binding.
+
+
+
+ For these fields, a CodeableConcept datatype is generally used by the
+ FHIR specification. This datatype allows multiple "codings", which
+ are a code and codesystem pair, optionally with a display name as well.
+ The following example shows how to interact with this type.
+
+
+
+
+
+
+
+
+ HAPI also provides typesafe enums to help in working with CodeableConcept
+ fields.
+
+
+
+
+
+
+