Search in sources :

Example 81 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson 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 82 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7DFTMessageTest method testResourceCreationFromDFT.

@Test
void testResourceCreationFromDFT() throws IOException {
    // Tests structure of DFT_P03 message type and DFT messages in general
    // DFT_P03 message types and IN1 are tested in detail in Hl7FinancialInsuranceTest
    String hl7message = "MSH|^~\\&|||||20151008111200||DFT^P03^DFT_P03|MSGID000001|T|2.6|||||||||\n" + "EVN||20210407191342||||||\n" + "PID|||MR1^^^XYZ^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\n" + // Minimal ORC for ServiceRequest
    "ORC|NW|||||||||||||||\n" + // Minimal OBR for ServiceRequest
    "OBR|1||||||||||||||||||||||||||||||||\n" + "NTE|1|O|TEST ORC/OBR NOTE AA|||\n" + // OBX is type ST so an observation will be created
    "OBX|1|ST|100||This is content|||||||X\n" + "NTE|1|L|TEST OBXa NOTE|\n" + // FT1.7 is required transaction code (currently not used)
    "FT1||||20201231145045||CG|FAKE|||||||||||||||||||||||||||||||||||||\n" + // IN1.2.4, IN1.2.6 to Identifier 2
    "IN1|1|Value1^^System3^Value4^^System6" + // IN1.5 to 15 NOT REFERENCED (See test testBasicInsuranceCoverageFields)
    "|IdValue1^^^IdSystem4^^^^|Large Blue Organization|||||||||||" + // IN1.18 through IN1.35 NOT REFERENCED
    "|DoeFake^Judy^^^Rev.|PAR||||||||||||||||||" + // IN1.50 through IN1.53 NOT REFERENCED
    "|MEMBER36||||||||||Value46|||J494949||||\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> encounters = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    // From PV1
    assertThat(encounters).hasSize(1);
    List<Resource> patients = ResourceUtils.getResourceList(e, ResourceType.Patient);
    // From PID
    assertThat(patients).hasSize(1);
    List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
    // From Payor created by IN1
    assertThat(organizations).hasSize(1);
    List<Resource> coverages = ResourceUtils.getResourceList(e, ResourceType.Coverage);
    // From IN1 segment
    assertThat(coverages).hasSize(1);
    List<Resource> relatedPersons = ResourceUtils.getResourceList(e, ResourceType.RelatedPerson);
    // From IN1.16 through IN1.19; IN1.43; INI.49
    assertThat(relatedPersons).hasSize(1);
    List<Resource> serviceRequests = ResourceUtils.getResourceList(e, ResourceType.ServiceRequest);
    // From ORC / OBR
    assertThat(serviceRequests).hasSize(1);
    ServiceRequest serviceRequest = ResourceUtils.getResourceServiceRequest(serviceRequests.get(0), ResourceUtils.context);
    assertThat(serviceRequest.getNote()).hasSize(1);
    assertThat(serviceRequest.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST ORC/OBR NOTE AA");
    List<Resource> observations = ResourceUtils.getResourceList(e, ResourceType.Observation);
    // From OBX
    assertThat(observations).hasSize(1);
    Observation observation = ResourceUtils.getResourceObservation(observations.get(0), ResourceUtils.context);
    assertThat(observation.getNote()).hasSize(1);
    assertThat(observation.getNote().get(0).getTextElement().getValueAsString()).isEqualTo("TEST OBXa NOTE");
    // Confirm there are no unaccounted for resources
    // Expected: Coverage, Organization, Patient, Encounter, RelatedPerson, ServiceRequest, Observation
    assertThat(e).hasSize(7);
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) Test(org.junit.jupiter.api.Test)

Example 83 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7FinancialInsuranceTest method testInsuranceCoverageFromIN2Self.

@Test
// Tests IN2.72 as backup IN1.17 coverage. Case of self. Code '01' is self. No related person should be created.
void testInsuranceCoverageFromIN2Self() throws IOException {
    String hl7message = "MSH|^~\\&|||||20151008111200||DFT^P03^DFT_P03|MSGID000001|T|2.6|||||||||\n" + "EVN||20210407191342||||||\n" + "PID|||MR1^^^XYZ^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\n" + // FT1.7 is required transaction code (currently not used)
    "FT1||||20201231145045||CG|FAKE|||||||||||||||||||||||||||||||||||||\n" + // IN1.2.4, IN1.2.6 to second XV Coverage.identifier
    "IN1|1|Value1^^System3^Value4^^System6" + // IN1.5 to 15 NOT REFERENCED (Tested in testBasicInsuranceCoverageFields)
    "|IdValue1^^^IdSystem4^^^^|Large Blue Organization|||||||||||" + // IN1.18 through IN1.35 NOT REFERENCED
    "||||||||||||||||||||" + // IN1.37 through IN1.53 NOT REFERENCED
    "|MEMBER36|||||||||||||||||\n" + // IN2.1 through IN2.71 NOT REFERENCED
    "IN2||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" + // Code 01 (self) should create relationship of ONESELF, and reference to patient
    "01|\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> encounters = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    // From PV1
    assertThat(encounters).hasSize(1);
    List<Resource> patients = ResourceUtils.getResourceList(e, ResourceType.Patient);
    // From PID
    assertThat(patients).hasSize(1);
    Patient patient = (Patient) patients.get(0);
    String patientId = patient.getId();
    List<Resource> organizations = ResourceUtils.getResourceList(e, ResourceType.Organization);
    // From Payor created by IN1
    assertThat(organizations).hasSize(1);
    Organization org = (Organization) organizations.get(0);
    // Check organization Id's
    assertThat(org.getIdentifier()).hasSize(1);
    // Organization identifiers checked deeply in other tests
    List<Resource> coverages = ResourceUtils.getResourceList(e, ResourceType.Coverage);
    // From IN1 segment
    assertThat(coverages).hasSize(1);
    Coverage coverage = (Coverage) coverages.get(0);
    // Confirm Coverage Identifiers
    // XV, XV, MB, SN
    assertThat(coverage.getIdentifier()).hasSize(4);
    // Coverage Identifiers deep check in testBasicInsuranceCoverageFields
    // Confirm Coverage Subscriber references to Patient
    assertThat(coverage.getSubscriber().getReference()).isEqualTo(patientId);
    // Confirm Coverage Beneficiary references to Patient, and Payor references to Organization
    assertThat(coverage.getBeneficiary().getReference()).isEqualTo(patientId);
    assertThat(coverage.getPayorFirstRep().getReference()).isEqualTo(organizations.get(0).getId());
    // Expect no RelatedPerson because IN2.72 was 01 (self)
    List<Resource> relatedPersons = ResourceUtils.getResourceList(e, ResourceType.RelatedPerson);
    // No related person should be created because IN2.72 was 01 (self)
    assertThat(relatedPersons).isEmpty();
    // Check coverage.relationship (from SubscriberRelationship mapping)
    DatatypeUtils.checkCommonCodeableConceptAssertions(coverage.getRelationship(), "self", "Self", "http://terminology.hl7.org/CodeSystem/subscriber-relationship", // IN2.72
    null);
    // Confirm there are no unaccounted for resources
    // Expected: Coverage, Organization, Patient, Encounter
    assertThat(e).hasSize(4);
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Organization(org.hl7.fhir.r4.model.Organization) Resource(org.hl7.fhir.r4.model.Resource) Patient(org.hl7.fhir.r4.model.Patient) Coverage(org.hl7.fhir.r4.model.Coverage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 84 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.

the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonGenderMatched.

@Test
public void searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonGenderMatched() {
    TokenAndListParam tokenAndListParam = new TokenAndListParam().addAnd(new TokenOrListParam().add(GENDER));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.GENDER_SEARCH_HANDLER, tokenAndListParam);
    when(dao.getSearchResultUuids(any())).thenReturn(singletonList(RELATED_PERSON_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(singletonList(relationship));
    when(translator.toFhirResource(relationship)).thenReturn(relatedPerson);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = relatedPersonService.searchForRelatedPeople(null, tokenAndListParam, null, null, null, null, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
}
Also used : TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 85 with RelatedPerson

use of org.hl7.fhir.r4.model.RelatedPerson in project openmrs-module-fhir2 by openmrs.

the class FhirRelatedPersonServiceImplTest method searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonPostalCodeMatched.

@Test
public void searchForRelatedPeople_shouldReturnCollectionOfRelatedPersonWhenPersonPostalCodeMatched() {
    StringAndListParam stringAndListParam = new StringAndListParam().addAnd(new StringOrListParam().add(new StringParam(POSTAL_CODE)));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.ADDRESS_SEARCH_HANDLER, FhirConstants.POSTAL_CODE_PROPERTY, stringAndListParam);
    when(dao.getSearchResultUuids(any())).thenReturn(singletonList(RELATED_PERSON_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(singletonList(relationship));
    when(translator.toFhirResource(relationship)).thenReturn(relatedPerson);
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    IBundleProvider results = relatedPersonService.searchForRelatedPeople(null, null, null, null, null, stringAndListParam, null, null, null, null, null);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
}
Also used : StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) StringOrListParam(ca.uhn.fhir.rest.param.StringOrListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)87 RelatedPerson (org.hl7.fhir.r4.model.RelatedPerson)54 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)51 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)33 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)29 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)24 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)24 StringParam (ca.uhn.fhir.rest.param.StringParam)24 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)24 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)20 RelatedPerson (org.hl7.fhir.dstu3.model.RelatedPerson)17 Test (org.junit.jupiter.api.Test)17 Resource (org.hl7.fhir.r4.model.Resource)14 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)13 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)12 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)12 Patient (org.hl7.fhir.r4.model.Patient)12 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)11 Identifier (org.hl7.fhir.r4.model.Identifier)10 Reference (org.hl7.fhir.r4.model.Reference)9