Search in sources :

Example 1 with PathogenTestResultType

use of de.symeda.sormas.api.sample.PathogenTestResultType in project SORMAS-Project by hzi-braunschweig.

the class TestEntityCreator method createSampleTest.

public static PathogenTest createSampleTest(Sample sample) {
    PathogenTestType pathogenTestType = PathogenTestType.RAPID_TEST;
    PathogenTestResultType pathogenTestResultType = PathogenTestResultType.NEGATIVE;
    Date sampleTestDateTime = new Date();
    PathogenTest pathogenTest = DatabaseHelper.getSampleTestDao().build(sample);
    pathogenTest.setTestType(pathogenTestType);
    pathogenTest.setTestResult(pathogenTestResultType);
    pathogenTest.setTestDateTime(sampleTestDateTime);
    try {
        DatabaseHelper.getSampleTestDao().saveAndSnapshot(pathogenTest);
        DatabaseHelper.getSampleTestDao().accept(pathogenTest);
    } catch (DaoException e) {
        throw new RuntimeException(e);
    }
    return DatabaseHelper.getSampleTestDao().queryForIdWithEmbedded(pathogenTest.getId());
}
Also used : PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) PathogenTest(de.symeda.sormas.app.backend.sample.PathogenTest) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) DaoException(de.symeda.sormas.app.backend.common.DaoException) Date(java.util.Date)

Example 2 with PathogenTestResultType

use of de.symeda.sormas.api.sample.PathogenTestResultType in project SORMAS-Project by hzi-braunschweig.

the class SampleFacadeEjbTest method testGetNewTestResultCountByResultType.

@Test
public void testGetNewTestResultCountByResultType() {
    RDCFEntities rdcf = creator.createRDCFEntities();
    UserReferenceDto user = creator.createUser(rdcf).toReference();
    PersonReferenceDto person1 = creator.createPerson("Heinz", "First").toReference();
    PersonReferenceDto person2 = creator.createPerson("Heinz", "Second").toReference();
    CaseDataDto case1 = creator.createCase(user, person1, rdcf);
    CaseDataDto case2 = creator.createCase(user, person2, rdcf);
    List<Long> caseIds = getCaseService().getAllIds(null);
    // no existing samples
    SampleFacade sampleFacade = getSampleFacade();
    Map<PathogenTestResultType, Long> resultMap = sampleFacade.getNewTestResultCountByResultType(caseIds);
    assertEquals(new Long(0), resultMap.values().stream().collect(Collectors.summingLong(Long::longValue)));
    assertNull(resultMap.getOrDefault(PathogenTestResultType.INDETERMINATE, null));
    assertNull(resultMap.getOrDefault(PathogenTestResultType.NEGATIVE, null));
    assertNull(resultMap.getOrDefault(PathogenTestResultType.PENDING, null));
    assertNull(resultMap.getOrDefault(PathogenTestResultType.POSITIVE, null));
    // one pending sample with in one case
    Facility lab = creator.createFacility("facility", rdcf.region, rdcf.district, rdcf.community);
    creator.createSample(case1.toReference(), user, lab);
    resultMap = sampleFacade.getNewTestResultCountByResultType(caseIds);
    assertEquals(new Long(1), resultMap.values().stream().collect(Collectors.summingLong(Long::longValue)));
    assertNull(resultMap.getOrDefault(PathogenTestResultType.INDETERMINATE, null));
    assertNull(resultMap.getOrDefault(PathogenTestResultType.NEGATIVE, null));
    assertEquals(new Long(1), resultMap.getOrDefault(PathogenTestResultType.PENDING, null));
    assertNull(resultMap.getOrDefault(PathogenTestResultType.POSITIVE, null));
    // one pending sample in each of two cases
    creator.createSample(case2.toReference(), user, lab);
    resultMap = sampleFacade.getNewTestResultCountByResultType(caseIds);
    assertEquals(new Long(2), resultMap.values().stream().collect(Collectors.summingLong(Long::longValue)));
    assertNull(resultMap.getOrDefault(PathogenTestResultType.INDETERMINATE, null));
    assertNull(resultMap.getOrDefault(PathogenTestResultType.NEGATIVE, null));
    assertEquals(new Long(2), resultMap.getOrDefault(PathogenTestResultType.PENDING, null));
    assertNull(resultMap.getOrDefault(PathogenTestResultType.POSITIVE, null));
    // one pending sample in each of two cases
    // and one positive sample in one of the two cases
    SampleDto sample = creator.createSample(case1.toReference(), user, lab);
    sample.setPathogenTestResult(PathogenTestResultType.POSITIVE);
    sampleFacade.saveSample(sample);
    resultMap = sampleFacade.getNewTestResultCountByResultType(caseIds);
    assertEquals(new Long(2), resultMap.values().stream().collect(Collectors.summingLong(Long::longValue)));
    assertNull(resultMap.getOrDefault(PathogenTestResultType.INDETERMINATE, null));
    assertNull(resultMap.getOrDefault(PathogenTestResultType.NEGATIVE, null));
    assertEquals(new Long(1), resultMap.getOrDefault(PathogenTestResultType.PENDING, null));
    assertEquals(new Long(1), resultMap.getOrDefault(PathogenTestResultType.POSITIVE, null));
}
Also used : UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) RDCFEntities(de.symeda.sormas.backend.TestDataCreator.RDCFEntities) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) SampleFacade(de.symeda.sormas.api.sample.SampleFacade) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) SampleDto(de.symeda.sormas.api.sample.SampleDto) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 3 with PathogenTestResultType

