Search in sources :

Example 56 with Annotation

use of org.hl7.fhir.r5.model.Annotation in project bunsen by cerner.

the class FhirEncodersTest method annotation.

@Test
public void annotation() throws FHIRException {
    Annotation original = medRequest.getNoteFirstRep();
    Annotation decoded = decodedMedRequest.getNoteFirstRep();
    Assert.assertEquals(original.getText(), medDataset.select(functions.expr("note[0].text")).head().get(0));
    Assert.assertEquals(original.getText(), decoded.getText());
    Assert.assertEquals(original.getAuthorReference().getReference(), decoded.getAuthorReference().getReference());
}
Also used : Annotation(org.hl7.fhir.r4.model.Annotation) Test(org.junit.Test)

Example 57 with Annotation

use of org.hl7.fhir.r5.model.Annotation in project bunsen by cerner.

the class TestData method newMedRequest.

/**
 * Returns a FHIR medication request for testing purposes.
 */
public static MedicationRequest newMedRequest() {
    MedicationRequest medReq = new MedicationRequest();
    medReq.setId("test-med");
    // Medication code
    CodeableConcept med = new CodeableConcept();
    med.addCoding().setSystem("http://www.nlm.nih.gov/research/umls/rxnorm").setCode("582620").setDisplay("Nizatidine 15 MG/ML Oral Solution [Axid]");
    med.setText("Nizatidine 15 MG/ML Oral Solution [Axid]");
    medReq.setMedication(med);
    Annotation annotation = new Annotation();
    annotation.setText("Test medication note.");
    annotation.setAuthor(new Reference("Provider/example").setDisplay("Example provider."));
    medReq.addNote(annotation);
    return medReq;
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) Reference(org.hl7.fhir.r4.model.Reference) Annotation(org.hl7.fhir.r4.model.Annotation) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 58 with Annotation

use of org.hl7.fhir.r5.model.Annotation in project bunsen by cerner.

the class TestData method newMedRequest.

/**
 * Returns a FHIR medication request for testing purposes.
 */
public static MedicationRequest newMedRequest() {
    MedicationRequest medReq = new MedicationRequest();
    medReq.setId("test-med");
    // Medication code
    CodeableConcept med = new CodeableConcept();
    med.addCoding().setSystem("http://www.nlm.nih.gov/research/umls/rxnorm").setCode("582620").setDisplay("Nizatidine 15 MG/ML Oral Solution [Axid]");
    med.setText("Nizatidine 15 MG/ML Oral Solution [Axid]");
    medReq.setMedication(med);
    Annotation annotation = new Annotation();
    annotation.setText("Test medication note.");
    annotation.setAuthor(new Reference("Provider/example").setDisplay("Example provider."));
    medReq.addNote(annotation);
    return medReq;
}
Also used : MedicationRequest(org.hl7.fhir.dstu3.model.MedicationRequest) Reference(org.hl7.fhir.dstu3.model.Reference) Annotation(org.hl7.fhir.dstu3.model.Annotation) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 59 with Annotation

use of org.hl7.fhir.r5.model.Annotation 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"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Parameters(org.hl7.fhir.dstu3.model.Parameters) ServletInputStream(javax.servlet.ServletInputStream) ServletInputStream(javax.servlet.ServletInputStream) InputStream(java.io.InputStream) Injector(com.google.inject.Injector) FHIRParameter(gov.cms.dpc.fhir.annotations.FHIRParameter) Patient(org.hl7.fhir.dstu3.model.Patient) FHIRParameter(gov.cms.dpc.fhir.annotations.FHIRParameter) Parameter(org.glassfish.jersey.server.model.Parameter) IParser(ca.uhn.fhir.parser.IParser) Test(org.junit.jupiter.api.Test)

Example 60 with Annotation

use of org.hl7.fhir.r5.model.Annotation 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"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Parameters(org.hl7.fhir.dstu3.model.Parameters) ServletInputStream(javax.servlet.ServletInputStream) WebApplicationException(javax.ws.rs.WebApplicationException) ServletInputStream(javax.servlet.ServletInputStream) InputStream(java.io.InputStream) Injector(com.google.inject.Injector) FHIRParameter(gov.cms.dpc.fhir.annotations.FHIRParameter) Patient(org.hl7.fhir.dstu3.model.Patient) FHIRParameter(gov.cms.dpc.fhir.annotations.FHIRParameter) Parameter(org.glassfish.jersey.server.model.Parameter) IParser(ca.uhn.fhir.parser.IParser) Test(org.junit.jupiter.api.Test)

Aggregations

NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 Trace (com.newrelic.api.agent.Trace)13 Operation (gov.cms.bfd.server.war.Operation)13 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)12 Annotation (org.hl7.fhir.r4.model.Annotation)12 NoResultException (javax.persistence.NoResultException)11 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)9 Annotation (org.hl7.fhir.dstu3.model.Annotation)9 Search (ca.uhn.fhir.rest.annotation.Search)8 OffsetLinkBuilder (gov.cms.bfd.server.war.commons.OffsetLinkBuilder)8 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)8 Read (ca.uhn.fhir.rest.annotation.Read)7 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)7 Patient (org.hl7.fhir.dstu3.model.Patient)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)6 Resource (org.hl7.fhir.r4.model.Resource)6 Test (org.junit.jupiter.api.Test)6