Search in sources :

Example 6 with ObsService

use of org.openmrs.api.ObsService in project openmrs-core by openmrs.

the class ORUR01HandlerTest method processMessage_shouldSetValue_CodedMatchingABooleanConceptForObsIfTheAnswerIs0Or1AndQuestionDatatypeIsCoded.

/**
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldSetValue_CodedMatchingABooleanConceptForObsIfTheAnswerIs0Or1AndQuestionDatatypeIsCoded() throws Exception {
    ObsService os = Context.getObsService();
    String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|21^CIVIL STATUS^99DCT||1|||||||||20080206";
    // the expected question for the obs in the hl7 message has to be coded
    Assert.assertEquals("Coded", Context.getConceptService().getConcept(21).getDatatype().getName());
    List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(21));
    Message hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
    // hacky way to get the newly added obs and make tests on it
    List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(21));
    Obs newObservation = null;
    for (Obs newObs : newList) {
        if (!oldList.contains(newObs) && !newObs.isObsGrouping()) {
            newObservation = newObs;
        }
    }
    Assert.assertEquals(Context.getConceptService().getTrueConcept(), newObservation.getValueCoded());
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Message(ca.uhn.hl7v2.model.Message) ObsService(org.openmrs.api.ObsService) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with ObsService

use of org.openmrs.api.ObsService in project openmrs-core by openmrs.

the class ORUR01HandlerTest method processMessage_shouldSetValue_NumericForObsIfQuestionDatatypeIsNumeric.

/**
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldSetValue_NumericForObsIfQuestionDatatypeIsNumeric() throws Exception {
    ObsService os = Context.getObsService();
    String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206";
    // the expected question for the obs in the hl7 message has to be
    // numeric
    Assert.assertEquals("Numeric", Context.getConceptService().getConcept(5497).getDatatype().getName());
    List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497));
    Message hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
    List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497));
    Obs newObservation = null;
    for (Obs newObs : newList) {
        if (!oldList.contains(newObs) && !newObs.isObsGrouping()) {
            newObservation = newObs;
        }
    }
    Assert.assertEquals(450, newObservation.getValueNumeric().intValue());
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Message(ca.uhn.hl7v2.model.Message) ObsService(org.openmrs.api.ObsService) Person(org.openmrs.Person) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with ObsService

use of org.openmrs.api.ObsService in project openmrs-core by openmrs.

the class PatientServiceImpl method mergeObservationsNotContainedInEncounters.

private void mergeObservationsNotContainedInEncounters(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) {
    // move all obs that weren't contained in encounters
    // TODO: this should be a copy, not a move
    ObsService obsService = Context.getObsService();
    for (Obs obs : obsService.getObservationsByPerson(notPreferred)) {
        if (obs.getEncounter() == null && !obs.getVoided()) {
            obs.setPerson(preferred);
            Obs persisted = obsService.saveObs(obs, "Merged from patient #" + notPreferred.getPatientId());
            mergedData.addMovedIndependentObservation(persisted.getUuid());
        }
    }
}
Also used : Obs(org.openmrs.Obs) ObsService(org.openmrs.api.ObsService)

Example 9 with ObsService

use of org.openmrs.api.ObsService in project openmrs-core by openmrs.

the class EncounterServiceImpl method unvoidEncounter.

/**
 * @see org.openmrs.api.EncounterService#unvoidEncounter(org.openmrs.Encounter)
 */
@Override
public Encounter unvoidEncounter(Encounter encounter) throws APIException {
    // if authenticated user is not supposed to edit encounter of certain type
    if (!canEditEncounter(encounter, null)) {
        throw new APIException("Encounter.error.privilege.required.unvoid", new Object[] { encounter.getEncounterType().getEditPrivilege() });
    }
    String voidReason = encounter.getVoidReason();
    if (voidReason == null) {
        voidReason = "";
    }
    ObsService os = Context.getObsService();
    for (Obs o : encounter.getObsAtTopLevel(true)) {
        if (voidReason.equals(o.getVoidReason())) {
            os.unvoidObs(o);
        }
    }
    OrderService orderService = Context.getOrderService();
    for (Order o : encounter.getOrders()) {
        if (voidReason.equals(o.getVoidReason())) {
            orderService.unvoidOrder(o);
        }
    }
    encounter.setVoided(false);
    encounter.setVoidedBy(null);
    encounter.setDateVoided(null);
    encounter.setVoidReason(null);
    Context.getEncounterService().saveEncounter(encounter);
    return encounter;
}
Also used : Order(org.openmrs.Order) Obs(org.openmrs.Obs) APIException(org.openmrs.api.APIException) ObsService(org.openmrs.api.ObsService) OrderService(org.openmrs.api.OrderService)

Example 10 with ObsService

use of org.openmrs.api.ObsService in project openmrs-core by openmrs.

the class EncounterServiceImpl method purgeEncounter.

/**
 * @see org.openmrs.api.EncounterService#purgeEncounter(Encounter, boolean)
 */
@Override
public void purgeEncounter(Encounter encounter, boolean cascade) throws APIException {
    // if authenticated user is not supposed to edit encounter of certain type
    if (!canEditEncounter(encounter, null)) {
        throw new APIException("Encounter.error.privilege.required.purge", new Object[] { encounter.getEncounterType().getEditPrivilege() });
    }
    if (cascade) {
        ObsService obsService = Context.getObsService();
        List<Encounter> justThisEncounter = new ArrayList<>();
        justThisEncounter.add(encounter);
        List<Obs> observations = new ArrayList<>(obsService.getObservations(null, justThisEncounter, null, null, null, null, null, null, null, null, null, true));
        for (Obs o : observations) {
            obsService.purgeObs(o);
        }
        Set<Order> orders = encounter.getOrders();
        for (Order o : orders) {
            Context.getOrderService().purgeOrder(o);
        }
    }
    Context.getEncounterService().purgeEncounter(encounter);
}
Also used : Order(org.openmrs.Order) Obs(org.openmrs.Obs) APIException(org.openmrs.api.APIException) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) ObsService(org.openmrs.api.ObsService)

Aggregations

ObsService (org.openmrs.api.ObsService)17 Obs (org.openmrs.Obs)16 Message (ca.uhn.hl7v2.model.Message)11 Test (org.junit.Test)11 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)11 Concept (org.openmrs.Concept)10 Person (org.openmrs.Person)7 Patient (org.openmrs.Patient)5 Date (java.util.Date)4 Order (org.openmrs.Order)4 ArrayList (java.util.ArrayList)3 APIException (org.openmrs.api.APIException)3 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 Encounter (org.openmrs.Encounter)2 OrderService (org.openmrs.api.OrderService)2 ConceptName (org.openmrs.ConceptName)1 ConceptProposal (org.openmrs.ConceptProposal)1 GlobalProperty (org.openmrs.GlobalProperty)1 Location (org.openmrs.Location)1