Search in sources :

Example 96 with Group

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

the class GroupFhirResourceProviderIntegrationTest method shouldUpdateExistingGroupAsJson.

@Test
public void shouldUpdateExistingGroupAsJson() throws Exception {
    // Before update
    MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Group group = readResponse(response);
    Extension descExtension = group.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION);
    assertThat(group, notNullValue());
    assertThat(group, validResource());
    assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID));
    assertThat(descExtension.getValue().toString(), equalTo("Covid19 patients"));
    // Get existing group with updated name
    String jsonGroup;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_UPDATE_GROUP_DOCUMENT)) {
        Objects.requireNonNull(is);
        jsonGroup = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // Update
    response = put("/Group/" + COHORT_UUID).jsonContent(jsonGroup).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read updated record
    group = readResponse(response);
    descExtension = group.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION);
    assertThat(group, notNullValue());
    assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID));
    assertThat(group.getActive(), is(true));
    assertThat(descExtension.getValue().toString(), equalTo("Patients with at least one encounter"));
    assertThat(group, validResource());
    // Double-check via get
    response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go();
    Group updatedGroup = readResponse(response);
    descExtension = updatedGroup.getExtensionByUrl(FhirConstants.OPENMRS_FHIR_EXT_GROUP_DESCRIPTION);
    assertThat(updatedGroup, validResource());
    assertThat(updatedGroup, notNullValue());
    assertThat(updatedGroup.getActive(), is(true));
    assertThat(descExtension.getValue().toString(), equalTo("Patients with at least one encounter"));
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Group(org.hl7.fhir.r4.model.Group) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 97 with Group

use of org.hl7.fhir.r4.model.Group in project ab2d by CMSgov.

the class CapabilityStatementR4 method populateCS.

public static CapabilityStatement populateCS(String server) {
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    CapabilityStatement cs = new CapabilityStatement();
    cs.setPublisher("Centers for Medicare & Medicaid Services");
    cs.setKind(CapabilityStatement.CapabilityStatementKind.REQUIREMENTS);
    cs.setStatus(Enumerations.PublicationStatus.DRAFT);
    try {
        Date lastUpdated = sdf.parse("02/22/2020 00:00:00");
        cs.setDate(lastUpdated);
    } catch (Exception ex) {
        cs.setDate(new Date());
    }
    cs.setFhirVersion(Enumerations.FHIRVersion._4_0_0);
    cs.setPurpose("Defines FHIR R4 (V2) version of AB2D bulk data download");
    CodeType codeType = new CodeType();
    codeType.setValue(APPLICATION_JSON);
    CodeType codeType2 = new CodeType();
    codeType2.setValue("application/fhir+json");
    cs.setFormat(List.of(codeType, codeType2));
    CapabilityStatement.CapabilityStatementSoftwareComponent cssc = new CapabilityStatement.CapabilityStatementSoftwareComponent();
    cssc.setName("AB2D");
    cssc.setVersion("V2");
    try {
        Date releaseDate = sdf.parse("05/01/2020 00:00:00");
        cssc.setReleaseDate(releaseDate);
    } catch (Exception ex) {
        cssc.setReleaseDate(new Date());
    }
    cs.setSoftware(cssc);
    CapabilityStatement.CapabilityStatementImplementationComponent implementation = new CapabilityStatement.CapabilityStatementImplementationComponent();
    implementation.setDescription("AB2D FHIR R4 Bulk Data Download Implementation");
    implementation.setUrl(server);
    cs.setImplementation(implementation);
    CapabilityStatement.CapabilityStatementRestComponent rest = new CapabilityStatement.CapabilityStatementRestComponent();
    rest.setMode(CapabilityStatement.RestfulCapabilityMode.SERVER);
    CapabilityStatement.CapabilityStatementRestSecurityComponent security = new CapabilityStatement.CapabilityStatementRestSecurityComponent();
    security.setCors(true);
    CodeableConcept codeableConcept = new CodeableConcept();
    Coding coding = new Coding();
    coding.setSystem("http://hl7.org/fhir/ValueSet/restful-security-service");
    coding.setCode("OAuth");
    coding.setDisplay("OAuth");
    codeableConcept.setCoding(List.of(coding));
    codeableConcept.setText("OAuth");
    security.setService(List.of(codeableConcept));
    rest.setSecurity(security);
    List<CapabilityStatement.CapabilityStatementRestResourceOperationComponent> restComponents = new ArrayList<>();
    restComponents.add(createOperation("export", server + "/Patient/$export"));
    restComponents.add(createOperation("export by contract", server + "/Group/{contractNumber}/$export"));
    restComponents.add(createOperation("cancel", server + "/Job/{jobUuid}/$status"));
    restComponents.add(createOperation("status", server + "/Job/{jobUuid}/$status"));
    restComponents.add(createOperation("download", server + "/Job/{jobUuid}/file/{filename}"));
    restComponents.add(createOperation("capability", server + "/metadata"));
    rest.setOperation(restComponents);
    rest.setInteraction(List.of(new CapabilityStatement.SystemInteractionComponent().setCode(CapabilityStatement.SystemRestfulInteraction.BATCH)));
    cs.setRest(List.of(rest));
    return cs;
}
Also used : ArrayList(java.util.ArrayList) Date(java.util.Date) Coding(org.hl7.fhir.r4.model.Coding) CapabilityStatement(org.hl7.fhir.r4.model.CapabilityStatement) CodeType(org.hl7.fhir.r4.model.CodeType) SimpleDateFormat(java.text.SimpleDateFormat) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 98 with Group

