From 74b15e2295f2800b56c233c0710333d69418148a Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 19 Nov 2014 11:29:33 -0500 Subject: [PATCH] Add a new date/time setter and update documentation --- .../fhir/model/primitive/BaseDateTimeDt.java | 27 ++++++++++++++++--- .../ca/uhn/fhir/model/primitive/DateDt.java | 10 +++++++ .../uhn/fhir/model/primitive/DateTimeDt.java | 11 ++++++++ .../uhn/fhir/model/primitive/InstantDt.java | 11 ++++++++ hapi-fhir-structures-dstu/pom.xml | 13 ++++++++- .../fhir/rest/server/ServerFeaturesTest.java | 10 ++++++- .../java/ca/uhn/fhir/example/Example01.java | 11 -------- .../example/Example01_CreateAPatient.java | 24 +++++++++++++++++ 8 files changed, 101 insertions(+), 16 deletions(-) delete mode 100644 hapi-fhir-tutorial/skeleton-project/src/main/java/ca/uhn/fhir/example/Example01.java create mode 100644 hapi-fhir-tutorial/skeleton-project/src/main/java/ca/uhn/fhir/example/Example01_CreateAPatient.java 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 a766fcdd8dd..75a46273d27 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 @@ -138,14 +138,22 @@ public abstract class BaseDateTimeDt extends BasePrimitive { /** - * Gets the precision for this datatype using field values from {@link Calendar}, such as {@link Calendar#MONTH}. Default is {@link Calendar#DAY_OF_MONTH} + * Gets the precision for this datatype (using the default for the given type if not set) * - * @see #setPrecision(int) + * @see #setPrecision(TemporalPrecisionEnum) */ public TemporalPrecisionEnum getPrecision() { + if (myPrecision == null) { + return getDefaultPrecisionForDatatype(); + } return myPrecision; } + /** + * Returns the default precision for the given datatype + */ + protected abstract TemporalPrecisionEnum getDefaultPrecisionForDatatype(); + /** * Returns the TimeZone associated with this dateTime's value. May return * null if no timezone was supplied. @@ -337,11 +345,24 @@ public abstract class BaseDateTimeDt extends BasePrimitive { } @Override - public void setValue(Date theValue) throws DataFormatException { + public void setValue(Date theValue) { clearTimeZone(); super.setValue(theValue); } + /** + * Sets the value of this date/time using the specified level of precision + * + * @param theValue The date value + * @param thePrecision The precision + * @throws DataFormatException + */ + public void setValue(Date theValue, TemporalPrecisionEnum thePrecision) throws DataFormatException { + clearTimeZone(); + super.setValue(theValue); + myPrecision = thePrecision; + } + @Override public void setValueAsString(String theValue) throws DataFormatException { clearTimeZone(); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/DateDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/DateDt.java index 6c6e1801e03..bfb20323432 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/DateDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/DateDt.java @@ -76,4 +76,14 @@ public class DateDt extends BaseDateTimeDt { } } + /** + * Returns the default precision for this datatype + * + * @see #DEFAULT_PRECISION + */ + @Override + protected TemporalPrecisionEnum getDefaultPrecisionForDatatype() { + return DEFAULT_PRECISION; + } + } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/DateTimeDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/DateTimeDt.java index ec0057469c4..efe7c57f018 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/DateTimeDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/DateTimeDt.java @@ -98,4 +98,15 @@ public class DateTimeDt extends BaseDateTimeDt { return new DateTimeDt(new Date(), TemporalPrecisionEnum.SECOND); } + /** + * Returns the default precision for this datatype + * + * @see #DEFAULT_PRECISION + */ + @Override + protected TemporalPrecisionEnum getDefaultPrecisionForDatatype() { + return DEFAULT_PRECISION; + } + + } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/InstantDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/InstantDt.java index f8249a26996..388196f1e4a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/InstantDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/InstantDt.java @@ -160,4 +160,15 @@ public class InstantDt extends BaseDateTimeDt { return new InstantDt(new Date(), TemporalPrecisionEnum.MILLI); } + /** + * Returns the default precision for this datatype + * + * @see #DEFAULT_PRECISION + */ + @Override + protected TemporalPrecisionEnum getDefaultPrecisionForDatatype() { + return DEFAULT_PRECISION; + } + + } diff --git a/hapi-fhir-structures-dstu/pom.xml b/hapi-fhir-structures-dstu/pom.xml index aa206c1674a..609667bb495 100644 --- a/hapi-fhir-structures-dstu/pom.xml +++ b/hapi-fhir-structures-dstu/pom.xml @@ -28,7 +28,7 @@ provided - + junit junit @@ -303,6 +303,17 @@ + + + ${baseDir}/src/main/resources + + + ${baseDir}/target/generated-sources/tinder + + + ${baseDir}/target/generated-resources/tinder + + diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java index 0435977c5f9..9e84410ecba 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java @@ -29,6 +29,7 @@ import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.composite.HumanNameDt; import ca.uhn.fhir.model.dstu.composite.IdentifierDt; +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.primitive.IdDt; @@ -236,11 +237,13 @@ public class ServerFeaturesTest { assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = servlet.getFhirContext().newXmlParser().parseBundle(responseContent); - assertEquals(1,bundle.size()); + assertEquals(2,bundle.size()); assertEquals("http://absolute.com/Patient/123", bundle.getEntries().get(0).getId().getValue()); assertEquals("http://absolute.com/Patient/123/_history/22", bundle.getEntries().get(0).getLinkSelf().getValue()); + assertEquals("http://foo.com/Organization/222",bundle.getEntries().get(1).getId().getValue()); + assertEquals("http://foo.com/Organization/222/_history/333",bundle.getEntries().get(1).getLinkSelf().getValue()); } @Test @@ -370,6 +373,11 @@ public class ServerFeaturesTest { Patient p = new Patient(); p.addIdentifier().setSystem("foo"); p.setId("http://absolute.com/Patient/123/_history/22"); + + Organization o = new Organization(); + o.setId("http://foo.com/Organization/222/_history/333"); + p.getManagingOrganization().setResource(o); + return Collections.singletonList(p); } diff --git a/hapi-fhir-tutorial/skeleton-project/src/main/java/ca/uhn/fhir/example/Example01.java b/hapi-fhir-tutorial/skeleton-project/src/main/java/ca/uhn/fhir/example/Example01.java deleted file mode 100644 index 33f6cabdadd..00000000000 --- a/hapi-fhir-tutorial/skeleton-project/src/main/java/ca/uhn/fhir/example/Example01.java +++ /dev/null @@ -1,11 +0,0 @@ -package ca.uhn.fhir.example; - -public class Example01 { - - public static void main(String[] theArgs) { - - - - } - -} diff --git a/hapi-fhir-tutorial/skeleton-project/src/main/java/ca/uhn/fhir/example/Example01_CreateAPatient.java b/hapi-fhir-tutorial/skeleton-project/src/main/java/ca/uhn/fhir/example/Example01_CreateAPatient.java new file mode 100644 index 00000000000..fbde2755839 --- /dev/null +++ b/hapi-fhir-tutorial/skeleton-project/src/main/java/ca/uhn/fhir/example/Example01_CreateAPatient.java @@ -0,0 +1,24 @@ +package ca.uhn.fhir.example; + +import ca.uhn.fhir.model.dstu.composite.HumanNameDt; +import ca.uhn.fhir.model.dstu.composite.IdentifierDt; +import ca.uhn.fhir.model.dstu.resource.Patient; + +@SuppressWarnings("unused") +public class Example01_CreateAPatient { + + public static void main(String[] theArgs) { + + Patient pat = new Patient(); + + IdentifierDt identifier = pat.addIdentifier(); + identifier.setSystem("http://acme.org/MRNs").setValue("7000135"); + + HumanNameDt name = pat.addName(); + name.addFamily("Simpson").addGiven("Homer").addGiven("J"); + + pat.getBirthDate().set + + } + +}