Search in sources :

Example 16 with ResourceType

use of org.hl7.fhir.r4.model.ResourceType in project openmrs-module-fhir2 by openmrs.

the class PatientFhirResourceProviderIntegrationTest method shouldReturnForPatientTypeEverythingWhenCountIsSpecifiedAsXml.

@Test
public void shouldReturnForPatientTypeEverythingWhenCountIsSpecifiedAsXml() throws Exception {
    MockHttpServletResponse response = get("/Patient/$everything?_count=5").accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Bundle result = readBundleResponse(response);
    assertThat(result, notNullValue());
    assertThat(result.getType(), equalTo(Bundle.BundleType.SEARCHSET));
    assertThat(result, hasProperty("total", equalTo(46)));
    assertThat(result.getEntry(), hasSize(5));
    List<Bundle.BundleEntryComponent> entries = result.getEntry();
    assertThat(entries, everyItem(hasProperty("fullUrl", startsWith("http://localhost/ws/fhir2/R4/"))));
    assertThat(entries, everyItem(hasResource(hasProperty("resourceType", in(getEverythingValidResourceTypes())))));
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 17 with ResourceType

use of org.hl7.fhir.r4.model.ResourceType in project org.hl7.fhir.core by hapifhir.

the class ExamplesPackageBuilder method process.

private void process(String source) throws FHIRFormatError, FileNotFoundException, IOException {
    Set<String> set = new HashSet<>();
    for (File f : new File(source).listFiles()) {
        if (f.getName().endsWith(".json")) {
            JsonObject obj = JsonTrackingParser.parseJson(new FileInputStream(f));
            if (obj.has("resourceType") && obj.has("id")) {
                String type = obj.get("resourceType").getAsString();
                String id = obj.get("id").getAsString();
                byte[] content = TextFile.fileToBytes(f);
                if (type.equals("ConceptMap")) {
                    System.out.println("convert " + f.getName());
                    content = r5ToR4B(content);
                    TextFile.bytesToFile(content, f);
                }
            // TextFile.bytesToFile(content, Utilities.path(dest2, type+"-"+id+".json"));
            // if (!set.contains(type+"/"+id)) {
            // set.add(type+"/"+id);
            // pck.addFile(Category.RESOURCE, type+"-"+id+".json", content);
            // }
            }
        }
    }
// pck.finish();
// 
}
Also used : JsonObject(com.google.gson.JsonObject) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Example 18 with ResourceType

use of org.hl7.fhir.r4.model.ResourceType in project org.hl7.fhir.core by hapifhir.

the class CorePackageTools method buildXml.

private void buildXml(String json, String xml, String version) throws FHIRFormatError, IOException {
    for (File f : new File(Utilities.path(json, "package")).listFiles()) {
        if (f.getName().endsWith(".json")) {
            JsonObject j = new JsonTrackingParser().parseJson(f);
            if (j.has("resourceType")) {
                if ("1.4".equals(version)) {
                    String n = f.getName();
                    System.out.println(n);
                    String xn = Utilities.changeFileExt(n, ".xml");
                    org.hl7.fhir.dstu2016may.model.Resource r = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(new FileInputStream(f));
                    new org.hl7.fhir.dstu2016may.formats.XmlParser().setOutputStyle(org.hl7.fhir.dstu2016may.formats.IParser.OutputStyle.NORMAL).compose(new FileOutputStream(Utilities.path(xml, "package", xn)), r);
                }
            }
        }
    }
}
Also used : JsonObject(com.google.gson.JsonObject) JsonTrackingParser(org.hl7.fhir.utilities.json.JsonTrackingParser) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 19 with ResourceType

use of org.hl7.fhir.r4.model.ResourceType in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parse.

public Element parse(JsonObject object) throws FHIRFormatError, DefinitionException {
    JsonElement rt = object.get("resourceType");
    if (rt == null) {
        logError(line(object), col(object), "$", IssueType.INVALID, "Unable to find resourceType property", IssueSeverity.FATAL);
        return null;
    } else {
        String name = rt.getAsString();
        String path = "/" + name;
        StructureDefinition sd = getDefinition(line(object), col(object), name);
        if (sd == null)
            return null;
        Element result = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd));
        checkObject(object, path);
        result.markLocation(line(object), col(object));
        result.setType(name);
        parseChildren(path, object, result, true);
        result.numberChildren();
        return result;
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) JsonElement(com.google.gson.JsonElement) JsonElement(com.google.gson.JsonElement) SpecialElement(org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement)

Example 20 with ResourceType

use of org.hl7.fhir.r4.model.ResourceType in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parseChildren.

private void parseChildren(String path, JsonObject object, Element context, boolean hasResourceType) throws DefinitionException, FHIRFormatError {
    reapComments(object, context);
    List<Property> properties = context.getProperty().getChildProperties(context.getName(), null);
    Set<String> processed = new HashSet<String>();
    if (hasResourceType)
        processed.add("resourceType");
    processed.add("fhir_comments");
    // first pass: process the properties
    for (Property property : properties) {
        if (property.isChoice()) {
            for (TypeRefComponent type : property.getDefinition().getType()) {
                String eName = property.getName().substring(0, property.getName().length() - 3) + Utilities.capitalize(type.getCode());
                if (!isPrimitive(type.getCode()) && object.has(eName)) {
                    parseChildComplex(path, object, context, processed, property, eName);
                    break;
                } else if (isPrimitive(type.getCode()) && (object.has(eName) || object.has("_" + eName))) {
                    parseChildPrimitive(object, context, processed, property, path, eName);
                    break;
                }
            }
        } else if (property.isPrimitive(property.getType(null))) {
            parseChildPrimitive(object, context, processed, property, path, property.getName());
        } else if (object.has(property.getName())) {
            parseChildComplex(path, object, context, processed, property, property.getName());
        }
    }
    // second pass: check for things not processed
    if (policy != ValidationPolicy.NONE) {
        for (Entry<String, JsonElement> e : object.entrySet()) {
            if (!processed.contains(e.getKey())) {
                logError(line(e.getValue()), col(e.getValue()), path, IssueType.STRUCTURE, "Unrecognised property '@" + e.getKey() + "'", IssueSeverity.ERROR);
            }
        }
    }
}
Also used : TypeRefComponent(org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent) JsonElement(com.google.gson.JsonElement) HashSet(java.util.HashSet)

Aggregations

JsonElement (com.google.gson.JsonElement)33 HashSet (java.util.HashSet)26 Bundle (org.hl7.fhir.r4.model.Bundle)24 ResourceType (org.hl7.fhir.r4.model.Enumerations.ResourceType)21 Test (org.junit.Test)20 Nonnull (javax.annotation.Nonnull)18 ArrayList (java.util.ArrayList)15 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)10 FhirContext (ca.uhn.fhir.context.FhirContext)9 File (java.io.File)9 Row (org.apache.spark.sql.Row)9 IdType (org.hl7.fhir.dstu3.model.IdType)9 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 JsonObject (com.google.gson.JsonObject)8 Test (org.junit.jupiter.api.Test)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 IOException (java.io.IOException)7 List (java.util.List)7 Bundle (org.hl7.fhir.dstu3.model.Bundle)7 Resource (org.hl7.fhir.r4.model.Resource)7