use of org.hl7.fhir.r5.formats.IParser in project dpc-app by CMSgov.
the class PractitionerResourceTest method testUpdatePractitionerNotImplemented.
@Test
public void testUpdatePractitionerNotImplemented() throws IOException {
IGenericClient client = APIAuthHelpers.buildAuthenticatedClient(ctx, getBaseURL(), ORGANIZATION_TOKEN, PUBLIC_KEY_ID, PRIVATE_KEY);
final IParser parser = ctx.newJsonParser();
APITestHelpers.setupPractitionerTest(client, parser);
// Grab a practitioner to update
final Bundle practitioners = client.search().forResource(Practitioner.class).returnBundle(Bundle.class).encodedJson().execute();
final Practitioner practitioner = (Practitioner) practitioners.getEntryFirstRep().getResource();
practitioner.setBirthDate(Date.valueOf("1989-01-01"));
IUpdateExecutable update = client.update().resource(practitioner).withId(practitioner.getId());
assertThrows(NotImplementedOperationException.class, update::execute);
}
use of org.hl7.fhir.r5.formats.IParser in project dpc-app by CMSgov.
the class GroupResourceTest method testMissingProvenance.
@Test
void testMissingProvenance() throws IOException {
final IParser parser = ctx.newJsonParser();
IGenericClient client = APIAuthHelpers.buildAuthenticatedClient(ctx, getBaseURL(), ORGANIZATION_TOKEN, PUBLIC_KEY_ID, PRIVATE_KEY);
APITestHelpers.setupPatientTest(client, parser);
APITestHelpers.setupPractitionerTest(client, parser);
// Create a patient
final Bundle specificSearch = client.search().forResource(Patient.class).where(Patient.IDENTIFIER.exactly().systemAndCode(DPCIdentifierSystem.MBI.getSystem(), "4S41C00AA00")).returnBundle(Bundle.class).encodedJson().execute();
assertEquals(1, specificSearch.getTotal(), "Should have a single patient");
final Patient patient = (Patient) specificSearch.getEntryFirstRep().getResource();
// Create the practitioner
final Bundle practSearch = client.search().forResource(Practitioner.class).where(Practitioner.IDENTIFIER.exactly().code("1232131239")).returnBundle(Bundle.class).encodedJson().execute();
assertEquals(1, practSearch.getTotal(), "Should have a specific provider");
// Fetch the provider directly
final Practitioner foundProvider = (Practitioner) practSearch.getEntryFirstRep().getResource();
final Group group = SeedProcessor.createBaseAttributionGroup(FHIRExtractors.getProviderNPI(foundProvider), ORGANIZATION_ID);
final Reference patientRef = new Reference(patient.getIdElement());
group.addMember().setEntity(patientRef);
// Submit the group
final ICreateTyped creation = client.create().resource(group).encodedJson();
final InvalidRequestException invalidRequestException = assertThrows(InvalidRequestException.class, creation::execute, "Should throw a 400");
final OperationOutcome operationOutcome = (OperationOutcome) invalidRequestException.getOperationOutcome();
assertAll(() -> assertEquals(HttpStatus.BAD_REQUEST_400, invalidRequestException.getStatusCode(), "Should have 400 status"), () -> assertEquals("Must have X-Provenance header", operationOutcome.getIssueFirstRep().getDetails().getText(), "Should have correct message"));
// Try again with provenance
final Provenance provenance = new Provenance();
provenance.setRecorded(Date.valueOf(Instant.now().atZone(ZoneOffset.UTC).toLocalDate()));
final Coding coding = new Coding();
coding.setSystem("http://hl7.org/fhir/v3/ActReason");
coding.setCode("TREAT");
provenance.setReason(Collections.singletonList(coding));
provenance.setTarget(Collections.singletonList(patientRef));
final Provenance.ProvenanceAgentComponent component = new Provenance.ProvenanceAgentComponent();
final Coding roleCode = new Coding();
roleCode.setSystem(V3RoleClass.AGNT.getSystem());
roleCode.setCode(V3RoleClass.AGNT.toCode());
final CodeableConcept roleConcept = new CodeableConcept();
roleConcept.addCoding(roleCode);
component.setRole(Collections.singletonList(roleConcept));
component.setWho(new Reference(new IdType("Organization", ORGANIZATION_ID)));
component.setOnBehalfOf(new Reference(foundProvider.getIdElement()));
provenance.addAgent(component);
creation.withAdditionalHeader("X-Provenance", ctx.newJsonParser().encodeResourceToString(provenance));
creation.execute();
}
use of org.hl7.fhir.r5.formats.IParser in project dpc-app by CMSgov.
the class SeedCommand method seedProviderBundle.
private void seedProviderBundle(FHIREntityConverter converter, DSLContext context, IParser parser, UUID organizationID) throws IOException {
try (final InputStream providerBundleStream = SeedCommand.class.getClassLoader().getResourceAsStream(PROVIDER_BUNDLE)) {
final Parameters parameters = parser.parseResource(Parameters.class, providerBundleStream);
final Bundle providerBundle = (Bundle) parameters.getParameterFirstRep().getResource();
final List<ProviderEntity> providers = BundleParser.parse(Practitioner.class, providerBundle, (provider) -> converter.fromFHIR(ProviderEntity.class, provider), organizationID);
providers.stream().map(entity -> providersEntityToRecord(context, entity)).forEach(context::executeInsert);
}
}
use of org.hl7.fhir.r5.formats.IParser in project dpc-app by CMSgov.
the class ParamResourceFactoryTest method testNamedResource.
@Test
void testNamedResource() throws IOException {
final Parameters parameters = new Parameters();
final Patient unnamedPatient = new Patient();
final Patient namedPatient = new Patient();
namedPatient.addName().setFamily("Patient").addGiven("Test");
parameters.addParameter().setResource(unnamedPatient);
parameters.addParameter().setResource(namedPatient).setName("named");
final HttpServletRequest mock = Mockito.mock(HttpServletRequest.class);
final ServletInputStream mockStream = Mockito.mock(ServletInputStream.class);
final IParser parser = Mockito.mock(IParser.class);
Mockito.when(parser.parseResource(Mockito.eq(Parameters.class), Mockito.any(InputStream.class))).thenReturn(parameters);
final Injector mockInjector = Mockito.mock(Injector.class);
Mockito.when(mockInjector.getInstance(HttpServletRequest.class)).thenReturn(mock);
Mockito.when(mock.getInputStream()).thenReturn(mockStream);
final Parameter parameter = Mockito.mock(Parameter.class);
final FHIRParameter annotation = Mockito.mock(FHIRParameter.class);
Mockito.when(annotation.name()).thenReturn("named");
Mockito.when(parameter.getAnnotation(FHIRParameter.class)).thenReturn(annotation);
Mockito.when(parameter.getRawType()).thenAnswer(answer -> Patient.class);
final ParamResourceFactory factory = new ParamResourceFactory(mockInjector, parameter, parser);
assertAll(() -> assertTrue(namedPatient.equalsDeep((Patient) factory.provide()), "Should have returned dummy patient"), () -> assertFalse(unnamedPatient.equalsDeep((Patient) factory.provide()), "Should have returned dummy patient"));
}
use of org.hl7.fhir.r5.formats.IParser in project dpc-app by CMSgov.
the class ParamResourceFactoryTest method testMissingResource.
@Test
void testMissingResource() throws IOException {
final Parameters parameters = new Parameters();
final Patient dummyPatient = new Patient();
parameters.addParameter().setResource(dummyPatient);
final HttpServletRequest mock = Mockito.mock(HttpServletRequest.class);
final ServletInputStream mockStream = Mockito.mock(ServletInputStream.class);
final IParser parser = Mockito.mock(IParser.class);
Mockito.when(parser.parseResource(Mockito.eq(Parameters.class), Mockito.any(InputStream.class))).thenReturn(parameters);
final Injector mockInjector = Mockito.mock(Injector.class);
Mockito.when(mockInjector.getInstance(HttpServletRequest.class)).thenReturn(mock);
Mockito.when(mock.getInputStream()).thenReturn(mockStream);
final Parameter parameter = Mockito.mock(Parameter.class);
final FHIRParameter annotation = Mockito.mock(FHIRParameter.class);
Mockito.when(annotation.name()).thenReturn("missing");
Mockito.when(parameter.getAnnotation(FHIRParameter.class)).thenReturn(annotation);
Mockito.when(parameter.getRawType()).thenAnswer(answer -> Patient.class);
final ParamResourceFactory factory = new ParamResourceFactory(mockInjector, parameter, parser);
final WebApplicationException exception = assertThrows(WebApplicationException.class, factory::provide, "Should throw an exception");
assertAll(() -> assertEquals(HttpStatus.BAD_REQUEST_400, exception.getResponse().getStatus(), "Should be a bad request"), () -> assertEquals("Cannot find matching parameter named `missing`", exception.getMessage(), "Should output which parameter is missing"));
}
Aggregations