Search in sources :

Example 26 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project elexis-server by elexis.

the class ConditionTest method createCondition.

@Test
public void createCondition() {
    Condition condition = new Condition();
    Narrative narrative = new Narrative();
    String divEncodedText = "Test\nText".replaceAll("(\r\n|\r|\n)", "<br />");
    narrative.setDivAsString(divEncodedText);
    condition.setText(narrative);
    condition.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    condition.addCategory(new CodeableConcept().addCoding(new Coding(ConditionCategory.PROBLEMLISTITEM.getSystem(), ConditionCategory.PROBLEMLISTITEM.toCode(), ConditionCategory.PROBLEMLISTITEM.getDisplay())));
    MethodOutcome outcome = client.create().resource(condition).execute();
    assertNotNull(outcome);
    assertTrue(outcome.getCreated());
    assertNotNull(outcome.getId());
    Condition readCondition = client.read().resource(Condition.class).withId(outcome.getId()).execute();
    assertNotNull(readCondition);
    assertEquals(outcome.getId().getIdPart(), readCondition.getIdElement().getIdPart());
    assertEquals(condition.getCategory().get(0).getCoding().get(0).getCode(), readCondition.getCategory().get(0).getCoding().get(0).getCode());
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Narrative(org.hl7.fhir.r4.model.Narrative) Coding(org.hl7.fhir.r4.model.Coding) Reference(org.hl7.fhir.r4.model.Reference) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 27 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project elexis-server by elexis.

the class EncounterTest method createEncounter.

@Test
public void createEncounter() {
    Condition problem = new Condition();
    problem.setCode(new CodeableConcept().addCoding(new Coding("http://hl7.org/fhir/sid/icpc-2", "A04", "Müdigkeit")));
    problem.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    problem.addCategory().addCoding(new Coding(ConditionCategory.PROBLEMLISTITEM.getSystem(), ConditionCategory.PROBLEMLISTITEM.toCode(), ConditionCategory.PROBLEMLISTITEM.getDisplay()));
    MethodOutcome problemOutcome = client.create().resource(problem).execute();
    Encounter encounter = new Encounter();
    EncounterParticipantComponent participant = new EncounterParticipantComponent();
    participant.setIndividual(new Reference("Practitioner/" + TestDatabaseInitializer.getMandant().getId()));
    encounter.addParticipant(participant);
    encounter.setPeriod(new Period().setStart(AllTests.getDate(LocalDate.now().atStartOfDay())).setEnd(AllTests.getDate(LocalDate.now().atTime(23, 59, 59))));
    encounter.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    encounter.addDiagnosis().setCondition(new Reference(new IdType(problem.getResourceType().name(), problemOutcome.getId().getIdPart())));
    encounter.addType(new CodeableConcept().addCoding(new Coding("www.elexis.info/encounter/type", "struct", "structured enconter")));
    MethodOutcome outcome = client.create().resource(encounter).execute();
    assertNotNull(outcome);
    assertTrue(outcome.getCreated());
    assertNotNull(outcome.getId());
    // add subjective to the encounter
    Observation subjective = new Observation();
    Narrative narrative = new Narrative();
    String divEncodedText = "Subjective\nTest".replaceAll("(\r\n|\r|\n)", "<br />");
    narrative.setDivAsString(divEncodedText);
    subjective.setText(narrative);
    subjective.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    subjective.addCategory().addCoding(new Coding(IdentifierSystem.ELEXIS_SOAP.getSystem(), ObservationCategory.SOAP_SUBJECTIVE.getCode(), ObservationCategory.SOAP_SUBJECTIVE.getLocalized()));
    subjective.setEncounter(new Reference(new IdType(encounter.getResourceType().name(), encounter.getId())));
    MethodOutcome subjectiveOutcome = client.create().resource(subjective).execute();
    assertTrue(subjectiveOutcome.getCreated());
    Encounter readEncounter = client.read().resource(Encounter.class).withId(outcome.getId()).execute();
    assertNotNull(readEncounter);
    assertEquals(outcome.getId().getIdPart(), readEncounter.getIdElement().getIdPart());
    assertEquals(encounter.getPeriod().getStart(), readEncounter.getPeriod().getStart());
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) Coding(org.hl7.fhir.r4.model.Coding) Narrative(org.hl7.fhir.r4.model.Narrative) Reference(org.hl7.fhir.r4.model.Reference) Observation(org.hl7.fhir.r4.model.Observation) Encounter(org.hl7.fhir.r4.model.Encounter) Period(org.hl7.fhir.r4.model.Period) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 28 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project elexis-server by elexis.

the class ServiceRequestTest method createServiceRequest.

@Test
public void createServiceRequest() {
    Condition problem = new Condition();
    problem.setCode(new CodeableConcept().addCoding(new Coding("http://hl7.org/fhir/sid/icpc-2", "A04", "Müdigkeit")));
    problem.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    problem.addCategory().addCoding(new Coding(ConditionCategory.PROBLEMLISTITEM.getSystem(), ConditionCategory.PROBLEMLISTITEM.toCode(), ConditionCategory.PROBLEMLISTITEM.getDisplay()));
    MethodOutcome problemOutcome = client.create().resource(problem).execute();
    Encounter encounter = new Encounter();
    EncounterParticipantComponent participant = new EncounterParticipantComponent();
    participant.setIndividual(new Reference("Practitioner/" + TestDatabaseInitializer.getMandant().getId()));
    encounter.addParticipant(participant);
    encounter.setPeriod(new Period().setStart(AllTests.getDate(LocalDate.of(2016, Month.DECEMBER, 1).atStartOfDay())).setEnd(AllTests.getDate(LocalDate.of(2016, Month.DECEMBER, 1).atTime(23, 59, 59))));
    encounter.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    encounter.addDiagnosis().setCondition(new Reference(new IdType(problem.getResourceType().name(), problemOutcome.getId().getIdPart())));
    encounter.addType(new CodeableConcept().addCoding(new Coding("www.elexis.info/encounter/type", "struct", "structured enconter")));
    MethodOutcome encounterOutcome = client.create().resource(encounter).execute();
    assertNotNull(encounterOutcome);
    assertTrue(encounterOutcome.getCreated());
    assertNotNull(encounterOutcome.getId());
    // add subjective to the encounter
    Observation subjective = new Observation();
    Narrative narrative = new Narrative();
    String divEncodedText = "Subjective\nTest".replaceAll("(\r\n|\r|\n)", "<br />");
    narrative.setDivAsString(divEncodedText);
    subjective.setText(narrative);
    subjective.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    subjective.addCategory().addCoding(new Coding(IdentifierSystem.ELEXIS_SOAP.getSystem(), ObservationCategory.SOAP_SUBJECTIVE.getCode(), ObservationCategory.SOAP_SUBJECTIVE.getLocalized()));
    subjective.setEncounter(new Reference(new IdType(encounter.getResourceType().name(), encounterOutcome.getId().getIdPart())));
    MethodOutcome subjectiveOutcome = client.create().resource(subjective).execute();
    assertTrue(subjectiveOutcome.getCreated());
    // add procedure request to encounter
    ServiceRequest serviceRequest = new ServiceRequest();
    narrative = new Narrative();
    divEncodedText = "Procedure\nTest".replaceAll("(\r\n|\r|\n)", "<br />");
    narrative.setDivAsString(divEncodedText);
    serviceRequest.setText(narrative);
    serviceRequest.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    serviceRequest.setEncounter(new Reference(new IdType(encounter.getResourceType().name(), encounterOutcome.getId().getIdPart())));
    MethodOutcome outcome = client.create().resource(serviceRequest).execute();
    assertNotNull(outcome);
    assertTrue(outcome.getCreated());
    assertNotNull(outcome.getId());
    ServiceRequest readServiceRequest = client.read().resource(ServiceRequest.class).withId(outcome.getId()).execute();
    assertNotNull(readServiceRequest);
    assertEquals(outcome.getId().getIdPart(), readServiceRequest.getIdElement().getIdPart());
    assertEquals(serviceRequest.getSubject().getReferenceElement().getIdPart(), readServiceRequest.getSubject().getReferenceElement().getIdPart());
    assertEquals(serviceRequest.getEncounter().getReferenceElement().getIdPart(), readServiceRequest.getEncounter().getReferenceElement().getIdPart());
    assertTrue(readServiceRequest.getText().getDivAsString().contains("Test"));
    // check if the consultation text has been updated
    // search by patient and date
    Bundle results = client.search().forResource(Encounter.class).where(Encounter.PATIENT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Encounter.DATE.exactly().day(AllTests.getDate(LocalDate.of(2016, Month.DECEMBER, 1).atStartOfDay()))).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    List<BundleEntryComponent> entries = results.getEntry();
    assertFalse(entries.isEmpty());
    Encounter readEncounter = (Encounter) entries.get(0).getResource();
    assertNotNull(readEncounter);
    assertEquals(readEncounter.getIdElement().getIdPart(), encounterOutcome.getId().getIdPart());
    List<Identifier> identifier = readEncounter.getIdentifier();
    String consultationId = null;
    for (Identifier id : identifier) {
        if (id.getSystem().equals(IdentifierSystem.ELEXIS_CONSID.getSystem())) {
            consultationId = id.getValue();
        }
    }
    assertNotNull(consultationId);
    Optional<IEncounter> behandlung = AllTests.getModelService().load(consultationId, IEncounter.class);
    assertTrue(behandlung.isPresent());
    assertTrue(behandlung.get().getVersionedEntry().getHead().contains("Procedure"));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) Bundle(org.hl7.fhir.r4.model.Bundle) Period(org.hl7.fhir.r4.model.Period) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) IdType(org.hl7.fhir.r4.model.IdType) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) IEncounter(ch.elexis.core.model.IEncounter) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) Narrative(org.hl7.fhir.r4.model.Narrative) Observation(org.hl7.fhir.r4.model.Observation) Encounter(org.hl7.fhir.r4.model.Encounter) IEncounter(ch.elexis.core.model.IEncounter) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 29 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project openmrs-module-fhir2 by openmrs.

