Search in sources :

Example 96 with IParser

use of org.hl7.fhir.dstu2.formats.IParser in project openmrs-module-fhir2 by openmrs.

the class FhirImmunizationServiceImplTest method saveImmunization_shouldCreateEncounterAndObsGroupWhenNewImmunization.

@Test
public void saveImmunization_shouldCreateEncounterAndObsGroupWhenNewImmunization() {
    // setup
    FhirContext ctx = FhirContext.forR4();
    IParser parser = ctx.newJsonParser();
    Immunization newImmunization = parser.parseResource(Immunization.class, "{\n" + "  \"resourceType\": \"Immunization\",\n" + "  \"status\": \"completed\",\n" + "  \"vaccineCode\": {\n" + "    \"coding\": [\n" + "      {\n" + "        \"code\": \"15f83cd6-64e9-4e06-a5f9-364d3b14a43d\",\n" + "        \"display\": \"Aspirin as a vaccine\"\n" + "      }\n" + "    ]\n" + "  },\n" + "  \"patient\": {\n" + "    \"reference\": \"Patient/a7e04421-525f-442f-8138-05b619d16def\",\n" + "    \"type\": \"Patient\"\n" + "  },\n" + "  \"encounter\": {\n" + "    \"reference\": \"Encounter/7d8c1980-6b78-11e0-93c3-18a905e044dc\",\n" + "    \"type\": \"Encounter\"\n" + "  },\n" + "  \"occurrenceDateTime\": \"2020-07-08T18:30:00.000Z\",\n" + "  \"manufacturer\": {\n" + "    \"display\": \"Acme\"\n" + "  },\n" + "  \"lotNumber\": \"FOO1234\",\n" + "  \"expirationDate\": \"2022-07-31T18:30:00.000Z\",\n" + "  \"performer\": [\n" + "    {\n" + "      \"actor\": {\n" + "        \"reference\": \"Practitioner/f9badd80-ab76-11e2-9e96-0800200c9a66\",\n" + "        \"type\": \"Practitioner\"\n" + "      }\n" + "    }\n" + "  ],\n" + "  \"protocolApplied\": [\n" + "    {\n" + "      \"doseNumberPositiveInt\": 2,\n" + "      \"series\": \"Dose 2\"\n" + "    }\n" + "  ]\n" + "}");
    // replay
    Immunization savedImmunization = service.create(newImmunization);
    Obs obs = obsService.getObsByUuid(savedImmunization.getId());
    // verify
    helper.validateImmunizationObsGroup(obs);
    assertObsCommons(obs, "a7e04421-525f-442f-8138-05b619d16def", "7d8c1980-6b78-11e0-93c3-18a905e044dc", "f9badd80-ab76-11e2-9e96-0800200c9a66");
    obs.getGroupMembers().forEach(o -> assertObsCommons(o, "a7e04421-525f-442f-8138-05b619d16def", "7d8c1980-6b78-11e0-93c3-18a905e044dc", "f9badd80-ab76-11e2-9e96-0800200c9a66"));
    Map<String, Obs> members = helper.getObsMembersMap(obs);
    assertThat(members.get(CIEL_984).getValueCoded().getUuid(), is("15f83cd6-64e9-4e06-a5f9-364d3b14a43d"));
    assertThat(members.get(CIEL_1410).getValueDatetime(), equalTo(new DateTimeType("2020-07-08T18:30:00.000Z").getValue()));
    assertThat(members.get(CIEL_1418).getValueNumeric(), equalTo(2.0));
    assertThat(members.get(CIEL_1419).getValueText(), is("Acme"));
    assertThat(members.get(CIEL_1420).getValueText(), is("FOO1234"));
    assertThat(members.get(CIEL_165907).getValueDatetime(), equalTo(new DateTimeType("2022-07-31T18:30:00.000Z").getValue()));
}
Also used : Obs(org.openmrs.Obs) FhirContext(ca.uhn.fhir.context.FhirContext) Immunization(org.hl7.fhir.r4.model.Immunization) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) IParser(ca.uhn.fhir.parser.IParser) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 97 with IParser

use of org.hl7.fhir.dstu2.formats.IParser in project ab2d by CMSgov.

the class EobTestDataUtil method createEOB.

public static IBaseResource createEOB() {
    IBaseResource eob;
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    Resource resource = resourceLoader.getResource("classpath:" + File.separator + "test-data" + File.separator + "EOB-for-Carrier-Claims.json");
    InputStream inputStream = getEOBInputStream(resource);
    final EncodingEnum respType = EncodingEnum.forContentType(EncodingEnum.JSON_PLAIN_STRING);
    final IParser parser = respType.newParser(FhirContext.forDstu3());
    final org.hl7.fhir.dstu3.model.ExplanationOfBenefit explanationOfBenefit = parser.parseResource(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.class, inputStream);
    eob = ExplanationOfBenefitTrimmerSTU3.getBenefit(explanationOfBenefit);
    org.hl7.fhir.dstu3.model.Period billingPeriod = new org.hl7.fhir.dstu3.model.Period();
    try {
        billingPeriod.setStart(sdf.parse("01/02/2020"));
        final LocalDate now = LocalDate.now();
        final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
        final String nowFormatted = now.format(formatter);
        billingPeriod.setEnd(sdf.parse(nowFormatted));
    } catch (Exception ignored) {
    }
    // noinspection ConstantConditions
    ((org.hl7.fhir.dstu3.model.ExplanationOfBenefit) eob).setBillablePeriod(billingPeriod);
    return eob;
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) InputStream(java.io.InputStream) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.springframework.core.io.Resource) EncodingEnum(ca.uhn.fhir.rest.api.EncodingEnum) LocalDate(java.time.LocalDate) IOException(java.io.IOException) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SimpleDateFormat(java.text.SimpleDateFormat) DateTimeFormatter(java.time.format.DateTimeFormatter) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) IParser(ca.uhn.fhir.parser.IParser)