use of org.hl7.fhir.r4.model.Group in project integration-adaptor-111 by nhsconnect.

the class EncounterReportBundleService method addSubject.

private void addSubject(Bundle bundle, Encounter encounter) {
    if (encounter.getSubjectTarget() instanceof Patient) {
        Patient patient = (Patient) encounter.getSubjectTarget();
        addEntry(bundle, patient);
        if (patient.hasGeneralPractitioner()) {
            for (Reference gp : patient.getGeneralPractitioner()) {
                Organization organization = (Organization) gp.getResource();
                addEntry(bundle, organization);
            }
        }
    }
    if (encounter.getSubjectTarget() instanceof Group) {
        Group group = (Group) encounter.getSubjectTarget();
        addEntry(bundle, group);
        for (Group.GroupMemberComponent groupMemberComponent : group.getMember()) {
            bundle.addEntry().setFullUrl(groupMemberComponent.getIdElement().getValue()).setResource(groupMemberComponent.getEntityTarget());
        }
    }
}
Also used : Group(org.hl7.fhir.dstu3.model.Group) Organization(org.hl7.fhir.dstu3.model.Organization) Reference(org.hl7.fhir.dstu3.model.Reference) Patient(org.hl7.fhir.dstu3.model.Patient)

Example 99 with Group

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

the class FHIRPathEngine method execute.