the class PractitionerRoleNarrativeTest method shouldGeneratePractitionerRoleNarrative.

/**
 * Check that the expected narrative is generated for some example PractitionerRole resource
 *
 * @throws IOException
 */
@Test
public void shouldGeneratePractitionerRoleNarrative() throws IOException {
    PractitionerRole given = parser.parseResource(PractitionerRole.class, getClass().getClassLoader().getResourceAsStream(EXAMPLE_RESOURCE_PATH));
    PractitionerRole result = parser.parseResource(PractitionerRole.class, parser.encodeResourceToString(given));
    assertThat(result, notNullValue());
    assertThat(result.getText(), notNullValue());
    assertThat(result.getText().getStatusAsString(), equalTo("generated"));
    assertThat(result.getText().getDivAsString(), equalTo(readNarrativeFile(EXPECTED_NARRATIVE_PATH)));
}
Also used : PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) Test(org.junit.Test)

Example 30 with Narrative

use of org.hl7.fhir.r4b.model.Narrative in project openmrs-module-fhir2 by openmrs.

the class RelatedPersonNarrativeTest method shouldGenerateRelatedPersonNarrative.

/**
 * Check that the expected narrative is generated for some example RelatedPerson resource
 *
 * @throws IOException
 */
@Test
public void shouldGenerateRelatedPersonNarrative() throws IOException {
    RelatedPerson given = parser.parseResource(RelatedPerson.class, getClass().getClassLoader().getResourceAsStream(EXAMPLE_RESOURCE_PATH));
    RelatedPerson result = parser.parseResource(RelatedPerson.class, parser.encodeResourceToString(given));
    assertThat(result, notNullValue());
    assertThat(result.getText(), notNullValue());
    assertThat(result.getText().getStatusAsString(), equalTo("generated"));
    assertThat(result.getText().getDivAsString(), equalTo(readNarrativeFile(EXPECTED_NARRATIVE_PATH)));
}
Also used : RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) Test(org.junit.Test)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)80 FHIRException (org.hl7.fhir.exceptions.FHIRException)40 IOException (java.io.IOException)34 NotImplementedException (org.apache.commons.lang3.NotImplementedException)30 UnsupportedEncodingException (java.io.UnsupportedEncodingException)27 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)23 Test (org.junit.Test)22 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)19 ArrayList (java.util.ArrayList)19 XhtmlParser (org.hl7.fhir.utilities.xhtml.XhtmlParser)17 Narrative (org.hl7.fhir.r4.model.Narrative)15 Narrative (org.hl7.fhir.r5.model.Narrative)15 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)14 XhtmlComposer (org.hl7.fhir.utilities.xhtml.XhtmlComposer)14 GET (javax.ws.rs.GET)12 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 IBaseOperationOutcome (org.hl7.fhir.instance.model.api.IBaseOperationOutcome)12 FileNotFoundException (java.io.FileNotFoundException)10 LinkedHashMap (java.util.LinkedHashMap)10