Search in sources :

Example 16 with Group

use of ca.uhn.hl7v2.model.Group in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7DataExtractor method getAllStructures.

public ParsingResult<Structure> getAllStructures(String group, int groupRep, String segment) {
    LOGGER.debug("Fetching segment: {} {} {} ", group, groupRep, segment);
    try {
        ParsingResult<Structure> parsingResult = null;
        Preconditions.checkArgument(StringUtils.isNotBlank(group), "group cannot be null or empty");
        Preconditions.checkArgument(StringUtils.isNotBlank(segment), SEGMENT_CANNOT_BE_NULL_OR_EMPTY);
        Preconditions.checkArgument(groupRep >= 0, "groupRep should be greater than or equal to 0");
        Structure groupStr = message.get(group, groupRep);
        if (groupStr instanceof Group) {
            Group gp = (Group) groupStr;
            Structure[] s = gp.getAll(segment);
            List<Structure> list = Lists.newArrayList(s);
            list.removeIf(isEmpty());
            parsingResult = new Hl7ParsingStructureResult(Lists.newArrayList(list));
        } else {
            parsingResult = new Hl7ParsingStructureResult(new ArrayList<>());
        }
        return parsingResult;
    } catch (HL7Exception | IllegalArgumentException | ArrayIndexOutOfBoundsException e) {
        String spec = group + " " + groupRep + " " + segment;
        LOGGER.debug("Cannot extract value for {} ", spec, e);
        LOGGER.warn("Cannot extract value for {} ", spec);
        return new Hl7ParsingStructureResult(new ArrayList<>());
    }
}
Also used : Group(ca.uhn.hl7v2.model.Group) ArrayList(java.util.ArrayList) HL7Exception(ca.uhn.hl7v2.HL7Exception) Structure(ca.uhn.hl7v2.model.Structure) Hl7ParsingStructureResult(io.github.linuxforhealth.hl7.parsing.result.Hl7ParsingStructureResult)

Example 17 with Group

use of ca.uhn.hl7v2.model.Group in project hl7v2-fhir-converter by LinuxForHealth.

the class HL7DataExtractor method getAllStructures.

public ParsingResult<Structure> getAllStructures(Structure struct, String segment) {
    LOGGER.debug("Fetching segment: {} {}  ", struct, segment);
    try {
        ParsingResult<Structure> parsingResult = null;
        Preconditions.checkArgument(struct != null, "struct cannot be null ");
        Preconditions.checkArgument(StringUtils.isNotBlank(segment), SEGMENT_CANNOT_BE_NULL_OR_EMPTY);
        if (struct instanceof Group) {
            Group gp = (Group) struct;
            Structure[] s = gp.getAll(segment);
            List<Structure> list = Lists.newArrayList(s);
            list.removeIf(isEmpty());
            parsingResult = new Hl7ParsingStructureResult(list);
        } else {
            parsingResult = new Hl7ParsingStructureResult(new ArrayList<>());
        }
        return parsingResult;
    } catch (HL7Exception | IllegalArgumentException | ArrayIndexOutOfBoundsException e) {
        LOGGER.debug("Cannot extract value for Structure {} Segment {} ", struct, segment, e);
        LOGGER.warn("Cannot extract value for Structure {} Segment {} ", struct, segment);
        return new Hl7ParsingStructureResult(new ArrayList<>());
    }
}
Also used : Group(ca.uhn.hl7v2.model.Group) ArrayList(java.util.ArrayList) HL7Exception(ca.uhn.hl7v2.HL7Exception) Structure(ca.uhn.hl7v2.model.Structure) Hl7ParsingStructureResult(io.github.linuxforhealth.hl7.parsing.result.Hl7ParsingStructureResult)

Example 18 with Group

use of ca.uhn.hl7v2.model.Group in project manifoldcf by apache.

the class ConfluenceClient method getUserAuthorities.

/**
 * @param username
 * @return
 * @throws Exception
 */