use of de.symeda.sormas.api.sample.PathogenTestResultType in project SORMAS-Project by hzi-braunschweig.

the class PathogenTestEditFragment method onAfterLayoutBinding.

@Override
public void onAfterLayoutBinding(FragmentPathogenTestEditLayoutBinding contentBinding) {
    setFieldVisibilitiesAndAccesses(PathogenTestDto.class, contentBinding.mainContent);
    // Initialize ControlSpinnerFields
    contentBinding.pathogenTestTestType.initializeSpinner(testTypeList, new ValueChangeListener() {

        @Override
        public void onChange(ControlPropertyField field) {
            PathogenTestType currentTestType = (PathogenTestType) field.getValue();
            if ((PathogenTestType.PCR_RT_PCR == currentTestType && PathogenTestResultType.POSITIVE == contentBinding.pathogenTestTestResult.getValue()) || PathogenTestType.CQ_VALUE_DETECTION == currentTestType) {
                contentBinding.pathogenTestCqValue.setVisibility(View.VISIBLE);
            } else {
                contentBinding.pathogenTestCqValue.hideField(true);
            }
            if (PathogenTestType.PCR_RT_PCR == currentTestType && Disease.CORONAVIRUS == record.getTestedDisease()) {
                getContentBinding().pathogenTestPcrTestSpecification.setVisibility(View.VISIBLE);
            } else {
                getContentBinding().pathogenTestPcrTestSpecification.hideField(false);
            }
        }
    });
    contentBinding.pathogenTestPcrTestSpecification.initializeSpinner(pcrTestSpecificationList);
    contentBinding.pathogenTestTestedDiseaseVariant.initializeSpinner(diseaseVariantList);
    contentBinding.pathogenTestTestedDisease.initializeSpinner(diseaseList, new ValueChangeListener() {

        final Disease currentDisease = record.getTestedDisease();

        @Override
        public void onChange(ControlPropertyField field) {
            if (PathogenTestType.PCR_RT_PCR == record.getTestType() && Disease.CORONAVIRUS == field.getValue()) {
                getContentBinding().pathogenTestPcrTestSpecification.setVisibility(View.VISIBLE);
            } else {
                getContentBinding().pathogenTestPcrTestSpecification.hideField(false);
            }
            if (this.currentDisease == null || contentBinding.pathogenTestTestedDisease.getValue() != currentDisease) {
                updateDiseaseVariantsField(contentBinding);
            }
            testTypeList = DataUtils.toItems(Arrays.asList(PathogenTestType.values()), true, FieldVisibilityCheckers.withDisease((Disease) field.getValue()), PathogenTestType.class);
            contentBinding.pathogenTestTestType.setSpinnerData(testTypeList);
        }
    });
    contentBinding.pathogenTestTestResult.initializeSpinner(testResultList, new ValueChangeListener() {

        @Override
        public void onChange(ControlPropertyField field) {
            PathogenTestResultType currentPathogenTestResult = (PathogenTestResultType) field.getValue();
            if ((PathogenTestType.PCR_RT_PCR == contentBinding.pathogenTestTestType.getValue() && PathogenTestResultType.POSITIVE == currentPathogenTestResult) || PathogenTestType.CQ_VALUE_DETECTION == contentBinding.pathogenTestTestType.getValue()) {
                contentBinding.pathogenTestCqValue.setVisibility(View.VISIBLE);
            } else {
                contentBinding.pathogenTestCqValue.hideField(true);
            }
        }
    });
    contentBinding.pathogenTestLab.initializeSpinner(DataUtils.toItems(labList), new ValueChangeListener() {

        @Override
        public void onChange(ControlPropertyField field) {
            Facility laboratory = (Facility) field.getValue();
            if (laboratory != null && laboratory.getUuid().equals(FacilityDto.OTHER_FACILITY_UUID)) {
                contentBinding.pathogenTestLabDetails.setVisibility(View.VISIBLE);
            } else {
                contentBinding.pathogenTestLabDetails.hideField(true);
            }
        }
    });
    // // Initialize ControlDateFields
    contentBinding.pathogenTestReportDate.initializeDateField(getFragmentManager());
    contentBinding.pathogenTestTestDateTime.initializeDateTimeField(getFragmentManager());
    if (sample.getSamplePurpose() == SamplePurpose.INTERNAL) {
        contentBinding.pathogenTestLab.setRequired(false);
    }
}
Also used : ValueChangeListener(de.symeda.sormas.app.component.controls.ValueChangeListener) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) Disease(de.symeda.sormas.api.Disease) ControlPropertyField(de.symeda.sormas.app.component.controls.ControlPropertyField) Facility(de.symeda.sormas.app.backend.facility.Facility) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType)

