-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #315 - Allow declaring of custom types for specific profiles
- Loading branch information
1 parent
5895881
commit 1adfc4b
Showing
58 changed files
with
2,550 additions
and
11,055 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package example; | ||
|
||
import org.hl7.fhir.dstu3.model.Observation; | ||
|
||
public class CustomObservation extends Observation { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package example; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import org.hl7.fhir.dstu3.model.DateTimeType; | ||
import org.hl7.fhir.dstu3.model.Extension; | ||
import org.hl7.fhir.dstu3.model.HumanName; | ||
import org.hl7.fhir.dstu3.model.Identifier.IdentifierUse; | ||
import org.hl7.fhir.dstu3.model.Patient; | ||
import org.hl7.fhir.dstu3.model.StringType; | ||
|
||
import ca.uhn.fhir.context.FhirContext; | ||
import ca.uhn.fhir.parser.DataFormatException; | ||
import ca.uhn.fhir.rest.client.IGenericClient; | ||
|
||
public class ExtensionsDstu3 { | ||
|
||
public void customType() { | ||
|
||
IGenericClient client = FhirContext.forDstu3().newRestfulGenericClient("http://foo"); | ||
|
||
//START SNIPPET: customTypeClientSimple | ||
// Create an example patient | ||
MyPatient custPatient = new MyPatient(); | ||
custPatient.addName().addFamily("Smith").addGiven("John"); | ||
custPatient.setPetName(new StringType("Rover")); // populate the extension | ||
|
||
// Create the resource like normal | ||
client.create().resource(custPatient).execute(); | ||
|
||
// You can also read the resource back like normal | ||
custPatient = client.read().resource(MyPatient.class).withId("123").execute(); | ||
//END SNIPPET: customTypeClientSimple | ||
|
||
|
||
} | ||
|
||
public void customTypeDeclared() { | ||
|
||
|
||
//START SNIPPET: customTypeClientDeclared | ||
FhirContext ctx = FhirContext.forDstu3(); | ||
|
||
// Instruct the context that if it receives a resource which | ||
// claims to conform to the given profile (by URL), it should | ||
// use the MyPatient type to parse this resource | ||
ctx.setDefaultTypeForProfile("http://example.com/StructureDefinition/mypatient", MyPatient.class); | ||
|
||
// You can declare as many default types as you like | ||
ctx.setDefaultTypeForProfile("http://foo.com/anotherProfile", CustomObservation.class); | ||
|
||
// Create a client | ||
IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3"); | ||
|
||
// You can also read the resource back like normal | ||
Patient patient = client.read().resource(Patient.class).withId("123").execute(); | ||
if (patient instanceof MyPatient) { | ||
// If the server supplied a resource which declared to conform | ||
// to the given profile, MyPatient will have been returned so | ||
// process it differently.. | ||
} | ||
|
||
//END SNIPPET: customTypeClientDeclared | ||
|
||
|
||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static void main(String[] args) throws DataFormatException, IOException { | ||
|
||
|
||
// START SNIPPET: resourceExtension | ||
// Create an example patient | ||
Patient patient = new Patient(); | ||
patient.addIdentifier().setUse(IdentifierUse.OFFICIAL).setSystem("urn:example").setValue("7000135"); | ||
|
||
// Create an extension | ||
Extension ext = new Extension(); | ||
ext.setUrl("http://example.com/extensions#someext"); | ||
ext.setValue(new DateTimeType("2011-01-02T11:13:15")); | ||
|
||
// Add the extension to the resource | ||
patient.addExtension(ext); | ||
//END SNIPPET: resourceExtension | ||
|
||
|
||
//START SNIPPET: resourceStringExtension | ||
// Continuing the example from above, we will add a name to the patient, and then | ||
// add an extension to part of that name | ||
HumanName name = patient.addName(); | ||
name.addFamily("Shmoe"); | ||
|
||
// Add a new "given name", which is of type String | ||
StringType given = name.addGivenElement(); | ||
given.setValue("Joe"); | ||
|
||
// Create an extension and add it to the String | ||
Extension givenExt = new Extension("http://examples.com#moreext", new StringType("Hello")); | ||
given.addExtension(givenExt); | ||
//END SNIPPET: resourceStringExtension | ||
|
||
FhirContext ctx = FhirContext.forDstu3(); | ||
String output = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); | ||
System.out.println(output); | ||
|
||
|
||
//START SNIPPET: parseExtension | ||
// Get all extensions (modifier or not) for a given URL | ||
List<Extension> resourceExts = patient.getExtensionsByUrl("http://fooextensions.com#exts"); | ||
|
||
// Get all non-modifier extensions regardless of URL | ||
List<Extension> nonModExts = patient.getExtension(); | ||
|
||
//Get all non-modifier extensions regardless of URL | ||
List<Extension> modExts = patient.getModifierExtension(); | ||
//END SNIPPET: parseExtension | ||
|
||
} | ||
|
||
|
||
public void foo() { | ||
//START SNIPPET: subExtension | ||
Patient patient = new Patient(); | ||
|
||
// Add an extension (initially with no contents) to the resource | ||
Extension parent = new Extension("http://example.com#parent"); | ||
patient.addExtension(parent); | ||
|
||
// Add two extensions as children to the parent extension | ||
Extension child1 = new Extension("http://example.com#childOne", new StringType("value1")); | ||
parent.addExtension(child1); | ||
|
||
Extension child2 = new Extension("http://example.com#chilwo", new StringType("value1")); | ||
parent.addExtension(child2); | ||
//END SNIPPET: subExtension | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
hapi-fhir-base-test-mindeps-server/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
4 changes: 4 additions & 0 deletions
4
hapi-fhir-base-test-mindeps-server/.settings/org.eclipse.wst.common.project.facet.core.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<faceted-project> | ||
<installed facet="java" version="1.7"/> | ||
</faceted-project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.