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());
}
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());
}
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());
}
}
}
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;
}
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);
}
Aggregations