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()));
}
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;
}
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);
}
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);
}
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());
}
Aggregations