use of org.hl7.fhir.r5.model.Questionnaire in project Gravity-SDOH-Exchange-RI by FHIR.
the class ConvertService method convert.
public Map<String, Object> convert(JSONObject questionnaireResponse) throws IOException {
QuestionnaireResponse qs = (QuestionnaireResponse) fhirContext.newJsonParser().parseResource(questionnaireResponse.toString());
if (qs.getQuestionnaire() == null) {
throw new IllegalStateException(String.format("QuestionnaireResponse '%s' does not contain a link to a Questionnaire.", qs.getIdElement().getIdPart()));
}
Optional<Questionnaire> foundQuestionnaire = questionnaireRepository.findByCanonnicalUri(qs.getQuestionnaire());
if (!foundQuestionnaire.isPresent()) {
throw new ResourceNotFoundException(String.format("Questionnaire was not found by URL '%s'.", qs.getQuestionnaire()));
}
Questionnaire questionnaire = foundQuestionnaire.get();
String mapUri = ((CanonicalType) questionnaire.getExtensionByUrl(MAP_EXTENSION).getValue()).getValueAsString();
boolean mapExists = validationEngine.getContext().listTransforms().stream().anyMatch(map -> map.getUrl().equals(mapUri));
if (!mapExists) {
loadMapIg(mapUri);
}
return new ObjectMapper().readValue(convertToBundle(questionnaireResponse, mapUri), Map.class);
}
use of org.hl7.fhir.r5.model.Questionnaire in project integration-adaptor-111 by nhsconnect.
the class QuestionnaireMapperTest method shouldMapQuestionnairePublisherName.
@Test
public void shouldMapQuestionnairePublisherName() {
var userName = "John";
when(pathwaysCase.getPathwayDetails().getPathwayTriageDetails().getPathwayTriageArray(0).getUser().getName()).thenReturn(userName);
Questionnaire questionnaire = questionnaireMapper.mapQuestionnaire(pathwaysCase, triageLine);
assertThat(questionnaire.getPublisher()).isEqualTo(String.format("User name: '%s' ", userName));
}
use of org.hl7.fhir.r5.model.Questionnaire in project integration-adaptor-111 by nhsconnect.
the class QuestionnaireMapperTest method shouldMapQuestionnairePublisherId.
@Test
public void shouldMapQuestionnairePublisherId() {
var userId = "123456";
when(pathwaysCase.getPathwayDetails().getPathwayTriageDetails().getPathwayTriageArray(0).getUser().getId()).thenReturn(userId);
Questionnaire questionnaire = questionnaireMapper.mapQuestionnaire(pathwaysCase, triageLine);
assertThat(questionnaire.getPublisher()).isEqualTo(String.format("User ID: '%s' ", userId));
}
use of org.hl7.fhir.r5.model.Questionnaire in project integration-adaptor-111 by nhsconnect.
the class QuestionnaireResponseMapper method mapQuestionnaireResponse.
public QuestionnaireResponse mapQuestionnaireResponse(PathwaysCase pathwaysCase, Reference patient, Reference encounter, TriageLine triageLine) {
QuestionnaireResponse questionnaireResponse = new QuestionnaireResponse();
Questionnaire questionnaire = questionnaireMapper.mapQuestionnaire(pathwaysCase, triageLine);
questionnaireResponse.setIdElement(resourceUtil.newRandomUuid());
questionnaireResponse.setQuestionnaire(resourceUtil.createReference(questionnaire)).setQuestionnaireTarget(questionnaire).setStatus(QuestionnaireResponse.QuestionnaireResponseStatus.COMPLETED).setSubject(patient).setContext(encounter);
if (pathwaysCase.getCaseDetails() != null) {
if (pathwaysCase.getCaseDetails().isSetCaseId()) {
questionnaireResponse.setIdentifier(new Identifier().setValue(pathwaysCase.getCaseDetails().getCaseId()));
}
}
if (pathwaysCase.isSetCaseReceiveEnd()) {
questionnaireResponse.setAuthored(DateUtil.parsePathwaysDate(pathwaysCase.getCaseReceiveEnd().toString()));
}
if (triageLine.getQuestion() != null) {
questionnaireResponse.addItem(getItem(triageLine.getQuestion()));
}
return questionnaireResponse;
}
use of org.hl7.fhir.r5.model.Questionnaire in project integration-adaptor-111 by nhsconnect.
the class QuestionnaireMapper method mapQuestionnaire.
public Questionnaire mapQuestionnaire(PathwaysCase pathwaysCase, TriageLine triageLine) {
Questionnaire questionnaire = new Questionnaire();
String publisher = getPublisher(pathwaysCase.getPathwayDetails().getPathwayTriageDetails().getPathwayTriageArray(0).getUser());
Date latestDate = getLatestDate(pathwaysCase);
questionnaire.setIdElement(resourceUtil.newRandomUuid());
questionnaire.addIdentifier(new Identifier().setValue(getCaseID(pathwaysCase))).setVersion(toIsoDateTimeString(latestDate)).setStatus(Enumerations.PublicationStatus.ACTIVE).setExperimental(false).addSubjectType("Patient").setDate(latestDate).setPublisher(publisher).setLastReviewDate(latestDate).setJurisdiction(Collections.singletonList(new CodeableConcept().setText(getCountry(pathwaysCase)))).addItem(getItem(triageLine.getQuestion(), getCaseID(pathwaysCase)));
setContact(pathwaysCase, questionnaire);
return questionnaire;
}
Aggregations