Search in sources :

Example 31 with ListResource

use of org.hl7.fhir.dstu3.model.ListResource in project MobileAccessGateway by i4mi.

the class Iti65RequestConverter method processDocumentManifest.

/**
 * ITI-65: process ListResource resource from Bundle
 * @param manifest
 * @param submissionSet
 */
private void processDocumentManifest(ListResource manifest, SubmissionSet submissionSet) {
    for (Identifier id : manifest.getIdentifier()) {
        if (id.getUse() == null || id.getUse().equals(Identifier.IdentifierUse.OFFICIAL)) {
        } else if (id.getUse().equals(Identifier.IdentifierUse.USUAL)) {
            String uniqueId = noPrefix(id.getValue());
            submissionSet.setUniqueId(uniqueId);
        }
    }
    submissionSet.assignEntryUuid();
    manifest.setId(submissionSet.getEntryUuid());
    Extension designationType = manifest.getExtensionByUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-designationType");
    if (designationType != null && designationType.getValue() instanceof CodeableConcept) {
        submissionSet.setContentTypeCode(transformCodeableConcept((CodeableConcept) designationType.getValue()));
    }
    DateTimeType created = manifest.getDateElement();
    submissionSet.setSubmissionTime(timestampFromDate(created));
    // subject	SubmissionSet.patientId
    Reference ref = manifest.getSubject();
    submissionSet.setPatientId(transformReferenceToIdentifiable(ref, manifest));
    // Author
    Extension authorRoleExt = manifest.getExtensionByUrl("http://fhir.ch/ig/ch-epr-mhealth/StructureDefinition/ch-ext-author-authorrole");
    if (manifest.hasSource() || (authorRoleExt != null)) {
        Identifiable identifiable = null;
        Reference author = manifest.getSource();
        if (authorRoleExt != null) {
            Coding coding = authorRoleExt.castToCoding(authorRoleExt.getValue());
            if (coding != null) {
                identifiable = new Identifiable(coding.getCode(), new AssigningAuthority(noPrefix(coding.getSystem())));
            }
        }
        submissionSet.setAuthor(transformAuthor(author, manifest.getContained(), identifiable));
    }
    for (Extension recipientExt : manifest.getExtensionsByUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-intendedRecipient")) {
        Reference recipientRef = (Reference) recipientExt.getValue();
        Resource res = findResource(recipientRef, manifest.getContained());
        if (res instanceof Practitioner) {
            Recipient recipient = new Recipient();
            recipient.setPerson(transform((Practitioner) res));
            recipient.setTelecom(transform(((Practitioner) res).getTelecomFirstRep()));
            submissionSet.getIntendedRecipients().add(recipient);
        } else if (res instanceof Organization) {
            Recipient recipient = new Recipient();
            recipient.setOrganization(transform((Organization) res));
            recipient.setTelecom(transform(((Organization) res).getTelecomFirstRep()));
            submissionSet.getIntendedRecipients().add(recipient);
        } else if (res instanceof PractitionerRole) {
            Recipient recipient = new Recipient();
            PractitionerRole role = (PractitionerRole) res;
            recipient.setOrganization(transform((Organization) findResource(role.getOrganization(), manifest.getContained())));
            recipient.setPerson(transform((Practitioner) findResource(role.getPractitioner(), manifest.getContained())));
            recipient.setTelecom(transform(role.getTelecomFirstRep()));
            submissionSet.getIntendedRecipients().add(recipient);
        } else if (res instanceof Patient) {
            Recipient recipient = new Recipient();
            recipient.setPerson(transform((Patient) res));
            recipient.setTelecom(transform(((Patient) res).getTelecomFirstRep()));
        } else if (res instanceof RelatedPerson) {
            Recipient recipient = new Recipient();
            recipient.setPerson(transform((RelatedPerson) res));
            recipient.setTelecom(transform(((RelatedPerson) res).getTelecomFirstRep()));
        }
    }
    Extension source = manifest.getExtensionByUrl("http://profiles.ihe.net/ITI/MHD/StructureDefinition/ihe-sourceId");
    if (source != null && source.getValue() instanceof Identifier) {
        submissionSet.setSourceId(noPrefix(((Identifier) source.getValue()).getValue()));
    }
    String title = manifest.getTitle();
    if (title != null)
        submissionSet.setTitle(localizedString(title));
    Annotation note = manifest.getNoteFirstRep();
    if (note != null && note.hasText()) {
        submissionSet.setComments(localizedString(note.getText()));
    }
}
Also used : Organization(org.hl7.fhir.r4.model.Organization) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Resource(org.hl7.fhir.r4.model.Resource) ListResource(org.hl7.fhir.r4.model.ListResource) DomainResource(org.hl7.fhir.r4.model.DomainResource) Patient(org.hl7.fhir.r4.model.Patient) Recipient(org.openehealth.ipf.commons.ihe.xds.core.metadata.Recipient) LocalizedString(org.openehealth.ipf.commons.ihe.xds.core.metadata.LocalizedString) AssigningAuthority(org.openehealth.ipf.commons.ihe.xds.core.metadata.AssigningAuthority) CXiAssigningAuthority(org.openehealth.ipf.commons.ihe.xds.core.metadata.CXiAssigningAuthority) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) Annotation(org.hl7.fhir.r4.model.Annotation) Identifiable(org.openehealth.ipf.commons.ihe.xds.core.metadata.Identifiable) Extension(org.hl7.fhir.r4.model.Extension) Practitioner(org.hl7.fhir.r4.model.Practitioner) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 32 with ListResource