Example 4 with PathogenTestResultType

use of de.symeda.sormas.api.sample.PathogenTestResultType in project SORMAS-Project by hzi-braunschweig.

the class SampleService method getNewTestResultCountByResultType.

public Map<PathogenTestResultType, Long> getNewTestResultCountByResultType(List<Long> caseIds) {
    if (CollectionUtils.isEmpty(caseIds)) {
        // Avoid empty IN clause
        return new HashMap<>();
    }
    // Avoid parameter limit by joining caseIds to a String instead of n parameters
    StringBuilder queryBuilder = new StringBuilder();
    // @formatter:off
    queryBuilder.append("WITH sortedsamples AS (SELECT DISTINCT ON (").append(Sample.ASSOCIATED_CASE).append("_id) ").append(Sample.ASSOCIATED_CASE).append("_id, ").append(Sample.PATHOGEN_TEST_RESULT).append(", ").append(Sample.SAMPLE_DATE_TIME).append(" FROM ").append(Sample.TABLE_NAME).append(" WHERE (").append(Sample.SPECIMEN_CONDITION).append(" IS NULL OR ").append(Sample.SPECIMEN_CONDITION).append(" = '").append(SpecimenCondition.ADEQUATE.name()).append("') AND ").append(Sample.TABLE_NAME).append(".").append(Sample.DELETED).append(" = false ORDER BY ").append(Sample.ASSOCIATED_CASE).append("_id, ").append(Sample.SAMPLE_DATE_TIME).append(" desc) SELECT sortedsamples.").append(Sample.PATHOGEN_TEST_RESULT).append(", COUNT(").append(Sample.ASSOCIATED_CASE).append("_id) FROM sortedsamples JOIN ").append(Case.TABLE_NAME).append(" ON sortedsamples.").append(Sample.ASSOCIATED_CASE).append("_id = ").append(Case.TABLE_NAME).append(".id ").append(" WHERE sortedsamples.").append(Sample.ASSOCIATED_CASE).append("_id IN (:caseIds)").append(" GROUP BY sortedsamples." + Sample.PATHOGEN_TEST_RESULT);
    if (caseIds.size() < ModelConstants.PARAMETER_LIMIT) {
        List<Object[]> results;
        Query query = em.createNativeQuery(queryBuilder.toString());
        query.setParameter("caseIds", caseIds);
        results = query.getResultList();
        return results.stream().filter(e -> e[0] != null).collect(Collectors.toMap(e -> PathogenTestResultType.valueOf((String) e[0]), e -> ((BigInteger) e[1]).longValue()));
    } else {
        List<Object[]> results = new LinkedList<>();
        IterableHelper.executeBatched(caseIds, ModelConstants.PARAMETER_LIMIT, batchedCaseIds -> {
            Query query = em.createNativeQuery(queryBuilder.toString());
            query.setParameter("caseIds", batchedCaseIds);
            results.addAll(query.getResultList());
        });
        return results.stream().filter(e -> e[0] != null).collect(Collectors.toMap(e -> PathogenTestResultType.valueOf((String) e[0]), e -> ((BigInteger) e[1]).longValue(), Long::sum));
    }
}
Also used : Arrays(java.util.Arrays) Join(javax.persistence.criteria.Join) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) SpecimenCondition(de.symeda.sormas.api.sample.SpecimenCondition) TransactionAttributeType(javax.ejb.TransactionAttributeType) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) Predicate(javax.persistence.criteria.Predicate) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) BigInteger(java.math.BigInteger) ContactJoins(de.symeda.sormas.backend.contact.ContactJoins) From(javax.persistence.criteria.From) Path(javax.persistence.criteria.Path) EventParticipantReferenceDto(de.symeda.sormas.api.event.EventParticipantReferenceDto) Contact(de.symeda.sormas.backend.contact.Contact) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) CaseService(de.symeda.sormas.backend.caze.CaseService) Person(de.symeda.sormas.backend.person.Person) Timestamp(java.sql.Timestamp) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) District(de.symeda.sormas.backend.infrastructure.district.District) Instant(java.time.Instant) Pseudonymizer(de.symeda.sormas.backend.util.Pseudonymizer) Collectors(java.util.stream.Collectors) ContactQueryContext(de.symeda.sormas.backend.contact.ContactQueryContext) EventParticipantQueryContext(de.symeda.sormas.backend.event.EventParticipantQueryContext) List(java.util.List) Query(javax.persistence.Query) UserService(de.symeda.sormas.backend.user.UserService) User(de.symeda.sormas.backend.user.User) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType) JurisdictionHelper(de.symeda.sormas.backend.util.JurisdictionHelper) Order(javax.persistence.criteria.Order) DeletableAdo(de.symeda.sormas.backend.common.DeletableAdo) Optional(java.util.Optional) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) Location(de.symeda.sormas.backend.location.Location) SampleAssociationType(de.symeda.sormas.api.sample.SampleAssociationType) SampleCriteria(de.symeda.sormas.api.sample.SampleCriteria) EventParticipant(de.symeda.sormas.backend.event.EventParticipant) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) SormasToSormasShareInfoService(de.symeda.sormas.backend.sormastosormas.share.shareinfo.SormasToSormasShareInfoService) DateHelper(de.symeda.sormas.api.utils.DateHelper) SampleListEntryDtoResultTransformer(de.symeda.sormas.backend.sample.transformers.SampleListEntryDtoResultTransformer) Selection(javax.persistence.criteria.Selection) HashMap(java.util.HashMap) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) CaseFacadeEjb(de.symeda.sormas.backend.caze.CaseFacadeEjb) Function(java.util.function.Function) EventParticipantService(de.symeda.sormas.backend.event.EventParticipantService) ArrayList(java.util.ArrayList) CaseReferenceDto(de.symeda.sormas.api.caze.CaseReferenceDto) PathogenTestType(de.symeda.sormas.api.sample.PathogenTestType) Case(de.symeda.sormas.backend.caze.Case) CriteriaUpdate(javax.persistence.criteria.CriteriaUpdate) CollectionUtils(org.apache.commons.collections.CollectionUtils) TransactionAttribute(javax.ejb.TransactionAttribute) IterableHelper(de.symeda.sormas.backend.util.IterableHelper) SampleListEntryDto(de.symeda.sormas.api.sample.SampleListEntryDto) LocalBean(javax.ejb.LocalBean) CaseQueryContext(de.symeda.sormas.backend.caze.CaseQueryContext) SampleIndexDto(de.symeda.sormas.api.sample.SampleIndexDto) LinkedList(java.util.LinkedList) Expression(javax.persistence.criteria.Expression) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) SampleJurisdictionFlagsDto(de.symeda.sormas.api.sample.SampleJurisdictionFlagsDto) AbstractDeletableAdoService(de.symeda.sormas.backend.common.AbstractDeletableAdoService) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) DataHelper(de.symeda.sormas.api.utils.DataHelper) SortProperty(de.symeda.sormas.api.utils.SortProperty) Captions(de.symeda.sormas.api.i18n.Captions) Event(de.symeda.sormas.backend.event.Event) ContactService(de.symeda.sormas.backend.contact.ContactService) Subquery(javax.persistence.criteria.Subquery) ContactReferenceDto(de.symeda.sormas.api.contact.ContactReferenceDto) Collections(java.util.Collections) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BigInteger(java.math.BigInteger) LinkedList(java.util.LinkedList)

