Merge branch 'master' of github.com:jamesagnew/hapi-fhir

This commit is contained in:
James Agnew 2015-04-24 12:40:24 -04:00
commit e147c74df7
5 changed files with 94 additions and 19 deletions

View File

@ -357,6 +357,13 @@ public class FhirContext {
return new FhirTerser(this);
}
/**
* Create a new validator instance.
* <p>
* Note on thread safety: Validators are thread safe, you may use a single validator
* in multiple threads. (This is in contrast to parsers)
* </p>
*/
public FhirValidator newValidator() {
return new FhirValidator(this);
}

View File

@ -1569,7 +1569,7 @@ class ParserState<T> {
return;
}
case RESOURCE: {
if (myInstance instanceof IResource) {
if (myInstance instanceof IResource || myInstance instanceof IElement) {
ParserState<T>.PreResourceStateHapi state = new PreResourceStateHapi(myInstance, child.getMutator(), null);
push(state);
} else {
@ -1842,7 +1842,7 @@ class ParserState<T> {
@Override
public void wereBack() {
super.wereBack();
if (myEntry == null) {
if (myEntry == null && myMutator == null) {
myObject = (T) getCurrentElement();
}

View File

@ -6,6 +6,7 @@ import static org.junit.Assert.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import net.sf.json.JSON;
import net.sf.json.JSONSerializer;
@ -37,6 +38,8 @@ import ca.uhn.fhir.model.dstu2.resource.MedicationPrescription;
import ca.uhn.fhir.model.dstu2.resource.Observation;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.dstu2.resource.QuestionnaireAnswers;
import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum;
import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
import ca.uhn.fhir.model.dstu2.valueset.ObservationReliabilityEnum;
import ca.uhn.fhir.model.dstu2.valueset.ObservationStatusEnum;
@ -61,6 +64,36 @@ public class JsonParserDstu2Test {
assertEquals("{\"resourceType\":\"Binary\",\"id\":\"11\",\"meta\":{\"versionId\":\"22\"},\"contentType\":\"foo\",\"content\":\"AQIDBA==\"}", val);
}
/**
* See #163
*/
@Test
public void testParseResourceType() {
IParser jsonParser = ourCtx.newJsonParser().setPrettyPrint(true);
// Patient
Patient patient = new Patient();
String patientId = UUID.randomUUID().toString();
patient.setId(new IdDt("Patient", patientId));
patient.addName().addGiven("John").addFamily("Smith");
patient.setGender(AdministrativeGenderEnum.MALE);
patient.setBirthDate(new DateDt("1987-04-16"));
// Bundle
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = new ca.uhn.fhir.model.dstu2.resource.Bundle();
bundle.setType(BundleTypeEnum.COLLECTION);
bundle.addEntry().setResource(patient);
String bundleText = jsonParser.encodeResourceToString(bundle);
ourLog.info(bundleText);
ca.uhn.fhir.model.dstu2.resource.Bundle reincarnatedBundle = jsonParser.parseResource (ca.uhn.fhir.model.dstu2.resource.Bundle.class, bundleText);
Patient reincarnatedPatient = reincarnatedBundle.getAllPopulatedChildElementsOfType(Patient.class).get(0);
assertEquals("Patient", patient.getId().getResourceType());
assertEquals("Patient", reincarnatedPatient.getId().getResourceType());
}
/**
* See #144 and #146
*/
@ -84,7 +117,6 @@ public class JsonParserDstu2Test {
Assert.assertThat(message, containsString("contained"));
}
@Test
public void testEncodeBundleOldBundleNoText() {
@ -109,7 +141,8 @@ public class JsonParserDstu2Test {
ca.uhn.fhir.model.dstu2.resource.Bundle b = new ca.uhn.fhir.model.dstu2.resource.Bundle();
b.getText().setDiv("");
b.getText().getStatus().setValueAsString("");;
b.getText().getStatus().setValueAsString("");
;
Entry e = b.addEntry();
e.setResource(new Patient());
@ -537,7 +570,6 @@ public class JsonParserDstu2Test {
assertThat(reencoded, containsString("contained"));
}
@Test
public void testParseAndEncodeBundle() throws Exception {
String content = IOUtils.toString(JsonParserDstu2Test.class.getResourceAsStream("/bundle-example.json"));
@ -604,7 +636,6 @@ public class JsonParserDstu2Test {
assertEquals("Medication/example", p.getMedication().getReference().getValue());
assertSame(p.getMedication().getResource(), m);
String reencoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(parsed);
ourLog.info(reencoded);

View File

@ -6,6 +6,7 @@ import static org.junit.Assert.*;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.apache.commons.io.IOUtils;
import org.custommonkey.xmlunit.Diff;
@ -36,6 +37,8 @@ import ca.uhn.fhir.model.dstu2.resource.MedicationPrescription;
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.dstu2.valueset.AdministrativeGenderEnum;
import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum;
import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum;
import ca.uhn.fhir.model.primitive.DateDt;
import ca.uhn.fhir.model.primitive.DateTimeDt;
@ -54,6 +57,35 @@ public class XmlParserDstu2Test {
XMLUnit.setIgnoreWhitespace(true);
}
/**
* See #163
*/
@Test
public void testParseResourceType() {
IParser xmlParser = ourCtx.newXmlParser().setPrettyPrint(true);
// Patient
Patient patient = new Patient();
String patientId = UUID.randomUUID().toString();
patient.setId(new IdDt("Patient", patientId));
patient.addName().addGiven("John").addFamily("Smith");
patient.setGender(AdministrativeGenderEnum.MALE);
patient.setBirthDate(new DateDt("1987-04-16"));
// Bundle
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = new ca.uhn.fhir.model.dstu2.resource.Bundle();
bundle.setType(BundleTypeEnum.COLLECTION);
bundle.addEntry().setResource(patient);
String bundleText = xmlParser.encodeResourceToString(bundle);
ourLog.info(bundleText);
ca.uhn.fhir.model.dstu2.resource.Bundle reincarnatedBundle = xmlParser.parseResource (ca.uhn.fhir.model.dstu2.resource.Bundle.class, bundleText);
Patient reincarnatedPatient = reincarnatedBundle.getAllPopulatedChildElementsOfType(Patient.class).get(0);
assertEquals("Patient", patient.getId().getResourceType());
assertEquals("Patient", reincarnatedPatient.getId().getResourceType());
}
/**
* see #144 and #146

View File

@ -150,6 +150,11 @@
credentials to client requests it makes). Thanks to Harsha Kumara for
the suggestion!
</action>
<action type="fix" issue="163">
Fix regression in early 1.0 builds where resource type sometimes does not get
populated in a resource ID when the resource is parsed. Thanks to
Nick Peterson for reporting, and for providing a test case!
</action>
</release>
<release version="0.9" date="2015-Mar-14">
<action type="add">