use of org.hl7.fhir.dstu3.model.ListResource in project gpconnect-demonstrator by nhsconnect.

the class StructuredAllergyIntoleranceBuilder method listResourceBuilder.

private void listResourceBuilder(ListResource buildingListResource, AllergyIntolerance allergyIntolerance, boolean isResolved) {
    ListEntryComponent comp = new ListEntryComponent();
    if (isResolved) {
        buildingListResource.addContained(allergyIntolerance);
        Reference allergyReference = new Reference("#" + allergyIntolerance.getId());
        comp.setItem(allergyReference);
    } else {
        Reference allergyReference = new Reference("AllergyIntolerance/" + allergyIntolerance.getId());
        comp.setItem(allergyReference);
    }
    buildingListResource.addEntry(comp);
}
Also used : ListEntryComponent(org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)

Example 33 with ListResource

use of org.hl7.fhir.dstu3.model.ListResource in project gpconnect-demonstrator by nhsconnect.

the class StructuredAllergyIntoleranceBuilder method buildStructuredAllergyIntolerence.

public Bundle buildStructuredAllergyIntolerence(String NHS, Set<String> practitionerIds, Bundle bundle, Boolean includedResolved) {
    List<StructuredAllergyIntoleranceEntity> allergyData = structuredAllergySearch.getAllergyIntollerence(NHS);
    ListResource activeList = initiateListResource(NHS, ACTIVE_ALLERGIES_DISPLAY, allergyData);
    ListResource resolvedList = initiateListResource(NHS, RESOLVED_ALLERGIES_DISPLAY, allergyData);
    // This is patient 5 example 2 only
    if (allergyData.size() == 1 && allergyData.get(0).getClinicalStatus().equals(SystemConstants.NO_KNOWN)) {
        StructuredAllergyIntoleranceEntity noKnownAllergy = allergyData.get(0);
        // #214 had incorrect code and value for no known allergies
        CodeableConcept noKnownAllergies = createCoding(SystemURL.VS_LIST_EMPTY_REASON_CODE, NO_CONTENT_RECORDED, NO_CONTENT_RECORDED_DISPLAY);
        noKnownAllergies.setText("No Known Allergies");
        // activeList.setEmptyReason(noKnownAllergies);
        // see spec example 2 no known allergies positively asserted
        Reference patient = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyData.get(0).getPatientRef());
        String noKnownAllergyId = noKnownAllergy.getGuid();
        Reference allergyIntolerance = new Reference("AllergyIntolerance/" + noKnownAllergyId);
        Resource noKnownAllergyResource = createNoKnownAllergy(noKnownAllergy);
        activeList.setSubject(patient);
        // reference to AllergyIntolerance item
        activeList.addEntry().setItem(allergyIntolerance);
        activeList.setOrderedBy(createCoding(SystemURL.CS_LIST_ORDER, "event-date", "Sorted by Event Date"));
        bundle.addEntry().setResource(activeList);
        bundle.addEntry().setResource(noKnownAllergyResource);
        if (includedResolved) {
            resolvedList.setSubject(patient);
            resolvedList.setEmptyReason(noKnownAllergies);
            bundle.addEntry().setResource(resolvedList);
        }
        return bundle;
    }
    for (StructuredAllergyIntoleranceEntity allergyIntoleranceEntity : allergyData) {
        AllergyIntolerance allergyIntolerance = new AllergyIntolerance();
        allergyIntolerance.setOnset(new DateTimeType(allergyIntoleranceEntity.getOnSetDateTime()));
        allergyIntolerance.setMeta(createMeta(SystemURL.SD_CC_ALLERGY_INTOLERANCE));
        allergyIntolerance.setId(allergyIntoleranceEntity.getId().toString());
        List<Identifier> identifiers = new ArrayList<>();
        Identifier identifier1 = new Identifier().setSystem("https://fhir.nhs.uk/Id/cross-care-setting-identifier").setValue(allergyIntoleranceEntity.getGuid());
        identifiers.add(identifier1);
        allergyIntolerance.setIdentifier(identifiers);
        if (allergyIntoleranceEntity.getClinicalStatus().equals(SystemConstants.ACTIVE)) {
            allergyIntolerance.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
        } else {
            allergyIntolerance.setClinicalStatus(AllergyIntoleranceClinicalStatus.RESOLVED);
        }
        if (allergyIntoleranceEntity.getCategory().equals(SystemConstants.MEDICATION)) {
            allergyIntolerance.addCategory(AllergyIntoleranceCategory.MEDICATION);
        } else {
            allergyIntolerance.addCategory(AllergyIntoleranceCategory.ENVIRONMENT);
        }
        allergyIntolerance.setVerificationStatus(AllergyIntoleranceVerificationStatus.UNCONFIRMED);
        // CODE
        codeableConceptBuilder.addConceptCode(SystemConstants.SNOMED_URL, allergyIntoleranceEntity.getConceptCode(), allergyIntoleranceEntity.getConceptDisplay()).addDescription(allergyIntoleranceEntity.getDescCode(), allergyIntoleranceEntity.getDescDisplay()).addTranslation(allergyIntoleranceEntity.getCodeTranslationRef());
        allergyIntolerance.setCode(codeableConceptBuilder.build());
        codeableConceptBuilder.clear();
        allergyIntolerance.setAssertedDate(allergyIntoleranceEntity.getAssertedDate());
        Reference patient = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyIntoleranceEntity.getPatientRef());
        allergyIntolerance.setPatient(patient);
        Annotation noteAnnotation = new Annotation(new StringType(allergyIntoleranceEntity.getNote()));
        allergyIntolerance.setNote(Collections.singletonList(noteAnnotation));
        AllergyIntoleranceReactionComponent reaction = new AllergyIntoleranceReactionComponent();
        // MANIFESTATION
        List<CodeableConcept> theManifestation = new ArrayList<>();
        codeableConceptBuilder.addConceptCode(SystemConstants.SNOMED_URL, allergyIntoleranceEntity.getManifestationCoding(), allergyIntoleranceEntity.getManifestationDisplay()).addDescription(allergyIntoleranceEntity.getManifestationDescCoding(), allergyIntoleranceEntity.getManifestationDescDisplay()).addTranslation(allergyIntoleranceEntity.getManTranslationRef());
        theManifestation.add(codeableConceptBuilder.build());
        codeableConceptBuilder.clear();
        reaction.setManifestation(theManifestation);
        reaction.setDescription(allergyIntoleranceEntity.getNote());
        // SEVERITY
        try {
            reaction.setSeverity(AllergyIntoleranceSeverity.fromCode(allergyIntoleranceEntity.getSeverity()));
        } catch (FHIRException e) {
            throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException("Unknown severity: " + allergyIntoleranceEntity.getSeverity()), SystemCode.INVALID_RESOURCE, IssueType.INVALID);
        }
        // EXPOSURE
        CodeableConcept exposureRoute = new CodeableConcept();
        reaction.setExposureRoute(exposureRoute);
        allergyIntolerance.addReaction(reaction);
        // RECORDER
        final Reference refValue = new Reference();
        final Identifier identifier = new Identifier();
        final String recorder = allergyIntoleranceEntity.getRecorder();
        // This is just an example to demonstrate using Reference element instead of Identifier element
        if (recorder.equals(patient2NhsNo.trim())) {
            Reference rec = new Reference(SystemConstants.PATIENT_REFERENCE_URL + allergyIntoleranceEntity.getPatientRef());
            allergyIntolerance.setRecorder(rec);
        } else if (patientRepository.findByNhsNumber(recorder) != null) {
            identifier.setSystem(SystemURL.ID_NHS_NUMBER);
            identifier.setValue(recorder);
            refValue.setIdentifier(identifier);
            allergyIntolerance.setRecorder(refValue);
        } else if (practitionerSearch.findPractitionerByUserId(recorder) != null) {
            refValue.setReference("Practitioner/" + recorder);
            allergyIntolerance.setRecorder(refValue);
            practitionerIds.add(recorder);
        }
        // CLINICAL STATUS
        List<Extension> extensions = new ArrayList<>();
        if (allergyIntolerance.getClinicalStatus().getDisplay().contains("Active")) {
            listResourceBuilder(activeList, allergyIntolerance, false);
            bundle.addEntry().setResource(allergyIntolerance);
        } else if (allergyIntolerance.getClinicalStatus().getDisplay().equals("Resolved") && includedResolved.equals(true)) {
            listResourceBuilder(resolvedList, allergyIntolerance, true);
            allergyIntolerance.setLastOccurrence(allergyIntoleranceEntity.getEndDate());
            final Extension allergyEndExtension = createAllergyEndExtension(allergyIntoleranceEntity);
            extensions.add(allergyEndExtension);
        }
        if (!extensions.isEmpty()) {
            allergyIntolerance.setExtension(extensions);
        }
        // ASSERTER
        Reference asserter = allergyIntolerance.getAsserter();
        if (asserter != null && asserter.getReference() != null && asserter.getReference().startsWith("Practitioner")) {
            String[] split = asserter.getReference().split("/");
            practitionerIds.add(split[1]);
        }
    }
    if (!activeList.hasEntry()) {
        addEmptyListNote(activeList);
        addEmptyReasonCode(activeList);
    }
    bundle.addEntry().setResource(activeList);
    if (includedResolved && !resolvedList.hasEntry()) {
        addEmptyListNote(resolvedList);
        addEmptyReasonCode(resolvedList);
    }
    if (includedResolved) {
        bundle.addEntry().setResource(resolvedList);
    }
    return bundle;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) StructuredAllergyIntoleranceEntity(uk.gov.hscic.patient.structuredAllergyIntolerance.StructuredAllergyIntoleranceEntity) FHIRException(org.hl7.fhir.exceptions.FHIRException) AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance)