Example 5 with PathogenTestResultType

use of de.symeda.sormas.api.sample.PathogenTestResultType in project SORMAS-Project by hzi-braunschweig.

the class PathogenTestService method getPathogenTestResultsForCase.

public List<PathogenTestResultType> getPathogenTestResultsForCase(long caseId) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<PathogenTestResultType> cq = cb.createQuery(PathogenTestResultType.class);
    Root<PathogenTest> root = cq.from(getElementClass());
    cq.where(cb.and(createDefaultFilter(cb, root), cb.equal(root.get(PathogenTest.SAMPLE).get(Sample.ASSOCIATED_CASE).get(Case.ID), caseId)));
    cq.select(root.get(PathogenTest.TEST_RESULT));
    List<PathogenTestResultType> result = em.createQuery(cq).getResultList();
    return result;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PathogenTestResultType(de.symeda.sormas.api.sample.PathogenTestResultType)

Aggregations

PathogenTestResultType (de.symeda.sormas.api.sample.PathogenTestResultType)8 PathogenTestType (de.symeda.sormas.api.sample.PathogenTestType)4 ComboBox (com.vaadin.v7.ui.ComboBox)2 Disease (de.symeda.sormas.api.Disease)2 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)2 SampleDto (de.symeda.sormas.api.sample.SampleDto)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 CollectionUtils (org.apache.commons.collections.CollectionUtils)2 Label (com.vaadin.ui.Label)1 Converter (com.vaadin.v7.data.util.converter.Converter)1 ItemCaptionMode (com.vaadin.v7.ui.AbstractSelect.ItemCaptionMode)1 CheckBox (com.vaadin.v7.ui.CheckBox)1 DateField (com.vaadin.v7.ui.DateField)1 TextArea (com.vaadin.v7.ui.TextArea)1 TextField (com.vaadin.v7.ui.TextField)1 EntityRelevanceStatus (de.symeda.sormas.api.EntityRelevanceStatus)1