public ConfluenceUser getUserAuthorities(final String username) throws Exception {
    final List<String> authorities = Lists.<String>newArrayList();
    final List<Group> groups = getUserGroups(username);
    groups.forEach(group -> {
        authorities.add("group-" + group.getName());
    });
    final User user = getConfluenceUser(username);
    authorities.add("user-" + user.getUserKey());
    final List<Space> spaces = getSpaces();
    for (final Space space : spaces) {
        final List<String> permissions = getSpacePermissionsForUser(space, username);
        if (permissions.contains(VIEW_PERMISSION)) {
            authorities.add("space-" + space.getKey());
        }
    }
    return new ConfluenceUser(username, authorities);
}
Also used : Space(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Space) Group(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Group) ConfluenceUser(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.ConfluenceUser) User(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.User) ConfluenceUser(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.ConfluenceUser)

Example 19 with Group

use of ca.uhn.hl7v2.model.Group in project manifoldcf by apache.

the class ConfluenceClient method getUserGroups.

private List<Group> getUserGroups(final String username) throws Exception {
    long lastStart = 0;
    final long defaultSize = 50;
    final List<Group> groups = new ArrayList<Group>();
    if (Logging.connectors != null && Logging.connectors.isDebugEnabled()) {
        final String groupsDesc = "groups of user " + username;
        Logging.connectors.debug(new MessageFormat("Starting from {0} and size {1} for {2}", Locale.ROOT).format(new Object[] { lastStart, defaultSize, groupsDesc }));
    }
    Boolean isLast = true;
    do {
        final ConfluenceResponse<Group> response = getUserGroups((int) lastStart, (int) defaultSize, username);
        int count = 0;
        for (final Group group : response.getResults()) {
            groups.add(group);
            count++;
        }
        lastStart += count;
        isLast = response.isLast();
        if (Logging.connectors != null && Logging.connectors.isDebugEnabled()) {
            Logging.connectors.debug(new MessageFormat("New start {0} and size {1}", Locale.ROOT).format(new Object[] { lastStart, defaultSize }));
        }
    } while (!isLast);
    return groups;
}
Also used : Group(org.apache.manifoldcf.crawler.connectors.confluence.v6.model.Group) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) JSONObject(org.json.simple.JSONObject)

Example 20 with Group

use of ca.uhn.hl7v2.model.Group in project cqf-ruler by DBCG.

the class ParameterUser method getPatientListFromGroup.

// TODO: replace this with version from the evaluator?
default List<Patient> getPatientListFromGroup(String subjectGroupId) {
    List<Patient> patientList = new ArrayList<>();
    Group group = read(newId(subjectGroupId));
    if (group == null) {
        throw new IllegalArgumentException("Could not find Group: " + subjectGroupId);
    }
    group.getMember().forEach(member -> {
        Reference reference = member.getEntity();
        if (reference.getReferenceElement().getResourceType().equals("Patient")) {
            Patient patient = ensurePatient(reference.getReference());
            patientList.add(patient);
        } else if (reference.getReferenceElement().getResourceType().equals("Group")) {
            patientList.addAll(getPatientListFromGroup(reference.getReference()));
        } else {
            ourLog.info("Group member was not a Patient or a Group, so skipping. \n{}", reference.getReference());
        }
    });
    return patientList;
}
Also used : Group(org.hl7.fhir.r4.model.Group) Reference(org.hl7.fhir.r4.model.Reference) ArrayList(java.util.ArrayList) Patient(org.hl7.fhir.r4.model.Patient)

Aggregations

Test (org.junit.Test)90 Group (org.hl7.fhir.r4.model.Group)74 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)49 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)40 Group (org.hl7.fhir.dstu3.model.Group)30 Cohort (org.openmrs.Cohort)30 InputStream (java.io.InputStream)20 ArrayList (java.util.ArrayList)16 Structure (ca.uhn.hl7v2.model.Structure)13 Group (ca.uhn.hl7v2.model.Group)12 Reference (org.hl7.fhir.r4.model.Reference)12 HL7Exception (ca.uhn.hl7v2.HL7Exception)11 Message (ca.uhn.hl7v2.model.Message)10 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)10 Segment (ca.uhn.hl7v2.model.Segment)8 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)8 List (java.util.List)6 Type (ca.uhn.hl7v2.model.Type)5 Test (org.junit.jupiter.api.Test)5 User (org.openmrs.User)5