Example 98 with IParser

use of org.hl7.fhir.dstu2.formats.IParser in project ab2d by CMSgov.

the class CapabilityAPIV1 method capabilityStatement.

@Operation(summary = CAP_REQ)
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = CAP_DESC + " https://www.hl7.org/fhir/STU3/capabilitystatement.html", headers = { @Header(name = CONTENT_TYPE, description = APPLICATION_JSON) }) })
@ResponseStatus(value = HttpStatus.OK)
@GetMapping(value = "/metadata")
public ResponseEntity<String> capabilityStatement(HttpServletRequest request) {
    IParser parser = STU3.getJsonParser();
    eventLogger.log(new ApiResponseEvent(MDC.get(ORGANIZATION), null, HttpStatus.OK, CAP_STMT, CAP_RET, (String) request.getAttribute(REQUEST_ID)));
    String server = common.getCurrentUrl(request).replace("/metadata", "");
    CapabilityStatement capabilityStatement = CapabilityStatementSTU3.populateCS(server);
    return new ResponseEntity<>(parser.encodeResourceToString(capabilityStatement), null, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) CapabilityStatement(org.hl7.fhir.dstu3.model.CapabilityStatement) ApiResponseEvent(gov.cms.ab2d.eventlogger.events.ApiResponseEvent) IParser(ca.uhn.fhir.parser.IParser) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 99 with IParser

use of org.hl7.fhir.dstu2.formats.IParser in project integration-adaptor-111 by nhsconnect.

the class EncounterReportServiceTest method shouldTransformAndPopulateToGP.

@Test
public void shouldTransformAndPopulateToGP() throws JMSException, XmlException {
    ItkReportHeader header = new ItkReportHeader();
    header.setTrackingId(TRACKING_ID);
    header.setSpecKey(SPECIFICATION_KEY);
    header.setSpecVal(SPECIFICATION_VALUE);
    POCDMT000002UK01ClinicalDocument1 clinicalDoc = mock(POCDMT000002UK01ClinicalDocument1.class);
    Bundle encounterBundle = mock(Bundle.class);
    when(encounterReportBundleService.createEncounterBundle(clinicalDoc, header, MESSAGE_ID)).thenReturn(encounterBundle);
    IParser parser = mock(IParser.class);
    when(fhirContext.newJsonParser()).thenReturn(parser);
    when(parser.setPrettyPrint(true)).thenReturn(parser);
    when(parser.encodeResourceToString(encounterBundle)).thenReturn(ENCOUNTER_REPORT_MAPPING);
    Session session = mock(Session.class);
    when(session.createTextMessage(any())).thenReturn(textMessage);
    encounterReportService.transformAndPopulateToGP(clinicalDoc, MESSAGE_ID, header);
    ArgumentCaptor<MessageCreator> argumentCaptor = ArgumentCaptor.forClass(MessageCreator.class);
    verify(jmsTemplate).send(eq(QUEUE_NAME), argumentCaptor.capture());
    argumentCaptor.getValue().createMessage(session);
    verify(session).createTextMessage(ENCOUNTER_REPORT_MAPPING);
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) ItkReportHeader(uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader) POCDMT000002UK01ClinicalDocument1(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01ClinicalDocument1) MessageCreator(org.springframework.jms.core.MessageCreator) IParser(ca.uhn.fhir.parser.IParser) Session(javax.jms.Session) Test(org.junit.jupiter.api.Test)

Example 100 with IParser

use of org.hl7.fhir.dstu2.formats.IParser in project fhir-bridge by ehrbase.

the class AbstractBundleMappingTestSetupIT method create.

@Override
protected void create(String path) throws IOException {
    String resource = testFileLoader.loadResourceToString(path);
    String outcome = client.transaction().withBundle(resource.replaceAll(PATIENT_ID_TOKEN, PATIENT_ID)).execute();
    IParser parser = context.newJsonParser();
    Bundle bundle = parser.parseResource(Bundle.class, outcome);
    assertNotNull(bundle.getId());
}
Also used : Bundle(org.hl7.fhir.r4.model.Bundle) IParser(ca.uhn.fhir.parser.IParser)

Aggregations

IParser (ca.uhn.fhir.parser.IParser)89 FhirContext (ca.uhn.fhir.context.FhirContext)43 IOException (java.io.IOException)35 ByteArrayOutputStream (java.io.ByteArrayOutputStream)30 Test (org.junit.Test)24 InputStream (java.io.InputStream)22 IParser (org.hl7.fhir.r5.formats.IParser)19 JsonParser (org.hl7.fhir.r5.formats.JsonParser)18 Test (org.junit.jupiter.api.Test)18 FHIRException (org.hl7.fhir.exceptions.FHIRException)17 ByteArrayInputStream (java.io.ByteArrayInputStream)16 File (java.io.File)16 FileInputStream (java.io.FileInputStream)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 Bundle (org.hl7.fhir.r4.model.Bundle)14 FileOutputStream (java.io.FileOutputStream)12 Bundle (org.hl7.fhir.dstu3.model.Bundle)12 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)12 XmlParser (org.hl7.fhir.r5.formats.XmlParser)12 ArrayList (java.util.ArrayList)11