Search in sources :

Example 26 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project summary-care-record-api by NHSDigital.

the class GetScrService method getScrId.

@LogExecutionTime
public Bundle getScrId(String nhsNumber, String nhsdAsid, String clientIp) {
    Document scrIdXml = getScrIdRawXml(nhsNumber, nhsdAsid, clientIp);
    checkDetectedIssues(scrIdXml);
    EventListQueryResponse response = eventListQueryResponseParser.parseXml(scrIdXml);
    Bundle bundle = buildBundle();
    if (StringUtils.isNotEmpty(response.getLatestScrId())) {
        bundle.setTotal(1);
        Patient patient = buildPatientResource(nhsNumber);
        DocumentReference documentReference = buildDocumentReference(nhsNumber, response, patient);
        bundle.addEntry(new BundleEntryComponent().setFullUrl(getScrUrl() + "/DocumentReference/" + documentReference.getId()).setResource(documentReference).setSearch(new Bundle.BundleEntrySearchComponent().setMode(MATCH)));
        bundle.addEntry(new BundleEntryComponent().setFullUrl(patient.getId()).setResource(patient));
    } else {
        bundle.setTotal(0);
    }
    return bundle;
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) EventListQueryResponse(uk.nhs.adaptors.scr.models.EventListQueryResponse) Patient(org.hl7.fhir.r4.model.Patient) Document(org.w3c.dom.Document) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) LogExecutionTime(uk.nhs.adaptors.scr.logging.LogExecutionTime)

Example 27 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project Gravity-SDOH-Exchange-RI by FHIR.

the class PersonalCharacteristicsService method retrieveDerivedFrom.

public AttachmentDto retrieveDerivedFrom(String id) {
    Observation obs = observationRepository.getWithDocumentReference(id);
    if (obs == null) {
        throw new ResourceNotFoundException(new IdType(Observation.class.getSimpleName(), id));
    }
    IBaseResource ref = obs.getDerivedFromFirstRep().getResource();
    if (ref == null || !(ref instanceof DocumentReference)) {
        throw new IllegalStateException("Observation with id " + id + " does not have a derived-from field set to a Document Reference resource.");
    }
    DocumentReference docRef = (DocumentReference) ref;
    Attachment attachment = docRef.getContentFirstRep().getAttachment();
    if (attachment == null) {
        throw new IllegalStateException("DocumentReference with id " + docRef.getIdElement().getIdPart() + " does not have an attachment.");
    }
    return AttachmentDto.builder().content(attachment.getData()).contentType(attachment.getContentType()).title(attachment.getTitle()).build();
}
Also used : Observation(org.hl7.fhir.r4.model.Observation) Attachment(org.hl7.fhir.r4.model.Attachment) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) IdType(org.hl7.fhir.r4.model.IdType)

Example 28 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project integration-adaptor-111 by nhsconnect.

the class EncounterReportBundleServiceTest method shouldMapIncomingReferralWithPractitioners.

@Test
@SuppressWarnings("MagicNumber")
public void shouldMapIncomingReferralWithPractitioners() throws XmlException {
    ItkReportHeader itkReportHeader = new ItkReportHeader();
    List<Reference> recipients = new ArrayList<>();
    when(reference.getResource()).thenReturn(PRACTITIONER);
    recipients.add(reference);
    REFERRAL_REQUEST.setRecipient(recipients);
    Bundle encounterBundle = encounterReportBundleService.createEncounterBundle(document, itkReportHeader, MESSAGEID);
    List<BundleEntryComponent> entries = encounterBundle.getEntry();
    verifyEntry(entries.get(7), REFERRAL_REQUEST_ID.getValue(), ResourceType.ReferralRequest);
    verifyEntry(entries.get(8), PRACTITIONER_ID.getValue(), ResourceType.Practitioner);
}
Also used : BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Reference(org.hl7.fhir.dstu3.model.Reference) Bundle(org.hl7.fhir.dstu3.model.Bundle) ItkReportHeader(uk.nhs.adaptors.oneoneone.cda.report.controller.utils.ItkReportHeader) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 29 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project org.hl7.fhir.core by hapifhir.

the class CountryCodesConverter method execute.