private List<Base> execute(ExecutionContext context, List<Base> focus, ExpressionNode exp, boolean atEntry) throws PathEngineException {
    // System.out.println("Evaluate {'"+exp.toString()+"'} on "+focus.toString());
    List<Base> work = new ArrayList<Base>();
    switch(exp.getKind()) {
        case Name:
            if (atEntry && exp.getName().equals("$this"))
                work.add(context.getThisItem());
            else
                for (Base item : focus) {
                    List<Base> outcome = execute(context, item, exp, atEntry);
                    for (Base base : outcome) if (base != null)
                        work.add(base);
                }
            break;
        case Function:
            List<Base> work2 = evaluateFunction(context, focus, exp);
            work.addAll(work2);
            break;
        case Constant:
            Base b = processConstant(context, exp.getConstant());
            if (b != null)
                work.add(b);
            break;
        case Group:
            work2 = execute(context, focus, exp.getGroup(), atEntry);
            work.addAll(work2);
    }
    if (exp.getInner() != null)
        work = execute(context, work, exp.getInner(), false);
    if (exp.isProximal() && exp.getOperation() != null) {
        ExpressionNode next = exp.getOpNext();
        ExpressionNode last = exp;
        while (next != null) {
            List<Base> work2 = preOperate(work, last.getOperation());
            if (work2 != null)
                work = work2;
            else if (last.getOperation() == Operation.Is || last.getOperation() == Operation.As) {
                work2 = executeTypeName(context, focus, next, false);
                work = operate(work, last.getOperation(), work2);
            } else {
                work2 = execute(context, focus, next, true);
                work = operate(work, last.getOperation(), work2);
            // System.out.println("Result of {'"+last.toString()+" "+last.getOperation().toCode()+" "+next.toString()+"'}: "+focus.toString());
            }
            last = next;
            next = next.getOpNext();
        }
    }
    // System.out.println("Result of {'"+exp.toString()+"'}: "+work.toString());
    return work;
}
Also used : ExpressionNode(org.hl7.fhir.dstu2.model.ExpressionNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Base(org.hl7.fhir.dstu2.model.Base)

Example 100 with Group

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

the class FHIRPathEngine method executeType.

private TypeDetails executeType(ExecutionTypeContext context, TypeDetails focus, ExpressionNode exp, boolean atEntry) throws PathEngineException, DefinitionException {
    // System.out.println("Evaluate {'"+exp.toString()+"'} on "+focus.toString());
    TypeDetails result = new TypeDetails(null);
    switch(exp.getKind()) {
        case Name:
            if (atEntry && exp.getName().equals("$this"))
                result.update(context.getThisItem());
            else {
                for (String s : focus.getTypes()) {
                    result.update(executeType(s, exp, atEntry));
                }
                if (result.hasNoTypes())
                    throw new PathEngineException("The name " + exp.getName() + " is not valid for any of the possible types: " + focus.describe());
            }
            break;
        case Function:
            result.update(evaluateFunctionType(context, focus, exp));
            break;
        case Constant:
            result.addType(readConstantType(context, exp.getConstant()));
            break;
        case Group:
            result.update(executeType(context, focus, exp.getGroup(), atEntry));
    }
    exp.setTypes(result);
    if (exp.getInner() != null) {
        result = executeType(context, result, exp.getInner(), false);
    }
    if (exp.isProximal() && exp.getOperation() != null) {
        ExpressionNode next = exp.getOpNext();
        ExpressionNode last = exp;
        while (next != null) {
            TypeDetails work;
            if (last.getOperation() == Operation.Is || last.getOperation() == Operation.As)
                work = executeTypeName(context, focus, next, atEntry);
            else
                work = executeType(context, focus, next, atEntry);
            result = operateTypes(result, last.getOperation(), work);
            last = next;
            next = next.getOpNext();
        }
        exp.setOpTypes(result);
    }
    return result;
}
Also used : TypeDetails(org.hl7.fhir.dstu2.model.ExpressionNode.TypeDetails) ExpressionNode(org.hl7.fhir.dstu2.model.ExpressionNode) PathEngineException(org.hl7.fhir.exceptions.PathEngineException)

Aggregations

Test (org.junit.Test)106 Group (org.hl7.fhir.r4.model.Group)74 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)59 ArrayList (java.util.ArrayList)57 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)50 Group (org.hl7.fhir.dstu3.model.Group)44 FHIRException (org.hl7.fhir.exceptions.FHIRException)37 Cohort (org.openmrs.Cohort)32 Test (org.junit.jupiter.api.Test)29 InputStream (java.io.InputStream)21 Reference (org.hl7.fhir.r4.model.Reference)21 List (java.util.List)16 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)16 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 Coding (org.hl7.fhir.r4.model.Coding)16 Diagnosis (gov.cms.bfd.server.war.commons.Diagnosis)15 IOException (java.io.IOException)13 IdType (org.hl7.fhir.dstu3.model.IdType)13 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)13 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)13