Documentation enhancements
This commit is contained in:
parent
b1b99e1aa2
commit
8a77ac939d
Binary file not shown.
|
@ -7,6 +7,7 @@ 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;
|
||||
|
@ -41,23 +42,21 @@ public void nonNull() {
|
|||
// START SNIPPET: nonNull
|
||||
Observation observation = new Observation();
|
||||
|
||||
// None of these calls will return null, but instead create their respective
|
||||
// None of these calls will return null, but instead create their
|
||||
// respective
|
||||
// child elements.
|
||||
IdentifierDt identifierDt = observation.getIdentifier();
|
||||
PeriodDt periodDt = observation.getIdentifier().getPeriod();
|
||||
DateTimeDt activeDt = observation.getIdentifier().getPeriod().getStart();
|
||||
|
||||
// DateTimeDt is a FHIR primitive however, so the following will return null
|
||||
// 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();
|
||||
// END SNIPPET: nonNull
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void codes() {
|
||||
// START SNIPPET: codes
|
||||
Patient patient = new Patient();
|
||||
|
@ -76,10 +75,27 @@ patient.setGender(AdministrativeGenderCodesEnum.M);
|
|||
public static void main(String[] args) {
|
||||
datatypes();
|
||||
|
||||
// START SNIPPET: observation
|
||||
Observation observation = new Observation();
|
||||
|
||||
// Create a quantity datatype
|
||||
QuantityDt q = new QuantityDt();
|
||||
q.setValue(185);
|
||||
q.setSystem("http://unitsofmeasure.org");
|
||||
q.setCode("lbs");
|
||||
|
||||
// Put the datatype in the observation
|
||||
observation.setValue(q);
|
||||
|
||||
// Set the reference range
|
||||
observation.getReferenceRangeFirstRep().setLow(100);
|
||||
observation.getReferenceRangeFirstRep().setHigh(200);
|
||||
|
||||
// END SNIPPET: observation
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void namesHard() {
|
||||
// START SNIPPET: namesHard
|
||||
Patient patient = new Patient();
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
package example;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
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.parser.DataFormatException;
|
||||
|
@ -11,8 +18,7 @@ import ca.uhn.fhir.validation.ValidationFailureException;
|
|||
|
||||
public class ValidatorExamples {
|
||||
|
||||
public static void main(String[] args) throws DataFormatException, IOException {
|
||||
|
||||
public void validateResource() {
|
||||
//START SNIPPET: basicValidation
|
||||
// As always, you need a context
|
||||
FhirContext ctx = new FhirContext();
|
||||
|
@ -35,10 +41,45 @@ public class ValidatorExamples {
|
|||
|
||||
System.out.println("Validation failed");
|
||||
|
||||
// The ValidationFailureException which gets thrown by the validator
|
||||
// will contain an OperationOutcome resource describing the failure
|
||||
String results = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(e.getOperationOutcome());
|
||||
System.out.println(results);
|
||||
}
|
||||
//END SNIPPET: basicValidation
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws DataFormatException, IOException {
|
||||
validateFiles();
|
||||
|
||||
}
|
||||
|
||||
private static void validateFiles() throws IOException, FileNotFoundException {
|
||||
//START SNIPPET: validateFiles
|
||||
FhirContext ctx = new FhirContext();
|
||||
|
||||
// Create a validator and configure it
|
||||
FhirValidator validator = ctx.newValidator();
|
||||
validator.setValidateAgainstStandardSchema(true);
|
||||
validator.setValidateAgainstStandardSchematron(true);
|
||||
|
||||
// Get a list of files in a given directory
|
||||
String[] fileList = new File("/home/some/dir").list(new WildcardFileFilter("*.txt"));
|
||||
for (String nextFile : fileList) {
|
||||
|
||||
// For each file, load the contents into a string
|
||||
String nextFileContents = IOUtils.toString(new FileReader(nextFile));
|
||||
|
||||
// Parse that string (this example assumes JSON encoding)
|
||||
IResource resource = ctx.newJsonParser().parseResource(nextFileContents);
|
||||
|
||||
// Apply the validation. This will throw an exception on the first validation failure
|
||||
validator.validate(resource);
|
||||
}
|
||||
|
||||
// If we make it here with no exception, all the files validated!
|
||||
//START SNIPPET: validateFiles
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -104,6 +104,23 @@
|
|||
|
||||
</section>
|
||||
|
||||
<section name="Examples">
|
||||
|
||||
<subsection name="Populating an Observation Resource">
|
||||
|
||||
<p>
|
||||
The following example shows how to create an observation resource containing
|
||||
a numeric datatype.
|
||||
</p>
|
||||
<macro name="snippet">
|
||||
<param name="id" value="observation" />
|
||||
<param name="file" value="examples/src/main/java/example/FhirDataModel.java" />
|
||||
</macro>
|
||||
|
||||
</subsection>
|
||||
|
||||
</section>
|
||||
|
||||
</body>
|
||||
|
||||
</document>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<subsection name="Background">
|
||||
|
||||
<p>
|
||||
FHIR resource definitions are distributed with a set of XML schema files (XDS)
|
||||
FHIR resource definitions are distributed with a set of XML schema files (XSD)
|
||||
as well as a set of XML Schematron (SCH) files. These two sets of files are
|
||||
complimentary to each other, meaning that in order to claim compliance to the
|
||||
FHIR specification, your resources must validate against both sets.
|
||||
|
@ -60,6 +60,19 @@
|
|||
|
||||
</subsection>
|
||||
|
||||
<subsection name="Validating a Set of Files">
|
||||
|
||||
<p>
|
||||
The following example shows how to load a set of resources from files
|
||||
on disk and validate each one.
|
||||
</p>
|
||||
<macro name="snippet">
|
||||
<param name="id" value="validateFiles" />
|
||||
<param name="file" value="examples/src/main/java/example/ValidatorExamples.java" />
|
||||
</macro>
|
||||
|
||||
</subsection>
|
||||
|
||||
</section>
|
||||
|
||||
</body>
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.junit.Test;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.util.FhirTerser;
|
||||
|
||||
|
@ -18,6 +19,7 @@ public class FhirTerserTest {
|
|||
public void testGetAllPopulatedChildElementsOfType() {
|
||||
|
||||
Patient p = new Patient();
|
||||
p.setGender(AdministrativeGenderCodesEnum.M);
|
||||
p.addIdentifier().setSystem("urn:foo");
|
||||
p.addAddress().addLine("Line1");
|
||||
p.addAddress().addLine("Line2");
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
/target/
|
||||
/bin/
|
||||
|
|
Loading…
Reference in New Issue