use of org.hl7.fhir.dstu3.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"));
}
use of org.hl7.fhir.dstu3.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;
}
use of org.hl7.fhir.dstu3.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());
}
}
}
use of org.hl7.fhir.dstu3.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;
}
use of org.hl7.fhir.dstu3.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;
}
Aggregations