private void execute() throws ParserConfigurationException, SAXException, IOException {
    Document src = load();
    CodeSystem cs1 = new CodeSystem();
    CodeSystem cs2 = new CodeSystem();
    CodeSystem cs3 = new CodeSystem();
    setMetadata(src, cs1, "iso3166", "urn:iso:std:iso:3166", "", "");
    setMetadata(src, cs2, "iso3166-2", "urn:iso:std:iso:3166:-2", "Part2", " Part 2");
    cs1.addProperty().setCode("canonical").setDescription("The 2 letter code that identifies the same country (so 2/3/numeric codes can be aligned)").setType(PropertyType.CODE);
    cs2.addProperty().setCode("country").setDescription("The 2 letter code that identifies the country for the subdivision").setType(PropertyType.CODE);
    for (Element e : XMLUtil.getNamedChildren(src.getDocumentElement(), "country")) {
        System.out.println(e.getAttribute("id"));
        String c2 = XMLUtil.getNamedChildText(e, "alpha-2-code");
        String c3 = XMLUtil.getNamedChildText(e, "alpha-3-code");
        String cN = XMLUtil.getNamedChildText(e, "numeric-code");
        Element n = XMLUtil.getNamedChildByAttribute(e, "short-name", "lang3code", "eng");
        if (n == null)
            n = XMLUtil.getNamedChildByAttribute(e, "short-name-upper-case", "lang3code", "eng");
        if (n == null)
            continue;
        String name = n.getTextContent();
        n = XMLUtil.getNamedChildByAttribute(e, "full-name", "lang3code", "eng");
        if (n == null)
            n = XMLUtil.getNamedChildByAttribute(e, "full-name-upper-case", "lang3code", "eng");
        if (n == null)
            n = XMLUtil.getNamedChildByAttribute(e, "short-name", "lang3code", "eng");
        if (n == null)
            n = XMLUtil.getNamedChildByAttribute(e, "short-name-upper-case", "lang3code", "eng");
        String desc = n.getTextContent();
        ConceptDefinitionComponent cc = cs1.addConcept();
        cc.setCode(c2);
        cc.setDisplay(name);
        cc.setDefinition(desc);
        poplang(e, cc);
        if (c3 != null) {
            cc = cs1.addConcept();
            cc.setCode(c3);
            cc.setDisplay(name);
            cc.setDefinition(desc);
            cc.addProperty().setCode("canonical").setValue(new CodeType(c2));
            poplang(e, cc);
        }
        if (cN != null) {
            cc = cs1.addConcept();
            cc.setCode(cN);
            cc.setDisplay(name);
            cc.setDefinition(desc);
            cc.addProperty().setCode("canonical").setValue(new CodeType(c2));
            poplang(e, cc);
        }
        for (Element sd : XMLUtil.getNamedChildren(e, "subdivision")) {
            cc = cs2.addConcept();
            cc.setCode(XMLUtil.getNamedChildText(sd, "subdivision-code"));
            Element l = XMLUtil.getNamedChild(sd, "subdivision-locale");
            cc.setDisplay(XMLUtil.getNamedChildText(l, "subdivision-locale-name"));
            cc.addProperty().setCode("country").setValue(new CodeType(c2));
        }
    }
    cs1.setCount(cs1.getConcept().size());
    cs2.setCount(cs2.getConcept().size());
    throw new Error("Needs revisiting");
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "4.0.1", "package", "CodeSstem-iso3166.json")), cs1);
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "3.0.2", "package", "CodeSstem-iso3166.json")), cs1); // format hasn't changed
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "4.0.1", "package", "CodeSstem-iso3166-2.json")), cs2);
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "3.0.2", "package", "CodeSstem-iso3166-2.json")), cs2); // format hasn't changed
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) Element(org.w3c.dom.Element) CodeType(org.hl7.fhir.r4.model.CodeType) Document(org.w3c.dom.Document) CodeSystem(org.hl7.fhir.r4.model.CodeSystem)

Example 30 with DOCUMENT

use of org.hl7.fhir.r4.model.Bundle.BundleType.DOCUMENT in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generateDocumentNarrative.

public XhtmlNode generateDocumentNarrative(Bundle feed) {
    /*
     When the document is presented for human consumption, applications must present the collated narrative portions of the following resources in order:
     * The Composition resource
     * The Subject resource
     * Resources referenced in the section.content
     */
    XhtmlNode root = new XhtmlNode(NodeType.Element, "div");
    Composition comp = (Composition) feed.getEntry().get(0).getResource();
    root.getChildNodes().add(comp.getText().getDiv());
    Resource subject = ResourceUtilities.getById(feed, null, comp.getSubject().getReference());
    if (subject != null && subject instanceof DomainResource) {
        root.addTag("hr");
        root.getChildNodes().add(((DomainResource) subject).getText().getDiv());
    }
    List<SectionComponent> sections = comp.getSection();
    renderSections(feed, root, sections, 1);
    return root;
}
Also used : Composition(org.hl7.fhir.dstu2.model.Composition) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) Resource(org.hl7.fhir.dstu2.model.Resource) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) SectionComponent(org.hl7.fhir.dstu2.model.Composition.SectionComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

Document (org.w3c.dom.Document)48 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)37 DocumentBuilder (javax.xml.parsers.DocumentBuilder)36 IOException (java.io.IOException)33 FHIRException (org.hl7.fhir.exceptions.FHIRException)33 ArrayList (java.util.ArrayList)28 Element (org.w3c.dom.Element)20 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)16 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)15 HashMap (java.util.HashMap)14 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)13 FileNotFoundException (java.io.FileNotFoundException)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 List (java.util.List)11 CSFile (org.hl7.fhir.utilities.CSFile)11 File (java.io.File)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 XmlGenerator (org.hl7.fhir.utilities.xml.XmlGenerator)9 Identifier (org.hl7.fhir.r4.model.Identifier)8 TextFile (org.hl7.fhir.utilities.TextFile)8