Example 34 with ListResource

use of org.hl7.fhir.dstu3.model.ListResource in project gpconnect-demonstrator by nhsconnect.

the class PopulateMedicationBundle method createListEntry.

private ListResource createListEntry(List<MedicationStatementDetail> medicationStatements, String nhsNumber) {
    ListResource medicationStatementsList = new ListResource();
    // #179 dont populate List.id
    // medicationStatementsList.setId(new IdType(1));
    medicationStatementsList.setMeta(new Meta().addProfile(SystemURL.SD_GPC_LIST));
    medicationStatementsList.setStatus(ListStatus.CURRENT);
    // #179 dont populate List.id
    // medicationStatementsList.setId(new IdDt(1));
    medicationStatementsList.setMode(ListMode.SNAPSHOT);
    medicationStatementsList.setTitle(SystemConstants.MEDICATION_LIST);
    medicationStatementsList.setCode(new CodeableConcept().addCoding(new Coding(SystemURL.VS_SNOMED, "933361000000108", MEDICATION_LIST)));
    medicationStatementsList.setSubject(new Reference(new IdType("Patient", 1L)).setIdentifier(new Identifier().setValue(nhsNumber).setSystem(SystemURL.ID_NHS_NUMBER)));
    medicationStatementsList.setDate(new Date());
    medicationStatementsList.setOrderedBy(new CodeableConcept().addCoding(new Coding(SystemURL.CS_LIST_ORDER, "event-date", "Sorted by Event Date")));
    medicationStatementsList.addExtension(setClinicalSetting());
    if (medicationStatements.isEmpty()) {
        medicationStatementsList.setEmptyReason(new CodeableConcept().setText(SystemConstants.NO_CONTENT));
        medicationStatementsList.setNote(Arrays.asList(new Annotation(new StringType(SystemConstants.INFORMATION_NOT_AVAILABLE))));
    }
    Set<String> warningCodes = new HashSet<>();
    medicationStatements.forEach(statement -> {
        Reference statementRef = new Reference(new IdType("MedicationStatement", statement.getId()));
        ListEntryComponent listEntryComponent = new ListEntryComponent(statementRef);
        medicationStatementsList.addEntry(listEntryComponent);
        if (statement.getWarningCode() != null) {
            warningCodes.add(statement.getWarningCode());
        }
    });
    WarningCodeExtHelper.addWarningCodeExtensions(warningCodes, medicationStatementsList, patientRepository, medicationStatementRepository, structuredAllergySearch);
    return medicationStatementsList;
}
Also used : IIdType(org.hl7.fhir.instance.model.api.IIdType) ListEntryComponent(org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)

