From 53674db3576cbe86557353049161d64aacf12862 Mon Sep 17 00:00:00 2001 From: Simon Marco Janic Date: Wed, 1 Nov 2017 11:37:51 +0100 Subject: [PATCH 1/2] [(master)] Added support for extensions in Meta resource --- .../model/api/ResourceMetadataKeyEnum.java | 25 +++++++ .../java/ca/uhn/fhir/parser/BaseParser.java | 12 ++++ .../java/ca/uhn/fhir/parser/JsonParser.java | 40 ++++++++++- .../java/ca/uhn/fhir/parser/ParserState.java | 19 +++++ .../uhn/fhir/parser/JsonParserDstu2Test.java | 72 +++++++++++++++---- .../src/test/resources/patient1.json | 70 +++++++++--------- .../dstu3/model/codesystems/Devicestatus.java | 47 +++++++----- .../codesystems/DevicestatusEnumFactory.java | 36 +++++----- 8 files changed, 238 insertions(+), 83 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java index 603ef37151f4..b0cb50f692be 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java @@ -613,5 +613,30 @@ public ResourceMetadataKeySupportingAnyResource(String theValue) { public abstract void put(IAnyResource theResource, T2 theObject); } + + public static final class ExtensionResourceMetadataKey extends ResourceMetadataKeyEnum { + public ExtensionResourceMetadataKey(String url) { + super(url); + } + + @Override + public ExtensionDt get(IResource theResource) { + Object retValObj = theResource.getResourceMetadata().get(this); + if (retValObj == null) { + return null; + } else if (retValObj instanceof ExtensionDt) { + return (ExtensionDt) retValObj; + } + throw new InternalErrorException("Found an object of type '" + retValObj.getClass().getCanonicalName() + + "' in resource metadata for key " + this.name() + " - Expected " + + ExtensionDt.class.getCanonicalName()); + } + + @Override + public void put(IResource theResource, ExtensionDt theObject) { + theResource.getResourceMetadata().put(this, theObject); + } + } + } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java index 6e5b82900275..efe0517eac89 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java @@ -911,6 +911,18 @@ protected void throwExceptionForUnknownChildType(BaseRuntimeChildDefinition next throw new DataFormatException(nextChild + " has no child of type " + theType); } + protected List, Object>> getExtensionMetadataKeys(IResource resource) { + List, Object>> extensionMetadataKeys = new ArrayList, Object>>(); + for (Map.Entry, Object> entry : resource.getResourceMetadata().entrySet()) { + if (entry.getKey() instanceof ResourceMetadataKeyEnum.ExtensionResourceMetadataKey) { + extensionMetadataKeys.add(entry); + } + } + + return extensionMetadataKeys; + } + + protected static List extractMetadataListNotNull(IResource resource, ResourceMetadataKeyEnum> key) { List securityLabels = key.get(resource); if (securityLabels == null) { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java index 55aa0bc7a7a2..fe9a062b6bf1 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java @@ -650,8 +650,9 @@ private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDe if (isBlank(versionIdPart)) { versionIdPart = ResourceMetadataKeyEnum.VERSION.get(resource); } + List, Object>> extensionMetadataKeys = getExtensionMetadataKeys(resource); - if (super.shouldEncodeResourceMeta(resource) && ElementUtil.isEmpty(versionIdPart, updated, securityLabels, tags, profiles) == false) { + if (super.shouldEncodeResourceMeta(resource) && (ElementUtil.isEmpty(versionIdPart, updated, securityLabels, tags, profiles) == false) || !extensionMetadataKeys.isEmpty()) { beginObject(theEventWriter, "meta"); writeOptionalTagWithTextNode(theEventWriter, "versionId", versionIdPart); writeOptionalTagWithTextNode(theEventWriter, "lastUpdated", updated); @@ -691,6 +692,8 @@ private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDe theEventWriter.endArray(); } + addExtensionMetadata(extensionMetadataKeys, theEventWriter); + theEventWriter.endObject(); // end meta } } @@ -712,6 +715,41 @@ private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDe theEventWriter.endObject(); } + private void addExtensionMetadata(List, Object>> extensionMetadataKeys, JsonLikeWriter theEventWriter) throws IOException { + if (extensionMetadataKeys.isEmpty()) { + return; + } + + List, Object>> extensionKeys = new ArrayList<>(extensionMetadataKeys.size()); + List, Object>> modifierExtensionKeys = new ArrayList<>(extensionKeys.size()); + for (Map.Entry, Object> entry : extensionMetadataKeys) { + if (!((ExtensionDt) entry.getValue()).isModifier()) { + extensionKeys.add(entry); + } else { + modifierExtensionKeys.add(entry); + } + } + + writeMetadataExtensions(extensionKeys, "extension", theEventWriter); + writeMetadataExtensions(extensionKeys, "modifierExtension", theEventWriter); + } + + private void writeMetadataExtensions(List, Object>> extensions, String arrayName, JsonLikeWriter theEventWriter) throws IOException { + if (extensions.isEmpty()) { + return; + } + beginArray(theEventWriter, arrayName); + for (Map.Entry, Object> key : extensions) { + ExtensionDt extension = (ExtensionDt) key.getValue(); + theEventWriter.beginObject(); + writeOptionalTagWithTextNode(theEventWriter, "url", extension.getUrl()); + String extensionDatatype = myContext.getRuntimeChildUndeclaredExtensionDefinition().getChildNameByDatatype(extension.getValue().getClass()); + writeOptionalTagWithTextNode(theEventWriter, extensionDatatype, extension.getValueAsPrimitive()); + theEventWriter.endObject(); + } + theEventWriter.endArray(); + } + /** * This is useful only for the two cases where extensions are encoded as direct children (e.g. not in some object * called _name): resource extensions, and extension extensions diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java index e54793602c67..fab95e21059a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java @@ -841,6 +841,25 @@ public void enteringNewElement(String theNamespaceUri, String theLocalPart) thro } } + @Override + public void enteringNewElementExtension(StartElement theElem, String theUrlAttr, boolean theIsModifier, final String baseServerUrl) { + ResourceMetadataKeyEnum.ExtensionResourceMetadataKey resourceMetadataKeyEnum = new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey(theUrlAttr); + Object metadataValue = myMap.get(resourceMetadataKeyEnum); + ExtensionDt newExtension; + if (metadataValue == null) { + newExtension = new ExtensionDt(theIsModifier); + } else if (metadataValue instanceof ExtensionDt) { + newExtension = (ExtensionDt) metadataValue; + } else { + throw new IllegalStateException("Expected ExtensionDt as custom resource metadata type, got: " + metadataValue.getClass().getSimpleName()); + } + newExtension.setUrl(theUrlAttr); + myMap.put(resourceMetadataKeyEnum, newExtension); + + ExtensionState newState = new ExtensionState(getPreResourceState(), newExtension); + push(newState); + } + } private class MetaVersionElementState extends BaseState { diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java index ba0860169a1d..dca45aaffa99 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java @@ -1,9 +1,11 @@ package ca.uhn.fhir.parser; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -1688,19 +1690,65 @@ public void testParseWithExtensions() throws Exception { Patient p = parser.parseResource(Patient.class, input); ArgumentCaptor capt = ArgumentCaptor.forClass(String.class); - verify(peh, times(4)).unknownElement(Mockito.isNull(IParseLocation.class), capt.capture()); - - //@formatter:off - List strings = capt.getAllValues(); - assertThat(strings, contains( - "extension", - "extension", - "modifierExtension", - "modifierExtension" - )); - //@formatter:off - + verify(peh, Mockito.never()).unknownElement(Mockito.isNull(IParseLocation.class), capt.capture()); assertEquals("Smith", p.getName().get(0).getGiven().get(0).getValue()); + assertExtensionMetadata(p, "fhir-request-method", false, StringDt.class, "POST"); + assertExtensionMetadata(p, "fhir-request-uri", false, UriDt.class, "Patient"); + assertExtensionMetadata(p, "modified-fhir-request-method", true, StringDt.class, "POST"); + assertExtensionMetadata(p, "modified-fhir-request-uri", true, UriDt.class, "Patient"); + } + + private void assertExtensionMetadata( + BaseResource resource, + String url, + boolean isModifier, + Class expectedType, + String expectedValue) { + ExtensionDt extension = (ExtensionDt) resource.getResourceMetadata().get(new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey(url)); + assertThat(extension.getValue(), instanceOf(expectedType)); + assertThat(extension.isModifier(), equalTo(isModifier)); + assertThat(extension.getValueAsPrimitive().getValueAsString(), equalTo(expectedValue)); + } + + @Test + public void testEncodeResourceWithExtensionMetadata() throws Exception { + ProcedureRequest procedureRequest = new ProcedureRequest(); + procedureRequest.setStatus(ProcedureRequestStatusEnum.ACCEPTED); + addExtensionResourceMetadataKeyToResource(procedureRequest, false, "http://someurl.com", "SomeValue"); + addExtensionResourceMetadataKeyToResource(procedureRequest, false, "http://someurl2.com", "SomeValue2"); + addExtensionResourceMetadataKeyToResource(procedureRequest, true, "http://someurl.com/modifier", "SomeValue"); + addExtensionResourceMetadataKeyToResource(procedureRequest, true, "http://someurl.com/modifier2", "SomeValue2"); + + String json = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(procedureRequest); + + // @formatter:off + assertThat(json, stringContainsInOrder("\"meta\": {", + "\"extension\": [", "{", + "\"url\": \"http://someurl.com\",", + "\"valueString\": \"SomeValue\"", + "},", + "{", + "\"url\": \"http://someurl2.com\",", + "\"valueString\": \"SomeValue2\"", + "}", + "],", + "\"modifierExtension\": [", + "{", + "\"url\": \"http://someurl.com\",", + "\"valueString\": \"SomeValue\"", + "},", + "{", + "\"url\": \"http://someurl2.com\",", + "\"valueString\": \"SomeValue2\"", + "}", + "]")); + // @formatter:on + } + + private void addExtensionResourceMetadataKeyToResource(BaseResource resource, boolean isModifier, String url, String value) { + ExtensionDt extensionDt = new ExtensionDt(isModifier, url, new StringDt(value)); + resource.getResourceMetadata() + .put(new ResourceMetadataKeyEnum.ExtensionResourceMetadataKey(extensionDt.getUrl()), extensionDt); } @Test diff --git a/hapi-fhir-structures-dstu2/src/test/resources/patient1.json b/hapi-fhir-structures-dstu2/src/test/resources/patient1.json index 6cc128a2684e..dbdd0c34abe9 100644 --- a/hapi-fhir-structures-dstu2/src/test/resources/patient1.json +++ b/hapi-fhir-structures-dstu2/src/test/resources/patient1.json @@ -1,35 +1,35 @@ -{ - "id": "73b551fb-46f5-4fb8-b735-2399344e9717", - "meta": { - "extension": [ - { - "url": "fhir-request-method", - "valueString": "POST" - }, - { - "url": "fhir-request-uri", - "valueUri": "Patient" - } - ], - "modifierExtension": [ - { - "url": "fhir-request-method", - "valueString": "POST" - }, - { - "url": "fhir-request-uri", - "valueUri": "Patient" - } - ], - "versionId": "01e5253d-d258-494c-8d8e-f22ad6d8f19b", - "lastUpdated": "2016-02-20T11:01:56.155Z" - }, - "name": [ - { - "given": [ - "Smith" - ] - } - ], - "resourceType": "Patient" -} +{ + "id": "73b551fb-46f5-4fb8-b735-2399344e9717", + "meta": { + "extension": [ + { + "url": "fhir-request-method", + "valueString": "POST" + }, + { + "url": "fhir-request-uri", + "valueUri": "Patient" + } + ], + "modifierExtension": [ + { + "url": "modified-fhir-request-method", + "valueString": "POST" + }, + { + "url": "modified-fhir-request-uri", + "valueUri": "Patient" + } + ], + "versionId": "01e5253d-d258-494c-8d8e-f22ad6d8f19b", + "lastUpdated": "2016-02-20T11:01:56.155Z" + }, + "name": [ + { + "given": [ + "Smith" + ] + } + ], + "resourceType": "Patient" +} diff --git a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/Devicestatus.java b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/Devicestatus.java index 42a5b675f487..d5ccb36916da 100644 --- a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/Devicestatus.java +++ b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/Devicestatus.java @@ -29,64 +29,73 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS */ -// Generated on Mon, Jan 16, 2017 12:12-0500 for FHIR v1.9.0 +// Generated on Sat, Mar 25, 2017 21:03-0400 for FHIR v3.0.0 import org.hl7.fhir.exceptions.FHIRException; -public enum Devicestatus { +public enum DeviceStatus { /** - * The Device is available for use. + * The Device is available for use. Note: This means for *implanted devices* the device is implanted in the patient. */ - AVAILABLE, + ACTIVE, /** - * The Device is no longer available for use (e.g. lost, expired, damaged). + * The Device is no longer available for use (e.g. lost, expired, damaged). Note: This means for *implanted devices* the device has been removed from the patient. */ - NOTAVAILABLE, + INACTIVE, /** * The Device was entered in error and voided. */ ENTEREDINERROR, + /** + * The status of the device has not been determined. + */ + UNKNOWN, /** * added to help the parsers */ NULL; - public static Devicestatus fromCode(String codeString) throws FHIRException { + public static DeviceStatus fromCode(String codeString) throws FHIRException { if (codeString == null || "".equals(codeString)) return null; - if ("available".equals(codeString)) - return AVAILABLE; - if ("not-available".equals(codeString)) - return NOTAVAILABLE; + if ("active".equals(codeString)) + return ACTIVE; + if ("inactive".equals(codeString)) + return INACTIVE; if ("entered-in-error".equals(codeString)) return ENTEREDINERROR; - throw new FHIRException("Unknown Devicestatus code '"+codeString+"'"); + if ("unknown".equals(codeString)) + return UNKNOWN; + throw new FHIRException("Unknown DeviceStatus code '"+codeString+"'"); } public String toCode() { switch (this) { - case AVAILABLE: return "available"; - case NOTAVAILABLE: return "not-available"; + case ACTIVE: return "active"; + case INACTIVE: return "inactive"; case ENTEREDINERROR: return "entered-in-error"; + case UNKNOWN: return "unknown"; default: return "?"; } } public String getSystem() { - return "http://hl7.org/fhir/devicestatus"; + return "http://hl7.org/fhir/device-status"; } public String getDefinition() { switch (this) { - case AVAILABLE: return "The Device is available for use."; - case NOTAVAILABLE: return "The Device is no longer available for use (e.g. lost, expired, damaged)."; + case ACTIVE: return "The Device is available for use. Note: This means for *implanted devices* the device is implanted in the patient."; + case INACTIVE: return "The Device is no longer available for use (e.g. lost, expired, damaged). Note: This means for *implanted devices* the device has been removed from the patient."; case ENTEREDINERROR: return "The Device was entered in error and voided."; + case UNKNOWN: return "The status of the device has not been determined."; default: return "?"; } } public String getDisplay() { switch (this) { - case AVAILABLE: return "Available"; - case NOTAVAILABLE: return "Not Available"; + case ACTIVE: return "Active"; + case INACTIVE: return "Inactive"; case ENTEREDINERROR: return "Entered in Error"; + case UNKNOWN: return "Unknown"; default: return "?"; } } diff --git a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/DevicestatusEnumFactory.java b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/DevicestatusEnumFactory.java index d08ce2ed34e0..64e4d361f1c9 100644 --- a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/DevicestatusEnumFactory.java +++ b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/DevicestatusEnumFactory.java @@ -29,36 +29,40 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS */ -// Generated on Mon, Jan 16, 2017 12:12-0500 for FHIR v1.9.0 +// Generated on Sat, Mar 25, 2017 21:03-0400 for FHIR v3.0.0 import org.hl7.fhir.dstu3.model.EnumFactory; -public class DevicestatusEnumFactory implements EnumFactory { +public class DeviceStatusEnumFactory implements EnumFactory { - public Devicestatus fromCode(String codeString) throws IllegalArgumentException { + public DeviceStatus fromCode(String codeString) throws IllegalArgumentException { if (codeString == null || "".equals(codeString)) return null; - if ("available".equals(codeString)) - return Devicestatus.AVAILABLE; - if ("not-available".equals(codeString)) - return Devicestatus.NOTAVAILABLE; + if ("active".equals(codeString)) + return DeviceStatus.ACTIVE; + if ("inactive".equals(codeString)) + return DeviceStatus.INACTIVE; if ("entered-in-error".equals(codeString)) - return Devicestatus.ENTEREDINERROR; - throw new IllegalArgumentException("Unknown Devicestatus code '"+codeString+"'"); + return DeviceStatus.ENTEREDINERROR; + if ("unknown".equals(codeString)) + return DeviceStatus.UNKNOWN; + throw new IllegalArgumentException("Unknown DeviceStatus code '"+codeString+"'"); } - public String toCode(Devicestatus code) { - if (code == Devicestatus.AVAILABLE) - return "available"; - if (code == Devicestatus.NOTAVAILABLE) - return "not-available"; - if (code == Devicestatus.ENTEREDINERROR) + public String toCode(DeviceStatus code) { + if (code == DeviceStatus.ACTIVE) + return "active"; + if (code == DeviceStatus.INACTIVE) + return "inactive"; + if (code == DeviceStatus.ENTEREDINERROR) return "entered-in-error"; + if (code == DeviceStatus.UNKNOWN) + return "unknown"; return "?"; } - public String toSystem(Devicestatus code) { + public String toSystem(DeviceStatus code) { return code.getSystem(); } From 11dc9175405761e136f2df57b1bfed5e867a80a1 Mon Sep 17 00:00:00 2001 From: Simon Marco Janic Date: Wed, 1 Nov 2017 12:52:17 +0100 Subject: [PATCH 2/2] [(master)] Reverted unintentional changes --- .../dstu3/model/codesystems/Devicestatus.java | 201 +++++++++--------- .../codesystems/DevicestatusEnumFactory.java | 136 ++++++------ 2 files changed, 162 insertions(+), 175 deletions(-) diff --git a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/Devicestatus.java b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/Devicestatus.java index d5ccb36916da..518a37bbf3c0 100644 --- a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/Devicestatus.java +++ b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/Devicestatus.java @@ -1,105 +1,96 @@ -package org.hl7.fhir.dstu3.model.codesystems; - -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - -*/ - -// Generated on Sat, Mar 25, 2017 21:03-0400 for FHIR v3.0.0 - - -import org.hl7.fhir.exceptions.FHIRException; - -public enum DeviceStatus { - - /** - * The Device is available for use. Note: This means for *implanted devices* the device is implanted in the patient. - */ - ACTIVE, - /** - * The Device is no longer available for use (e.g. lost, expired, damaged). Note: This means for *implanted devices* the device has been removed from the patient. - */ - INACTIVE, - /** - * The Device was entered in error and voided. - */ - ENTEREDINERROR, - /** - * The status of the device has not been determined. - */ - UNKNOWN, - /** - * added to help the parsers - */ - NULL; - public static DeviceStatus fromCode(String codeString) throws FHIRException { - if (codeString == null || "".equals(codeString)) - return null; - if ("active".equals(codeString)) - return ACTIVE; - if ("inactive".equals(codeString)) - return INACTIVE; - if ("entered-in-error".equals(codeString)) - return ENTEREDINERROR; - if ("unknown".equals(codeString)) - return UNKNOWN; - throw new FHIRException("Unknown DeviceStatus code '"+codeString+"'"); - } - public String toCode() { - switch (this) { - case ACTIVE: return "active"; - case INACTIVE: return "inactive"; - case ENTEREDINERROR: return "entered-in-error"; - case UNKNOWN: return "unknown"; - default: return "?"; - } - } - public String getSystem() { - return "http://hl7.org/fhir/device-status"; - } - public String getDefinition() { - switch (this) { - case ACTIVE: return "The Device is available for use. Note: This means for *implanted devices* the device is implanted in the patient."; - case INACTIVE: return "The Device is no longer available for use (e.g. lost, expired, damaged). Note: This means for *implanted devices* the device has been removed from the patient."; - case ENTEREDINERROR: return "The Device was entered in error and voided."; - case UNKNOWN: return "The status of the device has not been determined."; - default: return "?"; - } - } - public String getDisplay() { - switch (this) { - case ACTIVE: return "Active"; - case INACTIVE: return "Inactive"; - case ENTEREDINERROR: return "Entered in Error"; - case UNKNOWN: return "Unknown"; - default: return "?"; - } - } - - -} - +package org.hl7.fhir.dstu3.model.codesystems; + +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +// Generated on Mon, Jan 16, 2017 12:12-0500 for FHIR v1.9.0 + + +import org.hl7.fhir.exceptions.FHIRException; + +public enum Devicestatus { + + /** + * The Device is available for use. + */ + AVAILABLE, + /** + * The Device is no longer available for use (e.g. lost, expired, damaged). + */ + NOTAVAILABLE, + /** + * The Device was entered in error and voided. + */ + ENTEREDINERROR, + /** + * added to help the parsers + */ + NULL; + public static Devicestatus fromCode(String codeString) throws FHIRException { + if (codeString == null || "".equals(codeString)) + return null; + if ("available".equals(codeString)) + return AVAILABLE; + if ("not-available".equals(codeString)) + return NOTAVAILABLE; + if ("entered-in-error".equals(codeString)) + return ENTEREDINERROR; + throw new FHIRException("Unknown Devicestatus code '"+codeString+"'"); + } + public String toCode() { + switch (this) { + case AVAILABLE: return "available"; + case NOTAVAILABLE: return "not-available"; + case ENTEREDINERROR: return "entered-in-error"; + default: return "?"; + } + } + public String getSystem() { + return "http://hl7.org/fhir/devicestatus"; + } + public String getDefinition() { + switch (this) { + case AVAILABLE: return "The Device is available for use."; + case NOTAVAILABLE: return "The Device is no longer available for use (e.g. lost, expired, damaged)."; + case ENTEREDINERROR: return "The Device was entered in error and voided."; + default: return "?"; + } + } + public String getDisplay() { + switch (this) { + case AVAILABLE: return "Available"; + case NOTAVAILABLE: return "Not Available"; + case ENTEREDINERROR: return "Entered in Error"; + default: return "?"; + } + } + + +} + diff --git a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/DevicestatusEnumFactory.java b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/DevicestatusEnumFactory.java index 64e4d361f1c9..d316aafe5e31 100644 --- a/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/DevicestatusEnumFactory.java +++ b/hapi-fhir-structures-dstu3/src/main/java/org/hl7/fhir/dstu3/model/codesystems/DevicestatusEnumFactory.java @@ -1,70 +1,66 @@ -package org.hl7.fhir.dstu3.model.codesystems; - -/* - Copyright (c) 2011+, HL7, Inc. - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, - are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of HL7 nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - -*/ - -// Generated on Sat, Mar 25, 2017 21:03-0400 for FHIR v3.0.0 - - -import org.hl7.fhir.dstu3.model.EnumFactory; - -public class DeviceStatusEnumFactory implements EnumFactory { - - public DeviceStatus fromCode(String codeString) throws IllegalArgumentException { - if (codeString == null || "".equals(codeString)) - return null; - if ("active".equals(codeString)) - return DeviceStatus.ACTIVE; - if ("inactive".equals(codeString)) - return DeviceStatus.INACTIVE; - if ("entered-in-error".equals(codeString)) - return DeviceStatus.ENTEREDINERROR; - if ("unknown".equals(codeString)) - return DeviceStatus.UNKNOWN; - throw new IllegalArgumentException("Unknown DeviceStatus code '"+codeString+"'"); - } - - public String toCode(DeviceStatus code) { - if (code == DeviceStatus.ACTIVE) - return "active"; - if (code == DeviceStatus.INACTIVE) - return "inactive"; - if (code == DeviceStatus.ENTEREDINERROR) - return "entered-in-error"; - if (code == DeviceStatus.UNKNOWN) - return "unknown"; - return "?"; - } - - public String toSystem(DeviceStatus code) { - return code.getSystem(); - } - -} - +package org.hl7.fhir.dstu3.model.codesystems; + +/* + Copyright (c) 2011+, HL7, Inc. + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of HL7 nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +// Generated on Mon, Jan 16, 2017 12:12-0500 for FHIR v1.9.0 + + +import org.hl7.fhir.dstu3.model.EnumFactory; + +public class DevicestatusEnumFactory implements EnumFactory { + + public Devicestatus fromCode(String codeString) throws IllegalArgumentException { + if (codeString == null || "".equals(codeString)) + return null; + if ("available".equals(codeString)) + return Devicestatus.AVAILABLE; + if ("not-available".equals(codeString)) + return Devicestatus.NOTAVAILABLE; + if ("entered-in-error".equals(codeString)) + return Devicestatus.ENTEREDINERROR; + throw new IllegalArgumentException("Unknown Devicestatus code '"+codeString+"'"); + } + + public String toCode(Devicestatus code) { + if (code == Devicestatus.AVAILABLE) + return "available"; + if (code == Devicestatus.NOTAVAILABLE) + return "not-available"; + if (code == Devicestatus.ENTEREDINERROR) + return "entered-in-error"; + return "?"; + } + + public String toSystem(Devicestatus code) { + return code.getSystem(); + } + +} +