Example 35 with ListResource

use of org.hl7.fhir.dstu3.model.ListResource in project cqf-ruler by DBCG.

the class CollectDataProvider method readEvaluatedResources.

private List<Resource> readEvaluatedResources(MeasureReport report) {
    List<Resource> resources = new ArrayList<>();
    if (report.getEvaluatedResources() == null) {
        return resources;
    }
    Reference listReference = report.getEvaluatedResources();
    // Removes the contained "#" prefix
    String listId = listReference.getReference().substring(1);
    Optional<Resource> list = report.getContained().stream().filter(x -> x.getId().equals(listId)).findFirst();
    if (!list.isPresent()) {
        return resources;
    }
    ListResource containedList = (ListResource) list.get();
    for (ListEntryComponent entry : containedList.getEntry()) {
        if (!entry.hasItem()) {
            continue;
        }
        Reference reference = entry.getItem();
        resources.add(this.read(reference.getReferenceElement()));
    }
    return resources;
}
Also used : MeasureReportType(org.hl7.fhir.dstu3.model.MeasureReport.MeasureReportType) IdParam(ca.uhn.fhir.rest.annotation.IdParam) OperationParam(ca.uhn.fhir.rest.annotation.OperationParam) DaoRegistryOperationProvider(org.opencds.cqf.ruler.provider.DaoRegistryOperationProvider) Reference(org.hl7.fhir.dstu3.model.Reference) Parameters.newPart(org.opencds.cqf.ruler.utility.dstu3.Parameters.newPart) Resource(org.hl7.fhir.dstu3.model.Resource) IdType(org.hl7.fhir.dstu3.model.IdType) Description(ca.uhn.fhir.model.api.annotation.Description) Parameters.newParameters(org.opencds.cqf.ruler.utility.dstu3.Parameters.newParameters) Autowired(org.springframework.beans.factory.annotation.Autowired) ListResource(org.hl7.fhir.dstu3.model.ListResource) Operation(ca.uhn.fhir.rest.annotation.Operation) Measure(org.hl7.fhir.dstu3.model.Measure) ArrayList(java.util.ArrayList) List(java.util.List) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Parameters(org.hl7.fhir.dstu3.model.Parameters) Optional(java.util.Optional) MeasureReport(org.hl7.fhir.dstu3.model.MeasureReport) ListEntryComponent(org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent) Reference(org.hl7.fhir.dstu3.model.Reference) Resource(org.hl7.fhir.dstu3.model.Resource) ListResource(org.hl7.fhir.dstu3.model.ListResource) ArrayList(java.util.ArrayList) ListEntryComponent(org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent) ListResource(org.hl7.fhir.dstu3.model.ListResource)

Aggregations

ListResource (org.hl7.fhir.r5.model.ListResource)12 Element (org.w3c.dom.Element)12 ListResourceEntryComponent (org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent)11 ListResource (org.hl7.fhir.dstu3.model.ListResource)10 Reference (org.hl7.fhir.dstu3.model.Reference)10 ListEntryComponent (org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)9 ArrayList (java.util.ArrayList)8 ListResource (org.hl7.fhir.r4.model.ListResource)8 Reference (org.hl7.fhir.r4.model.Reference)6 HashMap (java.util.HashMap)5 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)5 SectionComponent (org.hl7.fhir.dstu3.model.Composition.SectionComponent)4 Patient (org.hl7.fhir.r4.model.Patient)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 List (java.util.List)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)2